Builtin Structural Tag

This page contains the API reference for the structural tag template function. For its usage, see Tool Calling and Reasoning.

Global Functions

The main public entry points are:

get_model_structural_tag(model[, tools, ...])

Get a structural tag for a model's reasoning and tool-call output format.

normalize_tool_choice([tools, tool_choice])

Normalize tools and tool choice for structural tag builders.

register_model_structural_tag(name, *[, ...])

Register a model-specific structural tag function under name.

xgrammar.builtin_structural_tag.get_builtin_structural_tag()

Deprecated alias for get_model_structural_tag().

All APIs

The remaining model-specific structural tag builders are generated from xgrammar.builtin_structural_tag automatically.

Functions:

get_model_structural_tag(model[, tools, ...])

Get a structural tag for a model's reasoning and tool-call output format.

normalize_tool_choice([tools, tool_choice])

Normalize tools and tool choice for structural tag builders.

register_model_structural_tag(name, *[, ...])

Register a model-specific structural tag function under name.

get_llama_structural_tag([tools, ...])

Get Llama style structural tag format.

get_kimi_structural_tag([tools, ...])

Get Kimi-K2 style structural tag format.

get_kimi_k3_structural_tag([tools, ...])

Get Kimi-K3 style structural tag format.

get_deepseek_r1_structural_tag([tools, ...])

Get DeepSeek-R1 style structural tag format.

get_deepseek_v3_1_structural_tag([tools, ...])

Get DeepSeek-V3.1 style structural tag format.

get_qwen_3_5_structural_tag([tools, ...])

Get Qwen XML tool-call structural tag format.

get_qwen_3_coder_structural_tag([tools, ...])

Deprecated alias for get_qwen_3_5_structural_tag().

get_mimo_structural_tag([tools, ...])

Get MiMo-V2.6 style structural tag format.

get_qwen_3_structural_tag([tools, ...])

Get Qwen3 style structural tag format.

get_harmony_structural_tag([tools, ...])

Get harmony(gpt-oss) style structural tag format.

get_deepseek_v3_2_structural_tag([tools, ...])

Get DeepSeek-V3.2 style structural tag format.

get_minimax_structural_tag([tools, ...])

Get MiniMax-M2.5 style structural tag format.

get_minimax_m3_structural_tag([tools, ...])

Get MiniMax-M3 style structural tag format.

get_glm_4_7_structural_tag([tools, ...])

Get GLM-4.7/GLM-5 style structural tag format.

get_gemma_4_structural_tag([tools, ...])

Get Gemma 4 style structural tag format.

get_deepseek_v4_structural_tag([tools, ...])

Get DeepSeek-V4 style structural tag format.

get_deepseek_v4_1_structural_tag([tools, ...])

Get DeepSeek-V4.1-Flash reasoning and tool-call structural tag format.

get_cohere_structural_tag([tools, ...])

Get Cohere style structural tag format.

get_exaone_structural_tag([tools, ...])

Get EXAONE 4.0 style structural tag format.

get_builtin_structural_tag(model[, tools, ...])

Alias for get_model_structural_tag().

xgrammar.builtin_structural_tag.get_model_structural_tag(model: str, tools: List[FunctionToolParam | BuiltinToolParam | dict] | None = None, tool_choice: Literal['none', 'auto', 'required'] | NamedToolChoiceParam | AllowedToolChoiceParam | BuiltinToolChoiceParam | dict | None = 'auto', reasoning: bool | Literal['enabled', 'disabled', 'auto'] = 'enabled', force_reasoning: bool = False, any_order: bool = False, exclude_special_tokens: bool = True, max_whitespace_cnt: int | None = None, parallel_tool_calls: bool = True, token_markers: bool = False) → StructuralTag[source]

Get a structural tag for a model’s reasoning and tool-call output format.

Use this function when a serving engine needs a structural tag that matches a model’s tool-call syntax. Pass the model format, the available tools, and the desired tool choice policy.

This API is designed to resemble OpenAI Chat Completions API.

Function tools use the OpenAI Chat Completions shape: {"type": "function", "function": {...}}.

Builtin tools use a compact shape:

  • type is the provider-level builtin tool type, such as "web_search_preview".

  • name is the exact tool name that may appear in model output. If it is omitted, type is used as the output name.

  • parameters is the JSON schema used to constrain the arguments emitted by the model.

Examples

Ordinary function tool:

structural_tag = get_model_structural_tag(
    "llama",
    tools=[
        {
            "type": "function",
            "function": {
                "name": "get_weather",
                "parameters": {
                    "type": "object",
                    "properties": {"location": {"type": "string"}},
                },
            },
        }
    ],
)

Harmony with a builtin web search tool:

structural_tag = get_model_structural_tag(
    "harmony",
    tools=[
        {
            "type": "web_search_preview",
            "name": "browser.search",
            "parameters": {
                "type": "object",
                "properties": {"query": {"type": "string"}},
                "required": ["query"],
            },
        }
    ],
)

Force an ordinary function tool:

structural_tag = get_model_structural_tag(
    "llama",
    tools=[
        {
            "type": "function",
            "function": {
                "name": "get_weather",
                "parameters": {
                    "type": "object",
                    "properties": {"location": {"type": "string"}},
                },
            },
        }
    ],
    tool_choice={
        "type": "function",
        "function": {"name": "get_weather"},
    },
)

Force a builtin tool by type and output name:

structural_tag = get_model_structural_tag(
    "harmony",
    tools=[...],
    tool_choice={"type": "web_search_preview"},
)

Allow only a subset of tools:

structural_tag = get_model_structural_tag(
    "harmony",
    tools=[...],
    tool_choice={
        "type": "allowed_tools",
        "allowed_tools": {
            "mode": "auto",
            "tools": [
                {"type": "function", "function": {"name": "get_weather"}},
                {"type": "web_search_preview"},
            ],
        },
    },
)
Parameters:
  • model (str) – The model type of the structural tag template. It should be one of the registered values.

  • tools (Optional[List[Union[ToolParam, dict]]]) – Function and builtin tools available to the model. Function tools use the Chat Completions shape. Builtin tools use type plus optional name and parameters fields. Defaults to None, which is treated as an empty list.

  • tool_choice (Union[ToolChoiceOptionParam, dict, None]) –

    Controls whether the model may or must call tools. Defaults to "auto".

    • "auto" lets the model choose between text output and tool calls.

    • None is treated the same as "auto".

    • "none" disables all tools.

    • "required" requires at least one available tool.

    • {"type": "function", "function": {"name": ...}} forces one function tool.

    • {"type": <builtin_type>} forces one builtin tool. Builtin tool choices are matched by type.

    • {"type": "allowed_tools", "allowed_tools": ...} limits the available tools before applying its mode. Its tools list may contain both function refs and builtin refs. Builtin refs are matched by type.

  • reasoning (Union[bool, Literal["enabled", "disabled", "auto"]]) – Controls the model-specific reasoning section. Use the recommended string modes "enabled", "disabled", or "auto". For models with a leading reasoning block, "auto" allows either a complete block or a direct response/tool call. Defaults to "enabled". The boolean aliases True and False are deprecated but remain supported by this dispatcher as "enabled" and "disabled", respectively. Model-specific builders accept the three string modes.

  • force_reasoning (bool) – Deprecated. Control whether to keep the reasoning part but leave its content empty. Now we will embed the model’s specific behavior into the structural tag function, so only controlling reasoning is enough.

  • any_order (bool) – Relax object property ordering for every tool-argument schema. When True, any_order=True is applied to every JSONSchemaFormat in the generated structural tag, so each tool’s arguments may be emitted in any property order (see JSONSchemaFormat for the exact semantics). When False (default), the declared property order is kept with full validation. Default: False.

  • exclude_special_tokens (bool) – Whether to forbid model special tokens (such as <think> and </think>) from appearing inside the free-text and triggered-text spans of the structural tag. Defaults to True, which keeps the free-text spans constrained to exclude those tokens. Set to False to allow them to appear as plain text. For models that have no special tokens to exclude (such as "harmony"), this has no effect. For Kimi-K3, this also applies to tool-argument string values without pattern/format and to property names, nested JSON strings included; minLength/maxLength on such strings are dropped with a warning.

  • max_whitespace_cnt (Optional[int]) – Applied to every tool-argument JSONSchemaFormat. Caps the number of consecutive whitespace characters. Setting it (e.g. 2) bounds runs of whitespace, which avoids the unbounded-whitespace outputs some models emit in bad cases that would otherwise blow up grammar compilation/matching. Default: None.

  • parallel_tool_calls (bool) – Whether the model may emit more than one tool call in a single response. Follows the OpenAI Chat Completions parameter of the same name. Default True, which keeps the multi-call grammar. When False, the structural tag allows at most one tool call, so the response holds exactly zero or one call under tool_choice="auto" and exactly one under "required" or a forced tool. Because a second call is no longer reachable, generation must end once the single call is closed: free text is still allowed before the call but not after it.

  • token_markers (bool) – Whether to match the control markers (<tool_call>, </think>, …) as their dedicated tokens instead of as strings, for output parsers that recognise the markers by token ID. Supported for "glm_4_7", "qwen_3", "qwen_3_5" and "qwen_3_coder". Default: False.

Notes

If a tool’s parameters field is omitted or None, its generated arguments are unconstrained JSON. If a function tool has strict=False, its parameters schema is also treated as unconstrained. MiniMax M3’s fixed-name XML converter currently rejects such unconstrained schemas.

Returns:

A structural tag for function calling format.

Return type:

StructuralTag

Raises:

ValueError – If tool lists, tool choices, reasoning modes, or required tool availability are invalid, or if token_markers is requested for a model that does not declare its markers.

xgrammar.builtin_structural_tag.normalize_tool_choice(tools: List[FunctionToolParam | BuiltinToolParam | dict] | None = None, tool_choice: Literal['none', 'auto', 'required'] | NamedToolChoiceParam | AllowedToolChoiceParam | BuiltinToolChoiceParam | dict | None = 'auto') → Tuple[List[FunctionToolParam], List[BuiltinToolParam], Literal['auto', 'required', 'forced']][source]

Normalize tools and tool choice for structural tag builders.

This helper exposes the model-independent part of get_model_structural_tag(). It is intended for serving engines that want to own their model-specific structural tag templates while reusing OpenAI-style tool and tool-choice handling.

The return value is not a new public tool-calling protocol. It is a compact prepared form for structural tag builder functions:

  • ordinary function tools are returned as FunctionToolParam objects;

  • builtin/server tools are returned as BuiltinToolParam objects;

  • public tool-choice values are simplified to "auto", "required", or "forced".

Parameters:
  • tools (Optional[List[Union[ToolParam, dict]]]) – Function and builtin tools available to the model. Function tools use the OpenAI Chat Completions shape, {"type": "function", "function": {...}}. Builtin tools use type plus optional name and parameters fields. None is treated as an empty list.

  • tool_choice (Union[ToolChoiceOptionParam, dict, None]) –

    Controls whether the model may or must call tools. This accepts the same values as get_model_structural_tag():

    • "auto" keeps all available tools and lets the builder allow text or tool calls.

    • None is treated as "auto".

    • "none" clears all tools and returns simplified choice "auto". Builders already interpret auto with no tools as text-only.

    • "required" keeps all available tools and requires at least one function or builtin tool to remain available.

    • {"type": "function", "function": {"name": ...}} filters to the named function tool and returns simplified choice "forced".

    • {"type": <builtin_type>} filters to exactly one builtin tool whose type matches and returns simplified choice "forced".

    • {"type": "allowed_tools", "allowed_tools": ...} filters to the referenced tools and returns the nested allowed-tools mode as the simplified choice.

Returns:

A tuple of (function_tools, builtin_tools, simplified_tool_choice) ready to pass to a model-specific structural tag builder.

Return type:

Tuple[List[FunctionToolParam], List[BuiltinToolParam], SimplifiedToolChoice]

Raises:

ValueError – If tools is not a list, a referenced tool is missing, a builtin tool choice does not match exactly one builtin tool, required leaves no available tools, or forced does not resolve to exactly one tool.

Examples

Build tool-choice handling with an external model-specific builder:

function_tools, builtin_tools, tool_choice = normalize_tool_choice(
    tools=[
        {
            "type": "function",
            "function": {
                "name": "get_weather",
                "parameters": {
                    "type": "object",
                    "properties": {"location": {"type": "string"}},
                },
            },
        }
    ],
    tool_choice={
        "type": "function",
        "function": {"name": "get_weather"},
    },
)

structural_tag = build_my_model_structural_tag(
    function_tools,
    builtin_tools,
    tool_choice,
    reasoning="enabled",
)
xgrammar.builtin_structural_tag.register_model_structural_tag(name: str, *, marker_tokens: List[str] | None = None)[source]

Register a model-specific structural tag function under name.

The decorated function is stored in the internal registry so that get_model_structural_tag() can look it up by the model argument. Use this to add support for a new model format.

Parameters:
  • name (str) – The model format key, e.g. "llama", "harmony".

  • marker_tokens (Optional[List[str]]) – The model’s control markers that are single tokens in its tokenizer. Declaring them enables token_markers=True in get_model_structural_tag(). Default: None.

Examples

@register_model_structural_tag("my_model")
def get_my_model_structural_tag(
    tools=None, builtin_tools=None, tool_choice="auto",
    reasoning="enabled", **kwargs,
):
    ...
xgrammar.builtin_structural_tag.get_llama_structural_tag(tools: List[FunctionToolParam] | None = None, builtin_tools: List[BuiltinToolParam] | None = None, tool_choice: Literal['auto', 'required', 'forced'] = 'auto', reasoning: Literal['enabled', 'disabled', 'auto'] = 'enabled', any_order: bool = False, exclude_special_tokens: bool = True, max_whitespace_cnt: int | None = None, parallel_tool_calls: bool = True, **kwargs: Any) → StructuralTag[source]

Get Llama style structural tag format.

Corresponding model key: "llama".

Reference: https://www.llama.com/docs/model-cards-and-prompt-formats/llama3_1/

Parameters are normalized by get_model_structural_tag() before this function is called:

  • tools: a list of function tools. Each tool should have a function object containing name and parameters fields.

  • reasoning: ignored because this format has no reasoning part.

Supported models:

  • Meta-Llama-3

  • Llama-3.1

  • Llama-3.2

Returns:

A structural tag for function calling format. This format is used by Llama 3 and other models that follow the same style.

Return type:

StructuralTag

xgrammar.builtin_structural_tag.get_kimi_structural_tag(tools: List[FunctionToolParam] | None = None, builtin_tools: List[BuiltinToolParam] | None = None, tool_choice: Literal['auto', 'required', 'forced'] = 'auto', reasoning: Literal['enabled', 'disabled', 'auto'] = 'enabled', any_order: bool = False, exclude_special_tokens: bool = True, max_whitespace_cnt: int | None = None, parallel_tool_calls: bool = True, **kwargs: Any) → StructuralTag[source]

Get Kimi-K2 style structural tag format.

Corresponding model key: "kimi".

Reference: https://huggingface.co/moonshotai/Kimi-K2-Instruct/blob/main/docs/tool_call_guidance.md

Parameters are normalized by get_model_structural_tag() before this function is called:

  • tools: a list of function tools. Each tool should have a function object containing name and parameters fields.

  • reasoning: "enabled" keeps the reasoning part, "disabled" removes it, and "auto" makes a complete reasoning block optional.

Supported models:

  • Kimi-K2

  • Kimi-K2.5

Returns:

A structural tag template. This format is used by Kimi-K2 and other models that follow the same style.

Return type:

StructuralTag

xgrammar.builtin_structural_tag.get_kimi_k3_structural_tag(tools: List[FunctionToolParam] | None = None, builtin_tools: List[BuiltinToolParam] | None = None, tool_choice: Literal['auto', 'required', 'forced'] = 'auto', reasoning: Literal['enabled', 'disabled', 'auto'] = 'enabled', any_order: bool = False, exclude_special_tokens: bool = True, max_whitespace_cnt: int | None = None, parallel_tool_calls: bool = True, **kwargs: Any) → StructuralTag[source]

Get Kimi-K3 style structural tag format.

Corresponding model key: "kimi_k3".

Kimi-K3 uses a token-delimited block format instead of the Kimi-K2 style. An assistant message looks like:

<|open|>think<|sep|>...<|close|>think<|sep|>
<|open|>response<|sep|>...<|close|>response<|sep|>
<|open|>tools<|sep|>
    <|open|>call tool="NAME" index="1"<|sep|>
        <|open|>argument key="KEY" type="TYPE"<|sep|>VALUE<|close|>argument<|sep|>
        ...
    <|close|>call<|sep|>
    ...
<|close|>tools<|sep|>
<|close|>message<|sep|>

(line breaks above are for readability only; the blocks are emitted back to back).

The chat template’s generation prompt already ends with the opening marker of the first block – <|open|>think<|sep|> in thinking mode and <|open|>response<|sep|> otherwise – so the constrained output starts inside that block’s body and this structural tag does not include that marker. Every later marker is generated by the model.

The tool-call arguments are emitted one tag per argument and are constrained by JSONSchemaFormat with style="kimi_k3_xml": string values are raw text, and other value types remain JSON-style. With exclude_special_tokens=True, string values without pattern/format and property names exclude <|open|>, <|close|>, and <|sep|> (see JSONSchemaFormat for the exact rules); argument and call wrappers remain outside this exclusion scope.

Parameters are normalized by get_model_structural_tag() before this function is called:

  • tools: a list of function tools. Each tool should have a function object containing name and parameters fields.

  • reasoning: selects "enabled", "disabled", or adaptive "auto" reasoning.

Supported models:

  • Kimi-K3

Returns:

A structural tag template. This format is used by Kimi-K3 and other models that follow the same style.

Return type:

StructuralTag

xgrammar.builtin_structural_tag.get_deepseek_r1_structural_tag(tools: List[FunctionToolParam] | None = None, builtin_tools: List[BuiltinToolParam] | None = None, tool_choice: Literal['auto', 'required', 'forced'] = 'auto', reasoning: Literal['enabled', 'disabled', 'auto'] = 'enabled', any_order: bool = False, exclude_special_tokens: bool = True, max_whitespace_cnt: int | None = None, parallel_tool_calls: bool = True, **kwargs: Any) → StructuralTag[source]

Get DeepSeek-R1 style structural tag format.

Corresponding model key: "deepseek_r1".

Reference: https://huggingface.co/deepseek-ai/DeepSeek-R1/blob/main/tokenizer_config.json

Supported models:

  • DeepSeek-R1

  • DeepSeek-R1-0528

xgrammar.builtin_structural_tag.get_deepseek_v3_1_structural_tag(tools: List[FunctionToolParam] | None = None, builtin_tools: List[BuiltinToolParam] | None = None, tool_choice: Literal['auto', 'required', 'forced'] = 'auto', reasoning: Literal['enabled', 'disabled', 'auto'] = 'enabled', any_order: bool = False, exclude_special_tokens: bool = True, max_whitespace_cnt: int | None = None, parallel_tool_calls: bool = True, **kwargs: Any) → StructuralTag[source]

Get DeepSeek-V3.1 style structural tag format.

Corresponding model key: "deepseek_v3_1".

Reference: https://huggingface.co/deepseek-ai/DeepSeek-V3.1/blob/main/tokenizer_config.json

Supported models:

  • DeepSeek-V3.1

  • DeepSeek-V3.2-Exp

xgrammar.builtin_structural_tag.get_qwen_3_5_structural_tag(tools: List[FunctionToolParam] | None = None, builtin_tools: List[BuiltinToolParam] | None = None, tool_choice: Literal['auto', 'required', 'forced'] = 'auto', reasoning: Literal['enabled', 'disabled', 'auto'] = 'enabled', any_order: bool = False, exclude_special_tokens: bool = True, max_whitespace_cnt: int | None = None, parallel_tool_calls: bool = True, **kwargs: Any) → StructuralTag[source]

Get Qwen XML tool-call structural tag format.

Corresponding model keys: "qwen_3_5" and "qwen_3_coder".

Reference: https://huggingface.co/Qwen/Qwen3-Coder-480B-A35B-Instruct-FP8/blob/main/chat_template.jinja

Parameters are normalized by get_model_structural_tag() before this function is called:

  • tools: a list of function tools. Each tool should have a function object containing name and parameters fields.

  • reasoning: controls whether the reasoning prefix is required, omitted, or optional before the tool/text suffix.

Supported models:

  • Qwen3.5

  • Qwen3.6

  • Qwen3-Coder

  • Qwen3-Coder-Next

Returns:

A structural tag for Qwen XML function calling format.

Return type:

StructuralTag

xgrammar.builtin_structural_tag.get_qwen_3_coder_structural_tag(tools: List[FunctionToolParam] | None = None, builtin_tools: List[BuiltinToolParam] | None = None, tool_choice: Literal['auto', 'required', 'forced'] = 'auto', reasoning: Literal['enabled', 'disabled', 'auto'] = 'enabled', any_order: bool = False, exclude_special_tokens: bool = True, max_whitespace_cnt: int | None = None, parallel_tool_calls: bool = True, **kwargs: Any) → StructuralTag

Deprecated alias for get_qwen_3_5_structural_tag().

xgrammar.builtin_structural_tag.get_mimo_structural_tag(tools: List[FunctionToolParam] | None = None, builtin_tools: List[BuiltinToolParam] | None = None, tool_choice: Literal['auto', 'required', 'forced'] = 'auto', reasoning: Literal['enabled', 'disabled', 'auto'] = 'enabled', any_order: bool = False, exclude_special_tokens: bool = True, max_whitespace_cnt: int | None = None, parallel_tool_calls: bool = True, **kwargs: Any) → StructuralTag[source]

Get MiMo-V2.6 style structural tag format.

Corresponding model key: "mimo".

Reference: https://huggingface.co/XiaomiMiMo/MiMo-V2.6-Pro-RL/blob/main/chat_template.jinja

MiMo uses the Qwen XML parameter format, but without the newlines that Qwen3-Coder puts between the wrapper tags:

<tool_call><function=NAME><parameter=KEY>VALUE</parameter></function></tool_call>

String arguments are raw text; other values are JSON. Arguments are constrained by JSONSchemaFormat with style="qwen_xml".

With enable_thinking=True the chat template ends the generation prompt at <|im_start|>assistant\n, so reasoning="enabled" generates the complete <think>...</think> block. With enable_thinking=False the template renders <think></think> into the prompt; use reasoning="disabled", also when the serving engine manages reasoning itself.

Parameters are normalized by get_model_structural_tag() before this function is called:

  • tools: a list of function tools. Each tool should have a function object containing name and parameters fields.

  • reasoning: selects "enabled", "disabled", or adaptive "auto" reasoning.

Supported models:

  • MiMo-V2.6-Pro-RL

  • MiMo-V2.6-Flash-RL

Returns:

A structural tag for MiMo function calling format.

Return type:

StructuralTag

xgrammar.builtin_structural_tag.get_qwen_3_structural_tag(tools: List[FunctionToolParam] | None = None, builtin_tools: List[BuiltinToolParam] | None = None, tool_choice: Literal['auto', 'required', 'forced'] = 'auto', reasoning: Literal['enabled', 'disabled', 'auto'] = 'enabled', any_order: bool = False, exclude_special_tokens: bool = True, max_whitespace_cnt: int | None = None, parallel_tool_calls: bool = True, **kwargs: Any) → StructuralTag[source]

Get Qwen3 style structural tag format.

Corresponding model key: "qwen_3".

Reference: https://qwen.readthedocs.io/en/latest/framework/function_call.html

Parameters are normalized by get_model_structural_tag() before this function is called:

  • tools: a list of function tools. Each tool should have a function object containing name and parameters fields.

  • reasoning: controls whether the reasoning block is required, omitted, or optional.

Supported models:

  • Qwen3

  • Qwen3-Next

Returns:

A structural tag template. This format is used by Qwen3 and other models that follow the same style.

Return type:

StructuralTag

xgrammar.builtin_structural_tag.get_harmony_structural_tag(tools: List[FunctionToolParam] | None = None, builtin_tools: List[BuiltinToolParam] | None = None, tool_choice: Literal['auto', 'required', 'forced'] = 'auto', reasoning: Literal['enabled', 'disabled', 'auto'] = 'enabled', any_order: bool = False, exclude_special_tokens: bool = True, max_whitespace_cnt: int | None = None, parallel_tool_calls: bool = True, **kwargs: Any) → StructuralTag[source]

Get harmony(gpt-oss) style structural tag format.

Corresponding model key: "harmony".

Reference: https://developers.openai.com/cookbook/articles/openai-harmony Reference: https://huggingface.co/openai/gpt-oss-120b/blob/main/chat_template.jinja

Parameters are normalized by get_model_structural_tag() before this function is called:

  • tools: a list of function tools. Each tool should have a function object containing name and parameters fields.

  • builtin_tools: a list of builtin tools. Each builtin tool should provide type, optional name, and parameters fields.

  • reasoning: controls whether the analysis channel is available.

Supported models:

  • gpt-oss

Returns:

A structural tag template. This format is in OpenAI Harmony Response Format, which is used by GPT-oss and other models that follow the same style.

Return type:

StructuralTag

xgrammar.builtin_structural_tag.get_deepseek_v3_2_structural_tag(tools: List[FunctionToolParam] | None = None, builtin_tools: List[BuiltinToolParam] | None = None, tool_choice: Literal['auto', 'required', 'forced'] = 'auto', reasoning: Literal['enabled', 'disabled', 'auto'] = 'enabled', any_order: bool = False, exclude_special_tokens: bool = True, max_whitespace_cnt: int | None = None, parallel_tool_calls: bool = True, **kwargs: Any) → StructuralTag[source]

Get DeepSeek-V3.2 style structural tag format.

Corresponding model key: "deepseek_v3_2".

Supported models:

  • DeepSeek-V3.2

xgrammar.builtin_structural_tag.get_minimax_structural_tag(tools: List[FunctionToolParam] | None = None, builtin_tools: List[BuiltinToolParam] | None = None, tool_choice: Literal['auto', 'required', 'forced'] = 'auto', reasoning: Literal['enabled', 'disabled', 'auto'] = 'enabled', any_order: bool = False, exclude_special_tokens: bool = True, max_whitespace_cnt: int | None = None, parallel_tool_calls: bool = True, **kwargs: Any) → StructuralTag[source]

Get MiniMax-M2.5 style structural tag format.

Corresponding model key: "minimax".

Supported models:

  • MiniMax-M2.5

  • MiniMax-M2.7

Returns:

A structural tag for MiniMax function calling format.

Return type:

StructuralTag

xgrammar.builtin_structural_tag.get_minimax_m3_structural_tag(tools: List[FunctionToolParam] | None = None, builtin_tools: List[BuiltinToolParam] | None = None, tool_choice: Literal['auto', 'required', 'forced'] = 'auto', reasoning: Literal['enabled', 'disabled', 'auto'] = 'auto', any_order: bool = False, exclude_special_tokens: bool = True, max_whitespace_cnt: int | None = None, parallel_tool_calls: bool = True, **kwargs: Any) → StructuralTag[source]

Get MiniMax-M3 style structural tag format.

MiniMax M3 recursively encodes tool arguments as namespace-prefixed XML. With reasoning="enabled", the matching generation prompt has already emitted <mm:think> and constrained output starts inside its body. "disabled" starts directly at the response body after the matching prompt. "auto" matches the adaptive prompt and accepts either a complete reasoning block or a direct response/tool call, optionally prefixed by </mm:think> when skipping reasoning. "auto" is the default for this model-specific builder.

Corresponding model key: "minimax_m3".

Supported models:

  • MiniMax-M3

Returns:

A structural tag for MiniMax M3 reasoning and function calling.

Return type:

StructuralTag

xgrammar.builtin_structural_tag.get_glm_4_7_structural_tag(tools: List[FunctionToolParam] | None = None, builtin_tools: List[BuiltinToolParam] | None = None, tool_choice: Literal['auto', 'required', 'forced'] = 'auto', reasoning: Literal['enabled', 'disabled', 'auto'] = 'enabled', any_order: bool = False, exclude_special_tokens: bool = True, max_whitespace_cnt: int | None = None, parallel_tool_calls: bool = True, **kwargs: Any) → StructuralTag[source]

Get GLM-4.7/GLM-5 style structural tag format.

The GLM tool calling format uses XML-like tags: <tool_call>function_name <arg_key>key</arg_key><arg_value>value</arg_value> </tool_call>

Corresponding model key: "glm_4_7".

Parameters are normalized by get_model_structural_tag() before this function is called:

  • tools: a list of function tools. Each tool should have a function object containing name and parameters fields.

  • reasoning: selects enabled, disabled, or automatic reasoning mode.

Supported models:

  • GLM-5

  • GLM-4.7

Returns:

A structural tag for GLM function calling format.

Return type:

StructuralTag

xgrammar.builtin_structural_tag.get_gemma_4_structural_tag(tools: List[FunctionToolParam] | None = None, builtin_tools: List[BuiltinToolParam] | None = None, tool_choice: Literal['auto', 'required', 'forced'] = 'auto', reasoning: Literal['enabled', 'disabled', 'auto'] = 'enabled', any_order: bool = False, exclude_special_tokens: bool = True, max_whitespace_cnt: int | None = None, parallel_tool_calls: bool = True, **kwargs: Any) → StructuralTag[source]

Get Gemma 4 style structural tag format.

Gemma 4 uses channel markers for reasoning and tool calls instead of <think>/</think>:

  • Thinking: <|channel>thought\n...thinking...<channel|>

  • Tool calls: <|tool_call>call:func_name{...}<tool_call|>

  • Turn end: <turn|>

Corresponding model key: "gemma_4".

Reference: https://ai.google.dev/gemma/docs/core/prompt-formatting-gemma4

Parameters are normalized by get_model_structural_tag() before this function is called:

  • tools: a list of function tools. Each tool should have a function object containing name and parameters fields.

  • reasoning: controls whether the reasoning channel is required, omitted, or optional.

  • tool_choice: "auto", "required", or "forced". "required" forces at least one tool call; "forced" forces exactly the single resolved tool.

Tool-call arguments use JSONSchemaFormat with style="gemma": keys are unquoted and strings are delimited by the <|"|> token. With exclude_special_tokens=True, argument strings and property names exclude <|tool_call>, <tool_call|>, <|channel> and <channel|> (see JSONSchemaFormat for the exact rules).

Supported models:

  • Gemma-4

  • gemma-4-12b-it

  • gemma-4-26b-a4b-it

  • gemma-4-31b-it

  • gemma-4-e2b-it

Returns:

A structural tag for Gemma 4 function calling format.

Return type:

StructuralTag

xgrammar.builtin_structural_tag.get_deepseek_v4_structural_tag(tools: List[FunctionToolParam] | None = None, builtin_tools: List[BuiltinToolParam] | None = None, tool_choice: Literal['auto', 'required', 'forced'] = 'auto', reasoning: Literal['enabled', 'disabled', 'auto'] = 'enabled', any_order: bool = False, exclude_special_tokens: bool = True, max_whitespace_cnt: int | None = None, parallel_tool_calls: bool = True, **kwargs: Any) → StructuralTag[source]

Get DeepSeek-V4 style structural tag format.

Corresponding model key: "deepseek_v4".

Supported models:

  • DeepSeek-V4

xgrammar.builtin_structural_tag.get_deepseek_v4_1_structural_tag(tools: List[FunctionToolParam] | None = None, builtin_tools: List[BuiltinToolParam] | None = None, tool_choice: Literal['auto', 'required', 'forced'] = 'auto', reasoning: Literal['enabled', 'disabled', 'auto'] = 'enabled', any_order: bool = False, exclude_special_tokens: bool = True, max_whitespace_cnt: int | None = None, parallel_tool_calls: bool = True, **kwargs: Any) → StructuralTag[source]

Get DeepSeek-V4.1-Flash reasoning and tool-call structural tag format.

Corresponding model key: "deepseek_v4_1".

Reference: https://huggingface.co/deepseek-ai/DeepSeek-V4.1-Flash/blob/main/encoding/encoding.py

V4.1 uses <|DSML| calls> with space-prefixed invoke and parameter tags. String arguments are raw text; other values are JSON. Namespace-qualified tools use namespace::name as the function name.

Apply this tag after the generation prompt, which already ends in <think> (reasoning) or </think> (chat). EOS is handled by the tokenizer’s stop token. Reasoning effort and image inputs are encoded in the prompt and do not change the output grammar.

xgrammar.builtin_structural_tag.get_cohere_structural_tag(tools: List[FunctionToolParam] | None = None, builtin_tools: List[BuiltinToolParam] | None = None, tool_choice: Literal['auto', 'required', 'forced'] = 'auto', reasoning: Literal['enabled', 'disabled', 'auto'] = 'enabled', any_order: bool = False, exclude_special_tokens: bool = True, max_whitespace_cnt: int | None = None, parallel_tool_calls: bool = True, **kwargs: Any) → StructuralTag[source]

Get Cohere style structural tag format.

Corresponding model key: "cohere".

Supported models:

  • Cohere Command models using XML tool calls.

xgrammar.builtin_structural_tag.get_exaone_structural_tag(tools: List[FunctionToolParam] | None = None, builtin_tools: List[BuiltinToolParam] | None = None, tool_choice: Literal['auto', 'required', 'forced'] = 'auto', reasoning: Literal['enabled', 'disabled', 'auto'] = 'enabled', any_order: bool = False, exclude_special_tokens: bool = True, max_whitespace_cnt: int | None = None, parallel_tool_calls: bool = True, **kwargs: Any) → StructuralTag[source]

Get EXAONE 4.0 style structural tag format.

Corresponding model key: "exaone".

Reference: https://huggingface.co/LGAI-EXAONE/EXAONE-4.0-32B

Supported models:

  • EXAONE-4.0-32B

  • EXAONE-4.0-1.2B

xgrammar.builtin_structural_tag.get_builtin_structural_tag(model: str, tools: List[FunctionToolParam | BuiltinToolParam | dict] | None = None, tool_choice: Literal['none', 'auto', 'required'] | NamedToolChoiceParam | AllowedToolChoiceParam | BuiltinToolChoiceParam | dict | None = 'auto', reasoning: bool | Literal['enabled', 'disabled', 'auto'] = 'enabled', force_reasoning: bool = False, any_order: bool = False, exclude_special_tokens: bool = True, max_whitespace_cnt: int | None = None, parallel_tool_calls: bool = True, token_markers: bool = False) → StructuralTag

Alias for get_model_structural_tag(). Deprecated.