vllm.v1.structured_output
¶
Modules:
Classes:
-
ConstraintBounds–Where tokens start being fed to the grammar and being masked.
-
StructuredOutputManager–Engine-level manager for structured output requests.
ConstraintBounds
¶
StructuredOutputManager
¶
Engine-level manager for structured output requests.
Methods:
-
accept_tokens–Advance grammar with accepted tokens. Returns False on rejection.
-
trim_spec_tokens–Trim structured-output padding and grammar-invalid suffixes.
_fill_bitmasks(batch)
¶
Fill one bitmask row per entry.
A row the grammar does not constrain allows every token except
masked_ids, the implicit reasoning ends masked while reasoning.
_get_constraint_bounds(request, spec_tokens, spec_tokens_committed=False)
¶
Return the index into spec_tokens where tokens should start being
constrained by the grammar.
Assumes spec_tokens are stripped of -1 padding tokens.
Returns len(spec_tokens) + 1 if no token should be constrained after
accepting all spec_tokens.
This is constraint_start; grammar_start is one less if reasoning ends
implicitly on a content token (e.g. a tool-call start).
spec_tokens_committed is True if spec_tokens is already in
request.all_token_ids.
_masked_reasoning_ends(request)
¶
Implicit reasoning-end tokens the grammar rejects as first content.
Such a token (e.g. a tool-call start) ends reasoning and is also the first content token, so sampling one where the grammar cannot start with it would make the output invalid. These stay masked while the request reasons. The grammar does not advance before reasoning ends, so the set is fixed per request.
accept_tokens(request, new_token_ids)
¶
Advance grammar with accepted tokens. Returns False on rejection.
trim_spec_tokens(request, spec_tokens)
¶
Trim structured-output padding and grammar-invalid suffixes.