For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/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; method names mirror llguidance’s LLMatcher
so a context can hold any backend’s matcher (llguidance, xgrammar) without
branching. The llguidance LLMatcher satisfies this protocol natively.
deep_copy()
deep_copy()
Independent copy for speculative walks (never mutates the original).
-
Return type:
get_error()
get_error()
Error message for the last rejection, if any (diagnostics).
-
Return type:
-
str | None
get_grammar_warnings()
get_grammar_warnings()
Grammar compilation warnings, if any (diagnostics).
-
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.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!