vllm.tool_parsers.structural_tag_registry ¶
Functions:
-
get_model_structural_tag–Build a structural tag with xgrammar's builtin model templates.
-
register_vllm_structural_tag–Register a vLLM-owned structural tag builder.
_K3_STRING_ATOM = '(?:[^<]|<[^|])' module-attribute ¶
One raw-string character: anything but the ambiguous "<|" marker prefix. Allows '<' inside values (e.g. HTML snippets); a value ending in '<' or containing a literal "<|" is not expressible and falls back to AnyText via the pattern checks below never matching those cases at build time (schemas cannot know values, so the only build-time effect is the length bound).
_dump_tool_choice_for_xgrammar(tool_choice) ¶
Convert tool_choice objects to xgrammar's expected protocol.
Source code in vllm/tool_parsers/structural_tag_registry.py
_dump_tool_for_xgrammar(tool) ¶
Convert tool objects to xgrammar's Chat Completions tool protocol.
Source code in vllm/tool_parsers/structural_tag_registry.py
_k3_argument_tag(key, schema, root_defs=None) ¶
Build one argument XTML tag for property key.
string values are emitted raw (bounded by the close marker); every other JSON type is emitted as JSON and validated against the property schema. A property whose type is a union / missing is left permissive (any XTML type, raw value) so a valid call is never rejected.
root_defs carries the tool parameters' root-level $defs / definitions: slicing a property out of the parameters document orphans its #/$defs/... references, so those tables must be re-attached to keep the embedded schema self-contained.
Source code in vllm/tool_parsers/structural_tag_registry.py
_k3_arguments_block(parameters) ¶
Build argument tags for a tool's parameter schema.
Require at least one tag when the root schema declares required properties. Otherwise, keep accepting zero-or-more tags. Arguments remain order-agnostic and non-unique.
Source code in vllm/tool_parsers/structural_tag_registry.py
_k3_bounded_string_regex(prop) ¶
Length/pattern constraint for the raw string channel, if expressible.
The XTML string channel emits values raw (not JSON-quoted), so JSONSchemaFormat cannot enforce string constraints there; unconstrained AnyText lets maxLength/pattern violations through (observed on the walle verifier: over-long junk strings pass the grammar and fail validation). xgrammar's regex engine has no lookahead, so the close marker is kept unambiguous by excluding the "<|" prefix from value characters.
Returns a regex for the value, or None to keep permissive AnyText.
Source code in vllm/tool_parsers/structural_tag_registry.py
_k3_call_tag(tool) ¶
One call tag: <|open|>call tool="N" index="<digits>"<|sep|> args.
Source code in vllm/tool_parsers/structural_tag_registry.py
_k3_escape_attr(value) ¶
_k3_permissive_argument_tag() ¶
A key/type-agnostic argument tag: any attributes, raw value.
Used as a fallback so tools with union/loose schemas still get the XTML skeleton constrained without over-rejecting the value.
Source code in vllm/tool_parsers/structural_tag_registry.py
_k3_response_prefix() ¶
The response channel that always precedes the tools channel.
response is generated in thinking mode (prefix ends at <|open|>think<|sep|>) but is part of the generation prefix in non-thinking mode, so its open marker is optional. The body is bounded by the response close marker.
Source code in vllm/tool_parsers/structural_tag_registry.py
get_model_structural_tag(model, tools, tool_choice, reasoning) ¶
Build a structural tag with xgrammar's builtin model templates.
Source code in vllm/tool_parsers/structural_tag_registry.py
register_vllm_structural_tag(model) ¶
Register a vLLM-owned structural tag builder.