For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).
Python class
GrammarMatcher
GrammarMatcher
class max.pipelines.context.GrammarMatcher(*args, **kwargs)
Bases: Protocol
Per-request grammar matcher stepped each decode step.
Backend-agnostic interface that any grammar backend’s matcher must satisfy.
The methods are: try_consume_tokens to advance the matcher,
is_accepting / is_stopped to query terminal state, and
deep_copy for speculative walks.
deep_copy()
deep_copy()
Independent copy for speculative walks (never mutates the original).
-
Return type:
is_accepting()
is_accepting()
Whether the matcher is at an accepting (stoppable) state.
-
Return type:
is_stopped()
is_stopped()
Whether the matcher has reached a terminal state.
-
Return type:
try_consume_tokens()
try_consume_tokens(tokens)
Advance the matcher; returns the number of tokens consumed.