IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
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

GrammarEnforcementSnapshot

GrammarEnforcementSnapshot​

class max.pipelines.context.GrammarEnforcementSnapshot(in_thinking_region, grammar_enforced, tool_calling_match_buffer, thinking_match_buffer)

source

Bases: object

Captured grammar-enforcement state for rollback.

The speculative bitmask path walks the enforcement state through draft tokens to compute downstream slot constraints and then restores this snapshot so committed-token processing on the next batch replays the same transitions from a clean state. Lives next to TextContext because it exposes TextContext.snapshot_grammar_state() / TextContext.restore_grammar_state(); the concrete implementation in TextContext constructs and consumes instances.

Parameters:

  • in_thinking_region (bool)
  • grammar_enforced (bool)
  • tool_calling_match_buffer (list[int])
  • thinking_match_buffer (list[int])

grammar_enforced​

grammar_enforced: bool

source

in_thinking_region​

in_thinking_region: bool

source

thinking_match_buffer​

thinking_match_buffer: list[int]

source

tool_calling_match_buffer​

tool_calling_match_buffer: list[int]

source