vllm.tool_parsers.structural_tag_registry
¶
Functions:
-
get_glm_4_7_structural_tag–Build the GLM-4.7 structural tag, dispatching per tool on strictness.
-
get_hy_v4_structural_tag–Build HYV4
/ / / structural tags. -
get_model_structural_tag–Build a structural tag with xgrammar's builtin model templates.
-
get_plamo3_structural_tag–Build PLaMo3's explicit tool-request structural tag.
-
get_structural_tag_tools–Return the tools a structural tag for
modellets the model call. -
limit_to_single_tool_call–Stop every tool-call list in
tagafter its first call, in place. -
register_vllm_structural_tag–Register a vLLM-owned structural tag builder.
-
resolve_tool_strictness–Decide whether a structural tag applies and pin each tool's
strict.
_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
_glm_4_7_plain_properties(params)
¶
Return properties when the schema is a plain object schema.
Source code in vllm/tool_parsers/structural_tag_registry.py
_glm_4_7_strict_tool_tag(tool)
¶
Schema-pinned tag matching the xgrammar builtin's strict content.
Source code in vllm/tool_parsers/structural_tag_registry.py
_glm_4_7_tool_tag(tool)
¶
Shallow tag for a non-strict tool: keys and scalar value types pinned.
Source code in vllm/tool_parsers/structural_tag_registry.py
_hy_v4_argument_keys(parameters)
¶
Split a tool's argument keys into (required, optional).
Both lists keep declaration order. Required keys missing from
properties are still treated as required.
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. Excluding the reserved
marker heads commits <|close|> to the response-close branch immediately
and prevents a nested channel from starting inside response text.
Source code in vllm/tool_parsers/structural_tag_registry.py
_with_tool_strict(tool, strict)
¶
Return a copy of tool with strict set, leaving the request's alone.
Source code in vllm/tool_parsers/structural_tag_registry.py
get_glm_4_7_structural_tag(function_tools, builtin_tools, tool_choice, reasoning, token_suffix='')
¶
Build the GLM-4.7 structural tag, dispatching per tool on strictness.
Parameters:
-
(function_tools¶list[FunctionToolParam]) –Normalized function tools with
strictpinned byresolve_tool_strictness. -
(builtin_tools¶list[BuiltinToolParam]) –Unused; GLM-4.7 has no builtin tools.
-
(tool_choice¶Any) –Simplified tool choice (
auto/required/forced). -
(reasoning¶bool) –Whether the grammar also covers the reasoning phase.
-
(token_suffix¶str, default:'') –Unused; GLM-4.7 structural tokens are fixed.
Source code in vllm/tool_parsers/structural_tag_registry.py
1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 | |
get_hy_v4_structural_tag(tools, builtin_tools, tool_choice, reasoning, token_suffix='')
¶
Build HYV4
Parameters:
-
(tools¶list[FunctionToolParam]) –Normalized function tools the model may call.
-
(builtin_tools¶list[BuiltinToolParam]) –Unused; HYV4 has no builtin tools.
-
(tool_choice¶SimplifiedToolChoice) –Simplified tool choice.
-
(reasoning¶bool) –Whether the grammar also covers the reasoning phase.
-
(token_suffix¶str, default:'') –Per-checkpoint structural-token suffix including the leading colon (e.g.
":6124c78e"), or""when the checkpoint uses unsuffixed tokens. The HYV4 tool parser reads it off the tokenizer vocab and passes it toget_model_structural_tag.
Source code in vllm/tool_parsers/structural_tag_registry.py
880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 | |
get_model_structural_tag(model, tools, tool_choice, reasoning, token_suffix='', strict_level=ToolStrictLevel.AUTO)
¶
Build a structural tag with xgrammar's builtin model templates.
Source code in vllm/tool_parsers/structural_tag_registry.py
get_plamo3_structural_tag(tools, builtin_tools, tool_choice, reasoning, token_suffix='')
¶
Build PLaMo3's explicit tool-request structural tag.
Source code in vllm/tool_parsers/structural_tag_registry.py
get_structural_tag_tools(model, tools, tool_choice)
¶
Return the tools a structural tag for model lets the model call.
Most models are only shown function tools, so their grammar must cover exactly those: a tool missing from the prompt cannot be called, and one missing from the grammar is shown but blocked.
Raises:
-
VLLMValidationError–tool_choicerequires a call, but the model has no tool it can call.
Source code in vllm/tool_parsers/structural_tag_registry.py
limit_to_single_tool_call(tag)
¶
Stop every tool-call list in tag after its first call, in place.
Enforces parallel_tool_calls=false in the grammar. In every registered
tag, _TOOL_CALL_LIST_FORMATS repeat tool calls, never arguments.
Source code in vllm/tool_parsers/structural_tag_registry.py
register_vllm_structural_tag(model, *, builtin_tools=False)
¶
Register a vLLM-owned structural tag builder.
Parameters:
-
(model¶str) –Structural tag model key.
-
(builtin_tools¶bool, default:False) –Whether the model can call non-function tools, so its builder receives every request tool instead of only the function tools from
get_function_tools.
Source code in vllm/tool_parsers/structural_tag_registry.py
resolve_tool_strictness(tools, tool_choice, strict_level)
¶
Decide whether a structural tag applies and pin each tool's strict.
A tool without an explicit strict is treated as non-strict: its call
envelope is still constrained, but its arguments stay free unless the
server level is PARAMETER. None means no structural tag.