Structural Tag

This page contains the API reference for the structural tag. For its usage, see Structural Tag Usage.

Top Level Classes

class xgrammar.StructuralTag(*, type: Literal['structural_tag'] = 'structural_tag', format: Union[AnyTextFormat, ConstStringFormat, JSONSchemaFormat, GrammarFormat, RegexFormat, QwenXMLParameterFormat, OrFormat, SequenceFormat, TagFormat, TriggeredTagsFormat, TokenTriggeredTagsFormat, TagsWithSeparatorFormat, OptionalFormat, PlusFormat, StarFormat, TokenFormat, ExcludeTokenFormat, AnyTokensFormat, RepeatFormat, DispatchFormat, TokenDispatchFormat])[source]

Bases: BaseModel

Describes a complete structural tag structure. It corresponds to "response_format": {"type": "structural_tag", "format": {...}} in API.

field type: Literal['structural_tag'] = 'structural_tag'

The type must be “structural_tag”.

field format: Union[AnyTextFormat, ConstStringFormat, JSONSchemaFormat, GrammarFormat, RegexFormat, QwenXMLParameterFormat, OrFormat, SequenceFormat, TagFormat, TriggeredTagsFormat, TokenTriggeredTagsFormat, TagsWithSeparatorFormat, OptionalFormat, PlusFormat, StarFormat, TokenFormat, ExcludeTokenFormat, AnyTokensFormat, RepeatFormat, DispatchFormat, TokenDispatchFormat] [Required]

The format of the structural tag. Could be any of the structural tag formats.

static from_legacy_structural_tag(tags: List[StructuralTagItem], triggers: List[str]) StructuralTag[source]

Convert a legacy structural tag item to a structural tag.

static from_json(json_str: Union[str, Dict[str, Any]]) StructuralTag[source]

Convert a JSON string to a structural tag.

class xgrammar.structural_tag.StructuralTagItem(*, begin: str, schema: Union[str, Type[BaseModel], Dict[str, Any]], end: str)[source]

Bases: BaseModel

Deprecated. Definition of a structural tag item.

See xgrammar.Grammar.from_structural_tag() for more details.

field begin: str [Required]

The begin tag.

field schema_: Union[str, Type[BaseModel], Dict[str, Any]] [Required] (alias 'schema')

The schema.

field end: str [Required]

The end tag.

Format Union

xgrammar.structural_tag.Format(*args, **kwargs)

Union of all structural tag formats.

alias of Annotated[Union[AnyTextFormat, ConstStringFormat, JSONSchemaFormat, GrammarFormat, RegexFormat, QwenXMLParameterFormat, OrFormat, SequenceFormat, TagFormat, TriggeredTagsFormat, TokenTriggeredTagsFormat, TagsWithSeparatorFormat, OptionalFormat, PlusFormat, StarFormat, TokenFormat, ExcludeTokenFormat, AnyTokensFormat, RepeatFormat, DispatchFormat, TokenDispatchFormat]]

Basic Formats

pydantic model xgrammar.structural_tag.ConstStringFormat[source]

Bases: BaseModel

A format that matches a constant string.

Show JSON schema
{
   "title": "ConstStringFormat",
   "description": "A format that matches a constant string.",
   "type": "object",
   "properties": {
      "type": {
         "const": "const_string",
         "default": "const_string",
         "title": "Type",
         "type": "string"
      },
      "value": {
         "title": "Value",
         "type": "string"
      }
   },
   "required": [
      "value"
   ]
}

field type: Literal['const_string'] = 'const_string'

The type of the format.

field value: str [Required]

The constant string.

pydantic model xgrammar.structural_tag.JSONSchemaFormat[source]

Bases: BaseModel

A format that matches a JSON schema.

Show JSON schema
{
   "title": "JSONSchemaFormat",
   "description": "A format that matches a JSON schema.",
   "type": "object",
   "properties": {
      "type": {
         "const": "json_schema",
         "default": "json_schema",
         "title": "Type",
         "type": "string"
      },
      "json_schema": {
         "anyOf": [
            {
               "type": "boolean"
            },
            {
               "additionalProperties": true,
               "type": "object"
            }
         ],
         "title": "Json Schema"
      },
      "style": {
         "default": "json",
         "enum": [
            "json",
            "qwen_xml",
            "minimax_xml",
            "deepseek_xml",
            "glm_xml"
         ],
         "title": "Style",
         "type": "string"
      }
   },
   "required": [
      "json_schema"
   ]
}

field type: Literal['json_schema'] = 'json_schema'

The type of the format.

field json_schema: Union[bool, Dict[str, Any]] [Required]

The JSON schema.

field style: Literal['json', 'qwen_xml', 'minimax_xml', 'deepseek_xml', 'glm_xml'] = 'json'

How to parse the content. Valid values: “json” (standard JSON), “qwen_xml” (Qwen XML: <parameter=key>value</parameter>), “minimax_xml” (MiniMax XML: <parameter name=”key”>value</parameter>), “deepseek_xml” (DeepSeek XML(DeepSeek-v3.2): <{dsml_token}parameter name=”key” string=”true|false”>value</{dsml_token}parameter>), “glm_xml” (GLM XML: <arg_key>key</arg_key><arg_value>value</arg_value>).

pydantic model xgrammar.structural_tag.AnyTextFormat[source]

Bases: BaseModel

A format that matches any text.

Show JSON schema
{
   "title": "AnyTextFormat",
   "description": "A format that matches any text.",
   "type": "object",
   "properties": {
      "type": {
         "const": "any_text",
         "default": "any_text",
         "title": "Type",
         "type": "string"
      },
      "excludes": {
         "default": [],
         "items": {
            "type": "string"
         },
         "title": "Excludes",
         "type": "array"
      }
   }
}

field type: Literal['any_text'] = 'any_text'

The type of the format.

field excludes: List[str] = []

List of strings that should not appear in the matched text.

pydantic model xgrammar.structural_tag.GrammarFormat[source]

Bases: BaseModel

A format that matches an ebnf grammar.

Show JSON schema
{
   "title": "GrammarFormat",
   "description": "A format that matches an ebnf grammar.",
   "type": "object",
   "properties": {
      "type": {
         "const": "grammar",
         "default": "grammar",
         "title": "Type",
         "type": "string"
      },
      "grammar": {
         "title": "Grammar",
         "type": "string"
      }
   },
   "required": [
      "grammar"
   ]
}

field type: Literal['grammar'] = 'grammar'

The type of the format.

field grammar: str [Required]

The ebnf grammar.

pydantic model xgrammar.structural_tag.RegexFormat[source]

Bases: BaseModel

A format that matches a regex pattern.

Show JSON schema
{
   "title": "RegexFormat",
   "description": "A format that matches a regex pattern.",
   "type": "object",
   "properties": {
      "type": {
         "const": "regex",
         "default": "regex",
         "title": "Type",
         "type": "string"
      },
      "pattern": {
         "title": "Pattern",
         "type": "string"
      }
   },
   "required": [
      "pattern"
   ]
}

field type: Literal['regex'] = 'regex'

The type of the format.

field pattern: str [Required]

The regex pattern.

pydantic model xgrammar.structural_tag.QwenXMLParameterFormat[source]

Bases: BaseModel

Deprecated. Use JSONSchemaFormat with style="qwen_xml" instead.

This format remains available so existing serialized structural tags with {"type": "qwen_xml_parameter"} can still be loaded.

Examples

Use the replacement format for new structural tags:

structural_tag = JSONSchemaFormat(
    json_schema={
        "type": "object",
        "properties": {"name": {"type": "string"}, "age": {"type": "integer"}},
        "required": ["name", "age"],
    },
    style="qwen_xml",
)

The above structural tag can accept the following outputs:

<parameter=name>Bob</parameter><parameter=age>100</parameter>
<parameter=name>"Bob&lt;"</parameter><parameter=age>100</parameter>

Show JSON schema
{
   "title": "QwenXMLParameterFormat",
   "description": "Deprecated. Use :class:`JSONSchemaFormat` with ``style=\"qwen_xml\"`` instead.\n\nThis format remains available so existing serialized structural tags with\n``{\"type\": \"qwen_xml_parameter\"}`` can still be loaded.\n\nExamples\n--------\nUse the replacement format for new structural tags:\n\n.. code-block:: python\n\n    structural_tag = JSONSchemaFormat(\n        json_schema={\n            \"type\": \"object\",\n            \"properties\": {\"name\": {\"type\": \"string\"}, \"age\": {\"type\": \"integer\"}},\n            \"required\": [\"name\", \"age\"],\n        },\n        style=\"qwen_xml\",\n    )\n\nThe above structural tag can accept the following outputs::\n\n    <parameter=name>Bob</parameter><parameter=age>100</parameter>\n    <parameter=name>\"Bob&lt;\"</parameter><parameter=age>100</parameter>",
   "type": "object",
   "properties": {
      "type": {
         "const": "qwen_xml_parameter",
         "default": "qwen_xml_parameter",
         "title": "Type",
         "type": "string"
      },
      "json_schema": {
         "anyOf": [
            {
               "type": "boolean"
            },
            {
               "additionalProperties": true,
               "type": "object"
            }
         ],
         "title": "Json Schema"
      }
   },
   "required": [
      "json_schema"
   ]
}

field type: Literal['qwen_xml_parameter'] = 'qwen_xml_parameter'

The type of the deprecated format.

field json_schema: Union[bool, Dict[str, Any]] [Required]

The JSON schema for the parameters of the function calling.

Combinatorial Formats

pydantic model xgrammar.structural_tag.SequenceFormat[source]

Bases: BaseModel

A format that matches a sequence of formats.

Show JSON schema
{
   "$defs": {
      "AnyTextFormat": {
         "description": "A format that matches any text.",
         "properties": {
            "type": {
               "const": "any_text",
               "default": "any_text",
               "title": "Type",
               "type": "string"
            },
            "excludes": {
               "default": [],
               "items": {
                  "type": "string"
               },
               "title": "Excludes",
               "type": "array"
            }
         },
         "title": "AnyTextFormat",
         "type": "object"
      },
      "AnyTokensFormat": {
         "description": "A format that matches zero or more tokens, excluding those in the given set.",
         "properties": {
            "type": {
               "const": "any_tokens",
               "default": "any_tokens",
               "title": "Type",
               "type": "string"
            },
            "exclude_tokens": {
               "default": [],
               "items": {
                  "anyOf": [
                     {
                        "type": "integer"
                     },
                     {
                        "type": "string"
                     }
                  ]
               },
               "title": "Exclude Tokens",
               "type": "array"
            }
         },
         "title": "AnyTokensFormat",
         "type": "object"
      },
      "ConstStringFormat": {
         "description": "A format that matches a constant string.",
         "properties": {
            "type": {
               "const": "const_string",
               "default": "const_string",
               "title": "Type",
               "type": "string"
            },
            "value": {
               "title": "Value",
               "type": "string"
            }
         },
         "required": [
            "value"
         ],
         "title": "ConstStringFormat",
         "type": "object"
      },
      "DispatchFormat": {
         "description": "Matches certain patterns in free-form text.\nWhen certain strings are generated, the following content must follow the corresponding format.\nCertain strings can be excluded from being generated in the free-form part.\n\nThe user specifies a list of (pattern, formats). The LLM can generate any free-form text, but\nwhen a pattern is matched in the text, the following output must follow the corresponding format.\nThe ``loop`` field controls whether the matching of this structure ends after accepting the first\npattern and format. If False, it ends. If true, the matching continues, and this format will\ncontinue to allow free-form text and detect the next pattern to be generated.\nThe ``excludes`` field controls the strings that cannot be generated in the free-form text.\nIt can also control the end of the format:\n``SequenceFormat(DispatchFormat(..., excludes=\"\"), ConstStringFormat(\"\"))``\nor\n``TagFormat(begin=..., content=DispatchFormat(..., excludes=\"\"), end=\"\")``\nends the matching of the format when LLM generates <end>.",
         "properties": {
            "type": {
               "const": "dispatch",
               "default": "dispatch",
               "title": "Type",
               "type": "string"
            },
            "rules": {
               "items": {
                  "maxItems": 2,
                  "minItems": 2,
                  "prefixItems": [
                     {
                        "type": "string"
                     },
                     {
                        "discriminator": {
                           "mapping": {
                              "any_text": "#/$defs/AnyTextFormat",
                              "any_tokens": "#/$defs/AnyTokensFormat",
                              "const_string": "#/$defs/ConstStringFormat",
                              "dispatch": "#/$defs/DispatchFormat",
                              "exclude_token": "#/$defs/ExcludeTokenFormat",
                              "grammar": "#/$defs/GrammarFormat",
                              "json_schema": "#/$defs/JSONSchemaFormat",
                              "optional": "#/$defs/OptionalFormat",
                              "or": "#/$defs/OrFormat",
                              "plus": "#/$defs/PlusFormat",
                              "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                              "regex": "#/$defs/RegexFormat",
                              "repeat": "#/$defs/RepeatFormat",
                              "sequence": "#/$defs/SequenceFormat",
                              "star": "#/$defs/StarFormat",
                              "tag": "#/$defs/TagFormat",
                              "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                              "token": "#/$defs/TokenFormat",
                              "token_dispatch": "#/$defs/TokenDispatchFormat",
                              "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                              "triggered_tags": "#/$defs/TriggeredTagsFormat"
                           },
                           "propertyName": "type"
                        },
                        "oneOf": [
                           {
                              "$ref": "#/$defs/AnyTextFormat"
                           },
                           {
                              "$ref": "#/$defs/ConstStringFormat"
                           },
                           {
                              "$ref": "#/$defs/JSONSchemaFormat"
                           },
                           {
                              "$ref": "#/$defs/GrammarFormat"
                           },
                           {
                              "$ref": "#/$defs/RegexFormat"
                           },
                           {
                              "$ref": "#/$defs/QwenXMLParameterFormat"
                           },
                           {
                              "$ref": "#/$defs/OrFormat"
                           },
                           {
                              "$ref": "#/$defs/SequenceFormat"
                           },
                           {
                              "$ref": "#/$defs/TagFormat"
                           },
                           {
                              "$ref": "#/$defs/TriggeredTagsFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenTriggeredTagsFormat"
                           },
                           {
                              "$ref": "#/$defs/TagsWithSeparatorFormat"
                           },
                           {
                              "$ref": "#/$defs/OptionalFormat"
                           },
                           {
                              "$ref": "#/$defs/PlusFormat"
                           },
                           {
                              "$ref": "#/$defs/StarFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenFormat"
                           },
                           {
                              "$ref": "#/$defs/ExcludeTokenFormat"
                           },
                           {
                              "$ref": "#/$defs/AnyTokensFormat"
                           },
                           {
                              "$ref": "#/$defs/RepeatFormat"
                           },
                           {
                              "$ref": "#/$defs/DispatchFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenDispatchFormat"
                           }
                        ]
                     }
                  ],
                  "type": "array"
               },
               "title": "Rules",
               "type": "array"
            },
            "loop": {
               "default": true,
               "title": "Loop",
               "type": "boolean"
            },
            "excludes": {
               "default": [],
               "items": {
                  "type": "string"
               },
               "title": "Excludes",
               "type": "array"
            }
         },
         "required": [
            "rules"
         ],
         "title": "DispatchFormat",
         "type": "object"
      },
      "ExcludeTokenFormat": {
         "description": "A format that matches a single token, excluding those in the given set.",
         "properties": {
            "type": {
               "const": "exclude_token",
               "default": "exclude_token",
               "title": "Type",
               "type": "string"
            },
            "exclude_tokens": {
               "default": [],
               "items": {
                  "anyOf": [
                     {
                        "type": "integer"
                     },
                     {
                        "type": "string"
                     }
                  ]
               },
               "title": "Exclude Tokens",
               "type": "array"
            }
         },
         "title": "ExcludeTokenFormat",
         "type": "object"
      },
      "GrammarFormat": {
         "description": "A format that matches an ebnf grammar.",
         "properties": {
            "type": {
               "const": "grammar",
               "default": "grammar",
               "title": "Type",
               "type": "string"
            },
            "grammar": {
               "title": "Grammar",
               "type": "string"
            }
         },
         "required": [
            "grammar"
         ],
         "title": "GrammarFormat",
         "type": "object"
      },
      "JSONSchemaFormat": {
         "description": "A format that matches a JSON schema.",
         "properties": {
            "type": {
               "const": "json_schema",
               "default": "json_schema",
               "title": "Type",
               "type": "string"
            },
            "json_schema": {
               "anyOf": [
                  {
                     "type": "boolean"
                  },
                  {
                     "additionalProperties": true,
                     "type": "object"
                  }
               ],
               "title": "Json Schema"
            },
            "style": {
               "default": "json",
               "enum": [
                  "json",
                  "qwen_xml",
                  "minimax_xml",
                  "deepseek_xml",
                  "glm_xml"
               ],
               "title": "Style",
               "type": "string"
            }
         },
         "required": [
            "json_schema"
         ],
         "title": "JSONSchemaFormat",
         "type": "object"
      },
      "OptionalFormat": {
         "description": "A format that matches the content 0 or 1 time (EBNF optional).\n\nSemantics: the inner format may appear once or not at all.",
         "properties": {
            "type": {
               "const": "optional",
               "default": "optional",
               "title": "Type",
               "type": "string"
            },
            "content": {
               "discriminator": {
                  "mapping": {
                     "any_text": "#/$defs/AnyTextFormat",
                     "any_tokens": "#/$defs/AnyTokensFormat",
                     "const_string": "#/$defs/ConstStringFormat",
                     "dispatch": "#/$defs/DispatchFormat",
                     "exclude_token": "#/$defs/ExcludeTokenFormat",
                     "grammar": "#/$defs/GrammarFormat",
                     "json_schema": "#/$defs/JSONSchemaFormat",
                     "optional": "#/$defs/OptionalFormat",
                     "or": "#/$defs/OrFormat",
                     "plus": "#/$defs/PlusFormat",
                     "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                     "regex": "#/$defs/RegexFormat",
                     "repeat": "#/$defs/RepeatFormat",
                     "sequence": "#/$defs/SequenceFormat",
                     "star": "#/$defs/StarFormat",
                     "tag": "#/$defs/TagFormat",
                     "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                     "token": "#/$defs/TokenFormat",
                     "token_dispatch": "#/$defs/TokenDispatchFormat",
                     "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                     "triggered_tags": "#/$defs/TriggeredTagsFormat"
                  },
                  "propertyName": "type"
               },
               "oneOf": [
                  {
                     "$ref": "#/$defs/AnyTextFormat"
                  },
                  {
                     "$ref": "#/$defs/ConstStringFormat"
                  },
                  {
                     "$ref": "#/$defs/JSONSchemaFormat"
                  },
                  {
                     "$ref": "#/$defs/GrammarFormat"
                  },
                  {
                     "$ref": "#/$defs/RegexFormat"
                  },
                  {
                     "$ref": "#/$defs/QwenXMLParameterFormat"
                  },
                  {
                     "$ref": "#/$defs/OrFormat"
                  },
                  {
                     "$ref": "#/$defs/SequenceFormat"
                  },
                  {
                     "$ref": "#/$defs/TagFormat"
                  },
                  {
                     "$ref": "#/$defs/TriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenTriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TagsWithSeparatorFormat"
                  },
                  {
                     "$ref": "#/$defs/OptionalFormat"
                  },
                  {
                     "$ref": "#/$defs/PlusFormat"
                  },
                  {
                     "$ref": "#/$defs/StarFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  },
                  {
                     "$ref": "#/$defs/ExcludeTokenFormat"
                  },
                  {
                     "$ref": "#/$defs/AnyTokensFormat"
                  },
                  {
                     "$ref": "#/$defs/RepeatFormat"
                  },
                  {
                     "$ref": "#/$defs/DispatchFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenDispatchFormat"
                  }
               ],
               "title": "Content"
            }
         },
         "required": [
            "content"
         ],
         "title": "OptionalFormat",
         "type": "object"
      },
      "OrFormat": {
         "description": "A format that matches one of the formats.",
         "properties": {
            "type": {
               "const": "or",
               "default": "or",
               "title": "Type",
               "type": "string"
            },
            "elements": {
               "items": {
                  "discriminator": {
                     "mapping": {
                        "any_text": "#/$defs/AnyTextFormat",
                        "any_tokens": "#/$defs/AnyTokensFormat",
                        "const_string": "#/$defs/ConstStringFormat",
                        "dispatch": "#/$defs/DispatchFormat",
                        "exclude_token": "#/$defs/ExcludeTokenFormat",
                        "grammar": "#/$defs/GrammarFormat",
                        "json_schema": "#/$defs/JSONSchemaFormat",
                        "optional": "#/$defs/OptionalFormat",
                        "or": "#/$defs/OrFormat",
                        "plus": "#/$defs/PlusFormat",
                        "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                        "regex": "#/$defs/RegexFormat",
                        "repeat": "#/$defs/RepeatFormat",
                        "sequence": "#/$defs/SequenceFormat",
                        "star": "#/$defs/StarFormat",
                        "tag": "#/$defs/TagFormat",
                        "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                        "token": "#/$defs/TokenFormat",
                        "token_dispatch": "#/$defs/TokenDispatchFormat",
                        "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                        "triggered_tags": "#/$defs/TriggeredTagsFormat"
                     },
                     "propertyName": "type"
                  },
                  "oneOf": [
                     {
                        "$ref": "#/$defs/AnyTextFormat"
                     },
                     {
                        "$ref": "#/$defs/ConstStringFormat"
                     },
                     {
                        "$ref": "#/$defs/JSONSchemaFormat"
                     },
                     {
                        "$ref": "#/$defs/GrammarFormat"
                     },
                     {
                        "$ref": "#/$defs/RegexFormat"
                     },
                     {
                        "$ref": "#/$defs/QwenXMLParameterFormat"
                     },
                     {
                        "$ref": "#/$defs/OrFormat"
                     },
                     {
                        "$ref": "#/$defs/SequenceFormat"
                     },
                     {
                        "$ref": "#/$defs/TagFormat"
                     },
                     {
                        "$ref": "#/$defs/TriggeredTagsFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenTriggeredTagsFormat"
                     },
                     {
                        "$ref": "#/$defs/TagsWithSeparatorFormat"
                     },
                     {
                        "$ref": "#/$defs/OptionalFormat"
                     },
                     {
                        "$ref": "#/$defs/PlusFormat"
                     },
                     {
                        "$ref": "#/$defs/StarFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenFormat"
                     },
                     {
                        "$ref": "#/$defs/ExcludeTokenFormat"
                     },
                     {
                        "$ref": "#/$defs/AnyTokensFormat"
                     },
                     {
                        "$ref": "#/$defs/RepeatFormat"
                     },
                     {
                        "$ref": "#/$defs/DispatchFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenDispatchFormat"
                     }
                  ]
               },
               "title": "Elements",
               "type": "array"
            }
         },
         "required": [
            "elements"
         ],
         "title": "OrFormat",
         "type": "object"
      },
      "PlusFormat": {
         "description": "A format that matches the content 1 or more times (EBNF plus).\n\nSemantics: the inner format must appear at least once.",
         "properties": {
            "type": {
               "const": "plus",
               "default": "plus",
               "title": "Type",
               "type": "string"
            },
            "content": {
               "discriminator": {
                  "mapping": {
                     "any_text": "#/$defs/AnyTextFormat",
                     "any_tokens": "#/$defs/AnyTokensFormat",
                     "const_string": "#/$defs/ConstStringFormat",
                     "dispatch": "#/$defs/DispatchFormat",
                     "exclude_token": "#/$defs/ExcludeTokenFormat",
                     "grammar": "#/$defs/GrammarFormat",
                     "json_schema": "#/$defs/JSONSchemaFormat",
                     "optional": "#/$defs/OptionalFormat",
                     "or": "#/$defs/OrFormat",
                     "plus": "#/$defs/PlusFormat",
                     "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                     "regex": "#/$defs/RegexFormat",
                     "repeat": "#/$defs/RepeatFormat",
                     "sequence": "#/$defs/SequenceFormat",
                     "star": "#/$defs/StarFormat",
                     "tag": "#/$defs/TagFormat",
                     "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                     "token": "#/$defs/TokenFormat",
                     "token_dispatch": "#/$defs/TokenDispatchFormat",
                     "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                     "triggered_tags": "#/$defs/TriggeredTagsFormat"
                  },
                  "propertyName": "type"
               },
               "oneOf": [
                  {
                     "$ref": "#/$defs/AnyTextFormat"
                  },
                  {
                     "$ref": "#/$defs/ConstStringFormat"
                  },
                  {
                     "$ref": "#/$defs/JSONSchemaFormat"
                  },
                  {
                     "$ref": "#/$defs/GrammarFormat"
                  },
                  {
                     "$ref": "#/$defs/RegexFormat"
                  },
                  {
                     "$ref": "#/$defs/QwenXMLParameterFormat"
                  },
                  {
                     "$ref": "#/$defs/OrFormat"
                  },
                  {
                     "$ref": "#/$defs/SequenceFormat"
                  },
                  {
                     "$ref": "#/$defs/TagFormat"
                  },
                  {
                     "$ref": "#/$defs/TriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenTriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TagsWithSeparatorFormat"
                  },
                  {
                     "$ref": "#/$defs/OptionalFormat"
                  },
                  {
                     "$ref": "#/$defs/PlusFormat"
                  },
                  {
                     "$ref": "#/$defs/StarFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  },
                  {
                     "$ref": "#/$defs/ExcludeTokenFormat"
                  },
                  {
                     "$ref": "#/$defs/AnyTokensFormat"
                  },
                  {
                     "$ref": "#/$defs/RepeatFormat"
                  },
                  {
                     "$ref": "#/$defs/DispatchFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenDispatchFormat"
                  }
               ],
               "title": "Content"
            }
         },
         "required": [
            "content"
         ],
         "title": "PlusFormat",
         "type": "object"
      },
      "QwenXMLParameterFormat": {
         "description": "Deprecated. Use :class:`JSONSchemaFormat` with ``style=\"qwen_xml\"`` instead.\n\nThis format remains available so existing serialized structural tags with\n``{\"type\": \"qwen_xml_parameter\"}`` can still be loaded.\n\nExamples\n--------\nUse the replacement format for new structural tags:\n\n.. code-block:: python\n\n    structural_tag = JSONSchemaFormat(\n        json_schema={\n            \"type\": \"object\",\n            \"properties\": {\"name\": {\"type\": \"string\"}, \"age\": {\"type\": \"integer\"}},\n            \"required\": [\"name\", \"age\"],\n        },\n        style=\"qwen_xml\",\n    )\n\nThe above structural tag can accept the following outputs::\n\n    <parameter=name>Bob</parameter><parameter=age>100</parameter>\n    <parameter=name>\"Bob&lt;\"</parameter><parameter=age>100</parameter>",
         "properties": {
            "type": {
               "const": "qwen_xml_parameter",
               "default": "qwen_xml_parameter",
               "title": "Type",
               "type": "string"
            },
            "json_schema": {
               "anyOf": [
                  {
                     "type": "boolean"
                  },
                  {
                     "additionalProperties": true,
                     "type": "object"
                  }
               ],
               "title": "Json Schema"
            }
         },
         "required": [
            "json_schema"
         ],
         "title": "QwenXMLParameterFormat",
         "type": "object"
      },
      "RegexFormat": {
         "description": "A format that matches a regex pattern.",
         "properties": {
            "type": {
               "const": "regex",
               "default": "regex",
               "title": "Type",
               "type": "string"
            },
            "pattern": {
               "title": "Pattern",
               "type": "string"
            }
         },
         "required": [
            "pattern"
         ],
         "title": "RegexFormat",
         "type": "object"
      },
      "RepeatFormat": {
         "description": "A format that matches the content between min and max times (inclusive).\n\nUse max=-1 for unbounded upper limit (e.g. \"at least min times\").",
         "properties": {
            "type": {
               "const": "repeat",
               "default": "repeat",
               "title": "Type",
               "type": "string"
            },
            "min": {
               "title": "Min",
               "type": "integer"
            },
            "max": {
               "title": "Max",
               "type": "integer"
            },
            "content": {
               "discriminator": {
                  "mapping": {
                     "any_text": "#/$defs/AnyTextFormat",
                     "any_tokens": "#/$defs/AnyTokensFormat",
                     "const_string": "#/$defs/ConstStringFormat",
                     "dispatch": "#/$defs/DispatchFormat",
                     "exclude_token": "#/$defs/ExcludeTokenFormat",
                     "grammar": "#/$defs/GrammarFormat",
                     "json_schema": "#/$defs/JSONSchemaFormat",
                     "optional": "#/$defs/OptionalFormat",
                     "or": "#/$defs/OrFormat",
                     "plus": "#/$defs/PlusFormat",
                     "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                     "regex": "#/$defs/RegexFormat",
                     "repeat": "#/$defs/RepeatFormat",
                     "sequence": "#/$defs/SequenceFormat",
                     "star": "#/$defs/StarFormat",
                     "tag": "#/$defs/TagFormat",
                     "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                     "token": "#/$defs/TokenFormat",
                     "token_dispatch": "#/$defs/TokenDispatchFormat",
                     "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                     "triggered_tags": "#/$defs/TriggeredTagsFormat"
                  },
                  "propertyName": "type"
               },
               "oneOf": [
                  {
                     "$ref": "#/$defs/AnyTextFormat"
                  },
                  {
                     "$ref": "#/$defs/ConstStringFormat"
                  },
                  {
                     "$ref": "#/$defs/JSONSchemaFormat"
                  },
                  {
                     "$ref": "#/$defs/GrammarFormat"
                  },
                  {
                     "$ref": "#/$defs/RegexFormat"
                  },
                  {
                     "$ref": "#/$defs/QwenXMLParameterFormat"
                  },
                  {
                     "$ref": "#/$defs/OrFormat"
                  },
                  {
                     "$ref": "#/$defs/SequenceFormat"
                  },
                  {
                     "$ref": "#/$defs/TagFormat"
                  },
                  {
                     "$ref": "#/$defs/TriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenTriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TagsWithSeparatorFormat"
                  },
                  {
                     "$ref": "#/$defs/OptionalFormat"
                  },
                  {
                     "$ref": "#/$defs/PlusFormat"
                  },
                  {
                     "$ref": "#/$defs/StarFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  },
                  {
                     "$ref": "#/$defs/ExcludeTokenFormat"
                  },
                  {
                     "$ref": "#/$defs/AnyTokensFormat"
                  },
                  {
                     "$ref": "#/$defs/RepeatFormat"
                  },
                  {
                     "$ref": "#/$defs/DispatchFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenDispatchFormat"
                  }
               ],
               "title": "Content"
            }
         },
         "required": [
            "min",
            "max",
            "content"
         ],
         "title": "RepeatFormat",
         "type": "object"
      },
      "SequenceFormat": {
         "description": "A format that matches a sequence of formats.",
         "properties": {
            "type": {
               "const": "sequence",
               "default": "sequence",
               "title": "Type",
               "type": "string"
            },
            "elements": {
               "items": {
                  "discriminator": {
                     "mapping": {
                        "any_text": "#/$defs/AnyTextFormat",
                        "any_tokens": "#/$defs/AnyTokensFormat",
                        "const_string": "#/$defs/ConstStringFormat",
                        "dispatch": "#/$defs/DispatchFormat",
                        "exclude_token": "#/$defs/ExcludeTokenFormat",
                        "grammar": "#/$defs/GrammarFormat",
                        "json_schema": "#/$defs/JSONSchemaFormat",
                        "optional": "#/$defs/OptionalFormat",
                        "or": "#/$defs/OrFormat",
                        "plus": "#/$defs/PlusFormat",
                        "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                        "regex": "#/$defs/RegexFormat",
                        "repeat": "#/$defs/RepeatFormat",
                        "sequence": "#/$defs/SequenceFormat",
                        "star": "#/$defs/StarFormat",
                        "tag": "#/$defs/TagFormat",
                        "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                        "token": "#/$defs/TokenFormat",
                        "token_dispatch": "#/$defs/TokenDispatchFormat",
                        "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                        "triggered_tags": "#/$defs/TriggeredTagsFormat"
                     },
                     "propertyName": "type"
                  },
                  "oneOf": [
                     {
                        "$ref": "#/$defs/AnyTextFormat"
                     },
                     {
                        "$ref": "#/$defs/ConstStringFormat"
                     },
                     {
                        "$ref": "#/$defs/JSONSchemaFormat"
                     },
                     {
                        "$ref": "#/$defs/GrammarFormat"
                     },
                     {
                        "$ref": "#/$defs/RegexFormat"
                     },
                     {
                        "$ref": "#/$defs/QwenXMLParameterFormat"
                     },
                     {
                        "$ref": "#/$defs/OrFormat"
                     },
                     {
                        "$ref": "#/$defs/SequenceFormat"
                     },
                     {
                        "$ref": "#/$defs/TagFormat"
                     },
                     {
                        "$ref": "#/$defs/TriggeredTagsFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenTriggeredTagsFormat"
                     },
                     {
                        "$ref": "#/$defs/TagsWithSeparatorFormat"
                     },
                     {
                        "$ref": "#/$defs/OptionalFormat"
                     },
                     {
                        "$ref": "#/$defs/PlusFormat"
                     },
                     {
                        "$ref": "#/$defs/StarFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenFormat"
                     },
                     {
                        "$ref": "#/$defs/ExcludeTokenFormat"
                     },
                     {
                        "$ref": "#/$defs/AnyTokensFormat"
                     },
                     {
                        "$ref": "#/$defs/RepeatFormat"
                     },
                     {
                        "$ref": "#/$defs/DispatchFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenDispatchFormat"
                     }
                  ]
               },
               "title": "Elements",
               "type": "array"
            }
         },
         "required": [
            "elements"
         ],
         "title": "SequenceFormat",
         "type": "object"
      },
      "StarFormat": {
         "description": "A format that matches the content 0 or more times (EBNF star).\n\nSemantics: the inner format may appear any number of times.",
         "properties": {
            "type": {
               "const": "star",
               "default": "star",
               "title": "Type",
               "type": "string"
            },
            "content": {
               "discriminator": {
                  "mapping": {
                     "any_text": "#/$defs/AnyTextFormat",
                     "any_tokens": "#/$defs/AnyTokensFormat",
                     "const_string": "#/$defs/ConstStringFormat",
                     "dispatch": "#/$defs/DispatchFormat",
                     "exclude_token": "#/$defs/ExcludeTokenFormat",
                     "grammar": "#/$defs/GrammarFormat",
                     "json_schema": "#/$defs/JSONSchemaFormat",
                     "optional": "#/$defs/OptionalFormat",
                     "or": "#/$defs/OrFormat",
                     "plus": "#/$defs/PlusFormat",
                     "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                     "regex": "#/$defs/RegexFormat",
                     "repeat": "#/$defs/RepeatFormat",
                     "sequence": "#/$defs/SequenceFormat",
                     "star": "#/$defs/StarFormat",
                     "tag": "#/$defs/TagFormat",
                     "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                     "token": "#/$defs/TokenFormat",
                     "token_dispatch": "#/$defs/TokenDispatchFormat",
                     "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                     "triggered_tags": "#/$defs/TriggeredTagsFormat"
                  },
                  "propertyName": "type"
               },
               "oneOf": [
                  {
                     "$ref": "#/$defs/AnyTextFormat"
                  },
                  {
                     "$ref": "#/$defs/ConstStringFormat"
                  },
                  {
                     "$ref": "#/$defs/JSONSchemaFormat"
                  },
                  {
                     "$ref": "#/$defs/GrammarFormat"
                  },
                  {
                     "$ref": "#/$defs/RegexFormat"
                  },
                  {
                     "$ref": "#/$defs/QwenXMLParameterFormat"
                  },
                  {
                     "$ref": "#/$defs/OrFormat"
                  },
                  {
                     "$ref": "#/$defs/SequenceFormat"
                  },
                  {
                     "$ref": "#/$defs/TagFormat"
                  },
                  {
                     "$ref": "#/$defs/TriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenTriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TagsWithSeparatorFormat"
                  },
                  {
                     "$ref": "#/$defs/OptionalFormat"
                  },
                  {
                     "$ref": "#/$defs/PlusFormat"
                  },
                  {
                     "$ref": "#/$defs/StarFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  },
                  {
                     "$ref": "#/$defs/ExcludeTokenFormat"
                  },
                  {
                     "$ref": "#/$defs/AnyTokensFormat"
                  },
                  {
                     "$ref": "#/$defs/RepeatFormat"
                  },
                  {
                     "$ref": "#/$defs/DispatchFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenDispatchFormat"
                  }
               ],
               "title": "Content"
            }
         },
         "required": [
            "content"
         ],
         "title": "StarFormat",
         "type": "object"
      },
      "TagFormat": {
         "description": "A format that matches a tag: ``begin content end``.\n\nThe ``end`` field can be a single string or a list of possible end strings.\nWhen multiple end strings are provided, any of them will be accepted as a valid\nending for the tag.\n\nExamples\n--------\n\nSingle end string:\n\n.. code-block:: python\n\n    TagFormat(begin=\"<response>\", content=..., end=\"</response>\")\n\nMultiple end strings:\n\n.. code-block:: python\n\n    TagFormat(begin=\"<response>\", content=..., end=[\"</response>\", \"</answer>\"])",
         "properties": {
            "type": {
               "const": "tag",
               "default": "tag",
               "title": "Type",
               "type": "string"
            },
            "begin": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  }
               ],
               "title": "Begin"
            },
            "content": {
               "discriminator": {
                  "mapping": {
                     "any_text": "#/$defs/AnyTextFormat",
                     "any_tokens": "#/$defs/AnyTokensFormat",
                     "const_string": "#/$defs/ConstStringFormat",
                     "dispatch": "#/$defs/DispatchFormat",
                     "exclude_token": "#/$defs/ExcludeTokenFormat",
                     "grammar": "#/$defs/GrammarFormat",
                     "json_schema": "#/$defs/JSONSchemaFormat",
                     "optional": "#/$defs/OptionalFormat",
                     "or": "#/$defs/OrFormat",
                     "plus": "#/$defs/PlusFormat",
                     "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                     "regex": "#/$defs/RegexFormat",
                     "repeat": "#/$defs/RepeatFormat",
                     "sequence": "#/$defs/SequenceFormat",
                     "star": "#/$defs/StarFormat",
                     "tag": "#/$defs/TagFormat",
                     "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                     "token": "#/$defs/TokenFormat",
                     "token_dispatch": "#/$defs/TokenDispatchFormat",
                     "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                     "triggered_tags": "#/$defs/TriggeredTagsFormat"
                  },
                  "propertyName": "type"
               },
               "oneOf": [
                  {
                     "$ref": "#/$defs/AnyTextFormat"
                  },
                  {
                     "$ref": "#/$defs/ConstStringFormat"
                  },
                  {
                     "$ref": "#/$defs/JSONSchemaFormat"
                  },
                  {
                     "$ref": "#/$defs/GrammarFormat"
                  },
                  {
                     "$ref": "#/$defs/RegexFormat"
                  },
                  {
                     "$ref": "#/$defs/QwenXMLParameterFormat"
                  },
                  {
                     "$ref": "#/$defs/OrFormat"
                  },
                  {
                     "$ref": "#/$defs/SequenceFormat"
                  },
                  {
                     "$ref": "#/$defs/TagFormat"
                  },
                  {
                     "$ref": "#/$defs/TriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenTriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TagsWithSeparatorFormat"
                  },
                  {
                     "$ref": "#/$defs/OptionalFormat"
                  },
                  {
                     "$ref": "#/$defs/PlusFormat"
                  },
                  {
                     "$ref": "#/$defs/StarFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  },
                  {
                     "$ref": "#/$defs/ExcludeTokenFormat"
                  },
                  {
                     "$ref": "#/$defs/AnyTokensFormat"
                  },
                  {
                     "$ref": "#/$defs/RepeatFormat"
                  },
                  {
                     "$ref": "#/$defs/DispatchFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenDispatchFormat"
                  }
               ],
               "title": "Content"
            },
            "end": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "items": {
                        "type": "string"
                     },
                     "type": "array"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  }
               ],
               "title": "End"
            }
         },
         "required": [
            "begin",
            "content",
            "end"
         ],
         "title": "TagFormat",
         "type": "object"
      },
      "TagsWithSeparatorFormat": {
         "description": "A format that matches a tags with separator. It can match zero, one, or more tags, separated\nby the separator, with no other text allowed.\n\nExamples\n--------\n\n.. code-block:: python\n\n    structural_tag = TagsWithSeparatorFormat(\n        tags=[\n            TagFormat(begin=\"<function=func1>\", content=JSONSchemaFormat(json_schema=...), end=\"</function>\"),\n            TagFormat(begin=\"<function=func2>\", content=JSONSchemaFormat(json_schema=...), end=\"</function>\"),\n        ],\n        separator=\",\",\n        at_least_one=False,\n        stop_after_first=False,\n    )\n\nThe above structural tag can accept an empty string, or the following outputs::\n\n    <function=func1>{\"name\": \"John\", \"age\": 30}</function>\n    <function=func1>{\"name\": \"John\", \"age\": 30}</function>,<function=func2>{\"name\": \"Jane\", \"age\": 25}</function>\n    <function=func1>{\"name\": \"John\", \"age\": 30}</function>,<function=func2>{\"name\": \"Jane\", \"age\": 25}</function>,<function=func1>{\"name\": \"John\", \"age\": 30}</function>",
         "properties": {
            "type": {
               "const": "tags_with_separator",
               "default": "tags_with_separator",
               "title": "Type",
               "type": "string"
            },
            "tags": {
               "items": {
                  "$ref": "#/$defs/TagFormat"
               },
               "title": "Tags",
               "type": "array"
            },
            "separator": {
               "title": "Separator",
               "type": "string"
            },
            "at_least_one": {
               "default": false,
               "title": "At Least One",
               "type": "boolean"
            },
            "stop_after_first": {
               "default": false,
               "title": "Stop After First",
               "type": "boolean"
            }
         },
         "required": [
            "tags",
            "separator"
         ],
         "title": "TagsWithSeparatorFormat",
         "type": "object"
      },
      "TokenDispatchFormat": {
         "description": "Matches certain patterns in free-form text.\nWhen certain tokens are generated, the following content must follow the corresponding format.\nCertain tokens can be excluded from being generated in the free-form part.\n\nThe user specifies a list of (pattern token, formats). The LLM can generate any free-form text, but\nwhen a pattern is matched in the text, the following output must follow the corresponding format.\nThe ``loop`` field controls whether the matching of this structure ends after accepting the first\npattern and format. If False, it ends. If true, the matching continues, and this format will\ncontinue to allow free-form text and detect the next pattern to be generated.\nThe ``excludes`` field controls the strings that cannot be generated in the free-form text.\nIt can also control the end of the format:\n``SequenceFormat(DispatchFormat(..., excludes=\"\"), ConstStringFormat(\"\"))``\nor\n``TagFormat(begin=..., content=DispatchFormat(..., excludes=\"\"), end=\"\")``\nends the matching of the format when LLM generates <end>.",
         "properties": {
            "type": {
               "const": "token_dispatch",
               "default": "token_dispatch",
               "title": "Type",
               "type": "string"
            },
            "rules": {
               "items": {
                  "maxItems": 2,
                  "minItems": 2,
                  "prefixItems": [
                     {
                        "anyOf": [
                           {
                              "type": "integer"
                           },
                           {
                              "type": "string"
                           }
                        ]
                     },
                     {
                        "discriminator": {
                           "mapping": {
                              "any_text": "#/$defs/AnyTextFormat",
                              "any_tokens": "#/$defs/AnyTokensFormat",
                              "const_string": "#/$defs/ConstStringFormat",
                              "dispatch": "#/$defs/DispatchFormat",
                              "exclude_token": "#/$defs/ExcludeTokenFormat",
                              "grammar": "#/$defs/GrammarFormat",
                              "json_schema": "#/$defs/JSONSchemaFormat",
                              "optional": "#/$defs/OptionalFormat",
                              "or": "#/$defs/OrFormat",
                              "plus": "#/$defs/PlusFormat",
                              "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                              "regex": "#/$defs/RegexFormat",
                              "repeat": "#/$defs/RepeatFormat",
                              "sequence": "#/$defs/SequenceFormat",
                              "star": "#/$defs/StarFormat",
                              "tag": "#/$defs/TagFormat",
                              "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                              "token": "#/$defs/TokenFormat",
                              "token_dispatch": "#/$defs/TokenDispatchFormat",
                              "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                              "triggered_tags": "#/$defs/TriggeredTagsFormat"
                           },
                           "propertyName": "type"
                        },
                        "oneOf": [
                           {
                              "$ref": "#/$defs/AnyTextFormat"
                           },
                           {
                              "$ref": "#/$defs/ConstStringFormat"
                           },
                           {
                              "$ref": "#/$defs/JSONSchemaFormat"
                           },
                           {
                              "$ref": "#/$defs/GrammarFormat"
                           },
                           {
                              "$ref": "#/$defs/RegexFormat"
                           },
                           {
                              "$ref": "#/$defs/QwenXMLParameterFormat"
                           },
                           {
                              "$ref": "#/$defs/OrFormat"
                           },
                           {
                              "$ref": "#/$defs/SequenceFormat"
                           },
                           {
                              "$ref": "#/$defs/TagFormat"
                           },
                           {
                              "$ref": "#/$defs/TriggeredTagsFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenTriggeredTagsFormat"
                           },
                           {
                              "$ref": "#/$defs/TagsWithSeparatorFormat"
                           },
                           {
                              "$ref": "#/$defs/OptionalFormat"
                           },
                           {
                              "$ref": "#/$defs/PlusFormat"
                           },
                           {
                              "$ref": "#/$defs/StarFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenFormat"
                           },
                           {
                              "$ref": "#/$defs/ExcludeTokenFormat"
                           },
                           {
                              "$ref": "#/$defs/AnyTokensFormat"
                           },
                           {
                              "$ref": "#/$defs/RepeatFormat"
                           },
                           {
                              "$ref": "#/$defs/DispatchFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenDispatchFormat"
                           }
                        ]
                     }
                  ],
                  "type": "array"
               },
               "title": "Rules",
               "type": "array"
            },
            "loop": {
               "default": true,
               "title": "Loop",
               "type": "boolean"
            },
            "exclude_tokens": {
               "default": [],
               "items": {
                  "anyOf": [
                     {
                        "type": "integer"
                     },
                     {
                        "type": "string"
                     }
                  ]
               },
               "title": "Exclude Tokens",
               "type": "array"
            }
         },
         "required": [
            "rules"
         ],
         "title": "TokenDispatchFormat",
         "type": "object"
      },
      "TokenFormat": {
         "description": "A format that matches a single token by ID or string representation.",
         "properties": {
            "type": {
               "const": "token",
               "default": "token",
               "title": "Type",
               "type": "string"
            },
            "token": {
               "anyOf": [
                  {
                     "type": "integer"
                  },
                  {
                     "type": "string"
                  }
               ],
               "title": "Token"
            }
         },
         "required": [
            "token"
         ],
         "title": "TokenFormat",
         "type": "object"
      },
      "TokenTriggeredTagsFormat": {
         "description": "A format that dispatches to tags based on token-level triggers.\n\nSimilar to TriggeredTagsFormat but uses token IDs instead of string triggers.\nTags must use ``TokenFormat`` ``begin`` fields, not strings.\nFor string-level dispatch, use ``TriggeredTagsFormat`` instead.",
         "properties": {
            "type": {
               "const": "token_triggered_tags",
               "default": "token_triggered_tags",
               "title": "Type",
               "type": "string"
            },
            "trigger_tokens": {
               "items": {
                  "anyOf": [
                     {
                        "type": "integer"
                     },
                     {
                        "type": "string"
                     }
                  ]
               },
               "title": "Trigger Tokens",
               "type": "array"
            },
            "tags": {
               "items": {
                  "$ref": "#/$defs/TagFormat"
               },
               "title": "Tags",
               "type": "array"
            },
            "exclude_tokens": {
               "default": [],
               "items": {
                  "anyOf": [
                     {
                        "type": "integer"
                     },
                     {
                        "type": "string"
                     }
                  ]
               },
               "title": "Exclude Tokens",
               "type": "array"
            },
            "at_least_one": {
               "default": false,
               "title": "At Least One",
               "type": "boolean"
            },
            "stop_after_first": {
               "default": false,
               "title": "Stop After First",
               "type": "boolean"
            }
         },
         "required": [
            "trigger_tokens",
            "tags"
         ],
         "title": "TokenTriggeredTagsFormat",
         "type": "object"
      },
      "TriggeredTagsFormat": {
         "description": "A format that matches triggered tags. It can allow any output until a trigger is\nencountered, then dispatch to the corresponding tag; when the end tag is encountered, the\ngrammar will allow any following output, until the next trigger is encountered.\n\nEach tag should be matched by exactly one trigger. \"matching\" means the trigger should be a\nprefix of the begin tag.\n\nTags must use **string** ``begin`` fields, not ``TokenFormat``.\nFor token-level dispatch, use ``TokenTriggeredTagsFormat`` instead.\n\nExamples\n--------\n\n.. code-block:: python\n\n    structural_tag = TriggeredTagsFormat(\n        triggers=[\"<function=\"],\n        tags=[\n            TagFormat(\n                begin=\"<function=func1>\",\n                content=JSONSchemaFormat(json_schema=...),\n                end=\"</function>\",\n            ),\n            TagFormat(\n                begin=\"<function=func2>\",\n                content=JSONSchemaFormat(json_schema=...),\n                end=\"</function>\",\n            ),\n        ],\n        at_least_one=False,\n        stop_after_first=False,\n    )\n\nThe above structural tag can accept the following outputs::\n\n    <function=func1>{\"name\": \"John\", \"age\": 30}</function>\n    <function=func2>{\"name\": \"Jane\", \"age\": 25}</function>\n    any_text<function=func1>{\"name\": \"John\", \"age\": 30}</function>any_text1<function=func2>{\"name\": \"Jane\", \"age\": 25}</function>any_text2",
         "properties": {
            "type": {
               "const": "triggered_tags",
               "default": "triggered_tags",
               "title": "Type",
               "type": "string"
            },
            "triggers": {
               "items": {
                  "type": "string"
               },
               "title": "Triggers",
               "type": "array"
            },
            "tags": {
               "items": {
                  "$ref": "#/$defs/TagFormat"
               },
               "title": "Tags",
               "type": "array"
            },
            "at_least_one": {
               "default": false,
               "title": "At Least One",
               "type": "boolean"
            },
            "stop_after_first": {
               "default": false,
               "title": "Stop After First",
               "type": "boolean"
            },
            "excludes": {
               "default": [],
               "items": {
                  "type": "string"
               },
               "title": "Excludes",
               "type": "array"
            }
         },
         "required": [
            "triggers",
            "tags"
         ],
         "title": "TriggeredTagsFormat",
         "type": "object"
      }
   },
   "$ref": "#/$defs/SequenceFormat"
}

field type: Literal['sequence'] = 'sequence'

The type of the format.

field elements: List[Format] [Required]

The elements of the sequence.

pydantic model xgrammar.structural_tag.OrFormat[source]

Bases: BaseModel

A format that matches one of the formats.

Show JSON schema
{
   "$defs": {
      "AnyTextFormat": {
         "description": "A format that matches any text.",
         "properties": {
            "type": {
               "const": "any_text",
               "default": "any_text",
               "title": "Type",
               "type": "string"
            },
            "excludes": {
               "default": [],
               "items": {
                  "type": "string"
               },
               "title": "Excludes",
               "type": "array"
            }
         },
         "title": "AnyTextFormat",
         "type": "object"
      },
      "AnyTokensFormat": {
         "description": "A format that matches zero or more tokens, excluding those in the given set.",
         "properties": {
            "type": {
               "const": "any_tokens",
               "default": "any_tokens",
               "title": "Type",
               "type": "string"
            },
            "exclude_tokens": {
               "default": [],
               "items": {
                  "anyOf": [
                     {
                        "type": "integer"
                     },
                     {
                        "type": "string"
                     }
                  ]
               },
               "title": "Exclude Tokens",
               "type": "array"
            }
         },
         "title": "AnyTokensFormat",
         "type": "object"
      },
      "ConstStringFormat": {
         "description": "A format that matches a constant string.",
         "properties": {
            "type": {
               "const": "const_string",
               "default": "const_string",
               "title": "Type",
               "type": "string"
            },
            "value": {
               "title": "Value",
               "type": "string"
            }
         },
         "required": [
            "value"
         ],
         "title": "ConstStringFormat",
         "type": "object"
      },
      "DispatchFormat": {
         "description": "Matches certain patterns in free-form text.\nWhen certain strings are generated, the following content must follow the corresponding format.\nCertain strings can be excluded from being generated in the free-form part.\n\nThe user specifies a list of (pattern, formats). The LLM can generate any free-form text, but\nwhen a pattern is matched in the text, the following output must follow the corresponding format.\nThe ``loop`` field controls whether the matching of this structure ends after accepting the first\npattern and format. If False, it ends. If true, the matching continues, and this format will\ncontinue to allow free-form text and detect the next pattern to be generated.\nThe ``excludes`` field controls the strings that cannot be generated in the free-form text.\nIt can also control the end of the format:\n``SequenceFormat(DispatchFormat(..., excludes=\"\"), ConstStringFormat(\"\"))``\nor\n``TagFormat(begin=..., content=DispatchFormat(..., excludes=\"\"), end=\"\")``\nends the matching of the format when LLM generates <end>.",
         "properties": {
            "type": {
               "const": "dispatch",
               "default": "dispatch",
               "title": "Type",
               "type": "string"
            },
            "rules": {
               "items": {
                  "maxItems": 2,
                  "minItems": 2,
                  "prefixItems": [
                     {
                        "type": "string"
                     },
                     {
                        "discriminator": {
                           "mapping": {
                              "any_text": "#/$defs/AnyTextFormat",
                              "any_tokens": "#/$defs/AnyTokensFormat",
                              "const_string": "#/$defs/ConstStringFormat",
                              "dispatch": "#/$defs/DispatchFormat",
                              "exclude_token": "#/$defs/ExcludeTokenFormat",
                              "grammar": "#/$defs/GrammarFormat",
                              "json_schema": "#/$defs/JSONSchemaFormat",
                              "optional": "#/$defs/OptionalFormat",
                              "or": "#/$defs/OrFormat",
                              "plus": "#/$defs/PlusFormat",
                              "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                              "regex": "#/$defs/RegexFormat",
                              "repeat": "#/$defs/RepeatFormat",
                              "sequence": "#/$defs/SequenceFormat",
                              "star": "#/$defs/StarFormat",
                              "tag": "#/$defs/TagFormat",
                              "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                              "token": "#/$defs/TokenFormat",
                              "token_dispatch": "#/$defs/TokenDispatchFormat",
                              "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                              "triggered_tags": "#/$defs/TriggeredTagsFormat"
                           },
                           "propertyName": "type"
                        },
                        "oneOf": [
                           {
                              "$ref": "#/$defs/AnyTextFormat"
                           },
                           {
                              "$ref": "#/$defs/ConstStringFormat"
                           },
                           {
                              "$ref": "#/$defs/JSONSchemaFormat"
                           },
                           {
                              "$ref": "#/$defs/GrammarFormat"
                           },
                           {
                              "$ref": "#/$defs/RegexFormat"
                           },
                           {
                              "$ref": "#/$defs/QwenXMLParameterFormat"
                           },
                           {
                              "$ref": "#/$defs/OrFormat"
                           },
                           {
                              "$ref": "#/$defs/SequenceFormat"
                           },
                           {
                              "$ref": "#/$defs/TagFormat"
                           },
                           {
                              "$ref": "#/$defs/TriggeredTagsFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenTriggeredTagsFormat"
                           },
                           {
                              "$ref": "#/$defs/TagsWithSeparatorFormat"
                           },
                           {
                              "$ref": "#/$defs/OptionalFormat"
                           },
                           {
                              "$ref": "#/$defs/PlusFormat"
                           },
                           {
                              "$ref": "#/$defs/StarFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenFormat"
                           },
                           {
                              "$ref": "#/$defs/ExcludeTokenFormat"
                           },
                           {
                              "$ref": "#/$defs/AnyTokensFormat"
                           },
                           {
                              "$ref": "#/$defs/RepeatFormat"
                           },
                           {
                              "$ref": "#/$defs/DispatchFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenDispatchFormat"
                           }
                        ]
                     }
                  ],
                  "type": "array"
               },
               "title": "Rules",
               "type": "array"
            },
            "loop": {
               "default": true,
               "title": "Loop",
               "type": "boolean"
            },
            "excludes": {
               "default": [],
               "items": {
                  "type": "string"
               },
               "title": "Excludes",
               "type": "array"
            }
         },
         "required": [
            "rules"
         ],
         "title": "DispatchFormat",
         "type": "object"
      },
      "ExcludeTokenFormat": {
         "description": "A format that matches a single token, excluding those in the given set.",
         "properties": {
            "type": {
               "const": "exclude_token",
               "default": "exclude_token",
               "title": "Type",
               "type": "string"
            },
            "exclude_tokens": {
               "default": [],
               "items": {
                  "anyOf": [
                     {
                        "type": "integer"
                     },
                     {
                        "type": "string"
                     }
                  ]
               },
               "title": "Exclude Tokens",
               "type": "array"
            }
         },
         "title": "ExcludeTokenFormat",
         "type": "object"
      },
      "GrammarFormat": {
         "description": "A format that matches an ebnf grammar.",
         "properties": {
            "type": {
               "const": "grammar",
               "default": "grammar",
               "title": "Type",
               "type": "string"
            },
            "grammar": {
               "title": "Grammar",
               "type": "string"
            }
         },
         "required": [
            "grammar"
         ],
         "title": "GrammarFormat",
         "type": "object"
      },
      "JSONSchemaFormat": {
         "description": "A format that matches a JSON schema.",
         "properties": {
            "type": {
               "const": "json_schema",
               "default": "json_schema",
               "title": "Type",
               "type": "string"
            },
            "json_schema": {
               "anyOf": [
                  {
                     "type": "boolean"
                  },
                  {
                     "additionalProperties": true,
                     "type": "object"
                  }
               ],
               "title": "Json Schema"
            },
            "style": {
               "default": "json",
               "enum": [
                  "json",
                  "qwen_xml",
                  "minimax_xml",
                  "deepseek_xml",
                  "glm_xml"
               ],
               "title": "Style",
               "type": "string"
            }
         },
         "required": [
            "json_schema"
         ],
         "title": "JSONSchemaFormat",
         "type": "object"
      },
      "OptionalFormat": {
         "description": "A format that matches the content 0 or 1 time (EBNF optional).\n\nSemantics: the inner format may appear once or not at all.",
         "properties": {
            "type": {
               "const": "optional",
               "default": "optional",
               "title": "Type",
               "type": "string"
            },
            "content": {
               "discriminator": {
                  "mapping": {
                     "any_text": "#/$defs/AnyTextFormat",
                     "any_tokens": "#/$defs/AnyTokensFormat",
                     "const_string": "#/$defs/ConstStringFormat",
                     "dispatch": "#/$defs/DispatchFormat",
                     "exclude_token": "#/$defs/ExcludeTokenFormat",
                     "grammar": "#/$defs/GrammarFormat",
                     "json_schema": "#/$defs/JSONSchemaFormat",
                     "optional": "#/$defs/OptionalFormat",
                     "or": "#/$defs/OrFormat",
                     "plus": "#/$defs/PlusFormat",
                     "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                     "regex": "#/$defs/RegexFormat",
                     "repeat": "#/$defs/RepeatFormat",
                     "sequence": "#/$defs/SequenceFormat",
                     "star": "#/$defs/StarFormat",
                     "tag": "#/$defs/TagFormat",
                     "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                     "token": "#/$defs/TokenFormat",
                     "token_dispatch": "#/$defs/TokenDispatchFormat",
                     "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                     "triggered_tags": "#/$defs/TriggeredTagsFormat"
                  },
                  "propertyName": "type"
               },
               "oneOf": [
                  {
                     "$ref": "#/$defs/AnyTextFormat"
                  },
                  {
                     "$ref": "#/$defs/ConstStringFormat"
                  },
                  {
                     "$ref": "#/$defs/JSONSchemaFormat"
                  },
                  {
                     "$ref": "#/$defs/GrammarFormat"
                  },
                  {
                     "$ref": "#/$defs/RegexFormat"
                  },
                  {
                     "$ref": "#/$defs/QwenXMLParameterFormat"
                  },
                  {
                     "$ref": "#/$defs/OrFormat"
                  },
                  {
                     "$ref": "#/$defs/SequenceFormat"
                  },
                  {
                     "$ref": "#/$defs/TagFormat"
                  },
                  {
                     "$ref": "#/$defs/TriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenTriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TagsWithSeparatorFormat"
                  },
                  {
                     "$ref": "#/$defs/OptionalFormat"
                  },
                  {
                     "$ref": "#/$defs/PlusFormat"
                  },
                  {
                     "$ref": "#/$defs/StarFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  },
                  {
                     "$ref": "#/$defs/ExcludeTokenFormat"
                  },
                  {
                     "$ref": "#/$defs/AnyTokensFormat"
                  },
                  {
                     "$ref": "#/$defs/RepeatFormat"
                  },
                  {
                     "$ref": "#/$defs/DispatchFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenDispatchFormat"
                  }
               ],
               "title": "Content"
            }
         },
         "required": [
            "content"
         ],
         "title": "OptionalFormat",
         "type": "object"
      },
      "OrFormat": {
         "description": "A format that matches one of the formats.",
         "properties": {
            "type": {
               "const": "or",
               "default": "or",
               "title": "Type",
               "type": "string"
            },
            "elements": {
               "items": {
                  "discriminator": {
                     "mapping": {
                        "any_text": "#/$defs/AnyTextFormat",
                        "any_tokens": "#/$defs/AnyTokensFormat",
                        "const_string": "#/$defs/ConstStringFormat",
                        "dispatch": "#/$defs/DispatchFormat",
                        "exclude_token": "#/$defs/ExcludeTokenFormat",
                        "grammar": "#/$defs/GrammarFormat",
                        "json_schema": "#/$defs/JSONSchemaFormat",
                        "optional": "#/$defs/OptionalFormat",
                        "or": "#/$defs/OrFormat",
                        "plus": "#/$defs/PlusFormat",
                        "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                        "regex": "#/$defs/RegexFormat",
                        "repeat": "#/$defs/RepeatFormat",
                        "sequence": "#/$defs/SequenceFormat",
                        "star": "#/$defs/StarFormat",
                        "tag": "#/$defs/TagFormat",
                        "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                        "token": "#/$defs/TokenFormat",
                        "token_dispatch": "#/$defs/TokenDispatchFormat",
                        "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                        "triggered_tags": "#/$defs/TriggeredTagsFormat"
                     },
                     "propertyName": "type"
                  },
                  "oneOf": [
                     {
                        "$ref": "#/$defs/AnyTextFormat"
                     },
                     {
                        "$ref": "#/$defs/ConstStringFormat"
                     },
                     {
                        "$ref": "#/$defs/JSONSchemaFormat"
                     },
                     {
                        "$ref": "#/$defs/GrammarFormat"
                     },
                     {
                        "$ref": "#/$defs/RegexFormat"
                     },
                     {
                        "$ref": "#/$defs/QwenXMLParameterFormat"
                     },
                     {
                        "$ref": "#/$defs/OrFormat"
                     },
                     {
                        "$ref": "#/$defs/SequenceFormat"
                     },
                     {
                        "$ref": "#/$defs/TagFormat"
                     },
                     {
                        "$ref": "#/$defs/TriggeredTagsFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenTriggeredTagsFormat"
                     },
                     {
                        "$ref": "#/$defs/TagsWithSeparatorFormat"
                     },
                     {
                        "$ref": "#/$defs/OptionalFormat"
                     },
                     {
                        "$ref": "#/$defs/PlusFormat"
                     },
                     {
                        "$ref": "#/$defs/StarFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenFormat"
                     },
                     {
                        "$ref": "#/$defs/ExcludeTokenFormat"
                     },
                     {
                        "$ref": "#/$defs/AnyTokensFormat"
                     },
                     {
                        "$ref": "#/$defs/RepeatFormat"
                     },
                     {
                        "$ref": "#/$defs/DispatchFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenDispatchFormat"
                     }
                  ]
               },
               "title": "Elements",
               "type": "array"
            }
         },
         "required": [
            "elements"
         ],
         "title": "OrFormat",
         "type": "object"
      },
      "PlusFormat": {
         "description": "A format that matches the content 1 or more times (EBNF plus).\n\nSemantics: the inner format must appear at least once.",
         "properties": {
            "type": {
               "const": "plus",
               "default": "plus",
               "title": "Type",
               "type": "string"
            },
            "content": {
               "discriminator": {
                  "mapping": {
                     "any_text": "#/$defs/AnyTextFormat",
                     "any_tokens": "#/$defs/AnyTokensFormat",
                     "const_string": "#/$defs/ConstStringFormat",
                     "dispatch": "#/$defs/DispatchFormat",
                     "exclude_token": "#/$defs/ExcludeTokenFormat",
                     "grammar": "#/$defs/GrammarFormat",
                     "json_schema": "#/$defs/JSONSchemaFormat",
                     "optional": "#/$defs/OptionalFormat",
                     "or": "#/$defs/OrFormat",
                     "plus": "#/$defs/PlusFormat",
                     "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                     "regex": "#/$defs/RegexFormat",
                     "repeat": "#/$defs/RepeatFormat",
                     "sequence": "#/$defs/SequenceFormat",
                     "star": "#/$defs/StarFormat",
                     "tag": "#/$defs/TagFormat",
                     "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                     "token": "#/$defs/TokenFormat",
                     "token_dispatch": "#/$defs/TokenDispatchFormat",
                     "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                     "triggered_tags": "#/$defs/TriggeredTagsFormat"
                  },
                  "propertyName": "type"
               },
               "oneOf": [
                  {
                     "$ref": "#/$defs/AnyTextFormat"
                  },
                  {
                     "$ref": "#/$defs/ConstStringFormat"
                  },
                  {
                     "$ref": "#/$defs/JSONSchemaFormat"
                  },
                  {
                     "$ref": "#/$defs/GrammarFormat"
                  },
                  {
                     "$ref": "#/$defs/RegexFormat"
                  },
                  {
                     "$ref": "#/$defs/QwenXMLParameterFormat"
                  },
                  {
                     "$ref": "#/$defs/OrFormat"
                  },
                  {
                     "$ref": "#/$defs/SequenceFormat"
                  },
                  {
                     "$ref": "#/$defs/TagFormat"
                  },
                  {
                     "$ref": "#/$defs/TriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenTriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TagsWithSeparatorFormat"
                  },
                  {
                     "$ref": "#/$defs/OptionalFormat"
                  },
                  {
                     "$ref": "#/$defs/PlusFormat"
                  },
                  {
                     "$ref": "#/$defs/StarFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  },
                  {
                     "$ref": "#/$defs/ExcludeTokenFormat"
                  },
                  {
                     "$ref": "#/$defs/AnyTokensFormat"
                  },
                  {
                     "$ref": "#/$defs/RepeatFormat"
                  },
                  {
                     "$ref": "#/$defs/DispatchFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenDispatchFormat"
                  }
               ],
               "title": "Content"
            }
         },
         "required": [
            "content"
         ],
         "title": "PlusFormat",
         "type": "object"
      },
      "QwenXMLParameterFormat": {
         "description": "Deprecated. Use :class:`JSONSchemaFormat` with ``style=\"qwen_xml\"`` instead.\n\nThis format remains available so existing serialized structural tags with\n``{\"type\": \"qwen_xml_parameter\"}`` can still be loaded.\n\nExamples\n--------\nUse the replacement format for new structural tags:\n\n.. code-block:: python\n\n    structural_tag = JSONSchemaFormat(\n        json_schema={\n            \"type\": \"object\",\n            \"properties\": {\"name\": {\"type\": \"string\"}, \"age\": {\"type\": \"integer\"}},\n            \"required\": [\"name\", \"age\"],\n        },\n        style=\"qwen_xml\",\n    )\n\nThe above structural tag can accept the following outputs::\n\n    <parameter=name>Bob</parameter><parameter=age>100</parameter>\n    <parameter=name>\"Bob&lt;\"</parameter><parameter=age>100</parameter>",
         "properties": {
            "type": {
               "const": "qwen_xml_parameter",
               "default": "qwen_xml_parameter",
               "title": "Type",
               "type": "string"
            },
            "json_schema": {
               "anyOf": [
                  {
                     "type": "boolean"
                  },
                  {
                     "additionalProperties": true,
                     "type": "object"
                  }
               ],
               "title": "Json Schema"
            }
         },
         "required": [
            "json_schema"
         ],
         "title": "QwenXMLParameterFormat",
         "type": "object"
      },
      "RegexFormat": {
         "description": "A format that matches a regex pattern.",
         "properties": {
            "type": {
               "const": "regex",
               "default": "regex",
               "title": "Type",
               "type": "string"
            },
            "pattern": {
               "title": "Pattern",
               "type": "string"
            }
         },
         "required": [
            "pattern"
         ],
         "title": "RegexFormat",
         "type": "object"
      },
      "RepeatFormat": {
         "description": "A format that matches the content between min and max times (inclusive).\n\nUse max=-1 for unbounded upper limit (e.g. \"at least min times\").",
         "properties": {
            "type": {
               "const": "repeat",
               "default": "repeat",
               "title": "Type",
               "type": "string"
            },
            "min": {
               "title": "Min",
               "type": "integer"
            },
            "max": {
               "title": "Max",
               "type": "integer"
            },
            "content": {
               "discriminator": {
                  "mapping": {
                     "any_text": "#/$defs/AnyTextFormat",
                     "any_tokens": "#/$defs/AnyTokensFormat",
                     "const_string": "#/$defs/ConstStringFormat",
                     "dispatch": "#/$defs/DispatchFormat",
                     "exclude_token": "#/$defs/ExcludeTokenFormat",
                     "grammar": "#/$defs/GrammarFormat",
                     "json_schema": "#/$defs/JSONSchemaFormat",
                     "optional": "#/$defs/OptionalFormat",
                     "or": "#/$defs/OrFormat",
                     "plus": "#/$defs/PlusFormat",
                     "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                     "regex": "#/$defs/RegexFormat",
                     "repeat": "#/$defs/RepeatFormat",
                     "sequence": "#/$defs/SequenceFormat",
                     "star": "#/$defs/StarFormat",
                     "tag": "#/$defs/TagFormat",
                     "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                     "token": "#/$defs/TokenFormat",
                     "token_dispatch": "#/$defs/TokenDispatchFormat",
                     "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                     "triggered_tags": "#/$defs/TriggeredTagsFormat"
                  },
                  "propertyName": "type"
               },
               "oneOf": [
                  {
                     "$ref": "#/$defs/AnyTextFormat"
                  },
                  {
                     "$ref": "#/$defs/ConstStringFormat"
                  },
                  {
                     "$ref": "#/$defs/JSONSchemaFormat"
                  },
                  {
                     "$ref": "#/$defs/GrammarFormat"
                  },
                  {
                     "$ref": "#/$defs/RegexFormat"
                  },
                  {
                     "$ref": "#/$defs/QwenXMLParameterFormat"
                  },
                  {
                     "$ref": "#/$defs/OrFormat"
                  },
                  {
                     "$ref": "#/$defs/SequenceFormat"
                  },
                  {
                     "$ref": "#/$defs/TagFormat"
                  },
                  {
                     "$ref": "#/$defs/TriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenTriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TagsWithSeparatorFormat"
                  },
                  {
                     "$ref": "#/$defs/OptionalFormat"
                  },
                  {
                     "$ref": "#/$defs/PlusFormat"
                  },
                  {
                     "$ref": "#/$defs/StarFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  },
                  {
                     "$ref": "#/$defs/ExcludeTokenFormat"
                  },
                  {
                     "$ref": "#/$defs/AnyTokensFormat"
                  },
                  {
                     "$ref": "#/$defs/RepeatFormat"
                  },
                  {
                     "$ref": "#/$defs/DispatchFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenDispatchFormat"
                  }
               ],
               "title": "Content"
            }
         },
         "required": [
            "min",
            "max",
            "content"
         ],
         "title": "RepeatFormat",
         "type": "object"
      },
      "SequenceFormat": {
         "description": "A format that matches a sequence of formats.",
         "properties": {
            "type": {
               "const": "sequence",
               "default": "sequence",
               "title": "Type",
               "type": "string"
            },
            "elements": {
               "items": {
                  "discriminator": {
                     "mapping": {
                        "any_text": "#/$defs/AnyTextFormat",
                        "any_tokens": "#/$defs/AnyTokensFormat",
                        "const_string": "#/$defs/ConstStringFormat",
                        "dispatch": "#/$defs/DispatchFormat",
                        "exclude_token": "#/$defs/ExcludeTokenFormat",
                        "grammar": "#/$defs/GrammarFormat",
                        "json_schema": "#/$defs/JSONSchemaFormat",
                        "optional": "#/$defs/OptionalFormat",
                        "or": "#/$defs/OrFormat",
                        "plus": "#/$defs/PlusFormat",
                        "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                        "regex": "#/$defs/RegexFormat",
                        "repeat": "#/$defs/RepeatFormat",
                        "sequence": "#/$defs/SequenceFormat",
                        "star": "#/$defs/StarFormat",
                        "tag": "#/$defs/TagFormat",
                        "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                        "token": "#/$defs/TokenFormat",
                        "token_dispatch": "#/$defs/TokenDispatchFormat",
                        "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                        "triggered_tags": "#/$defs/TriggeredTagsFormat"
                     },
                     "propertyName": "type"
                  },
                  "oneOf": [
                     {
                        "$ref": "#/$defs/AnyTextFormat"
                     },
                     {
                        "$ref": "#/$defs/ConstStringFormat"
                     },
                     {
                        "$ref": "#/$defs/JSONSchemaFormat"
                     },
                     {
                        "$ref": "#/$defs/GrammarFormat"
                     },
                     {
                        "$ref": "#/$defs/RegexFormat"
                     },
                     {
                        "$ref": "#/$defs/QwenXMLParameterFormat"
                     },
                     {
                        "$ref": "#/$defs/OrFormat"
                     },
                     {
                        "$ref": "#/$defs/SequenceFormat"
                     },
                     {
                        "$ref": "#/$defs/TagFormat"
                     },
                     {
                        "$ref": "#/$defs/TriggeredTagsFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenTriggeredTagsFormat"
                     },
                     {
                        "$ref": "#/$defs/TagsWithSeparatorFormat"
                     },
                     {
                        "$ref": "#/$defs/OptionalFormat"
                     },
                     {
                        "$ref": "#/$defs/PlusFormat"
                     },
                     {
                        "$ref": "#/$defs/StarFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenFormat"
                     },
                     {
                        "$ref": "#/$defs/ExcludeTokenFormat"
                     },
                     {
                        "$ref": "#/$defs/AnyTokensFormat"
                     },
                     {
                        "$ref": "#/$defs/RepeatFormat"
                     },
                     {
                        "$ref": "#/$defs/DispatchFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenDispatchFormat"
                     }
                  ]
               },
               "title": "Elements",
               "type": "array"
            }
         },
         "required": [
            "elements"
         ],
         "title": "SequenceFormat",
         "type": "object"
      },
      "StarFormat": {
         "description": "A format that matches the content 0 or more times (EBNF star).\n\nSemantics: the inner format may appear any number of times.",
         "properties": {
            "type": {
               "const": "star",
               "default": "star",
               "title": "Type",
               "type": "string"
            },
            "content": {
               "discriminator": {
                  "mapping": {
                     "any_text": "#/$defs/AnyTextFormat",
                     "any_tokens": "#/$defs/AnyTokensFormat",
                     "const_string": "#/$defs/ConstStringFormat",
                     "dispatch": "#/$defs/DispatchFormat",
                     "exclude_token": "#/$defs/ExcludeTokenFormat",
                     "grammar": "#/$defs/GrammarFormat",
                     "json_schema": "#/$defs/JSONSchemaFormat",
                     "optional": "#/$defs/OptionalFormat",
                     "or": "#/$defs/OrFormat",
                     "plus": "#/$defs/PlusFormat",
                     "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                     "regex": "#/$defs/RegexFormat",
                     "repeat": "#/$defs/RepeatFormat",
                     "sequence": "#/$defs/SequenceFormat",
                     "star": "#/$defs/StarFormat",
                     "tag": "#/$defs/TagFormat",
                     "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                     "token": "#/$defs/TokenFormat",
                     "token_dispatch": "#/$defs/TokenDispatchFormat",
                     "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                     "triggered_tags": "#/$defs/TriggeredTagsFormat"
                  },
                  "propertyName": "type"
               },
               "oneOf": [
                  {
                     "$ref": "#/$defs/AnyTextFormat"
                  },
                  {
                     "$ref": "#/$defs/ConstStringFormat"
                  },
                  {
                     "$ref": "#/$defs/JSONSchemaFormat"
                  },
                  {
                     "$ref": "#/$defs/GrammarFormat"
                  },
                  {
                     "$ref": "#/$defs/RegexFormat"
                  },
                  {
                     "$ref": "#/$defs/QwenXMLParameterFormat"
                  },
                  {
                     "$ref": "#/$defs/OrFormat"
                  },
                  {
                     "$ref": "#/$defs/SequenceFormat"
                  },
                  {
                     "$ref": "#/$defs/TagFormat"
                  },
                  {
                     "$ref": "#/$defs/TriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenTriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TagsWithSeparatorFormat"
                  },
                  {
                     "$ref": "#/$defs/OptionalFormat"
                  },
                  {
                     "$ref": "#/$defs/PlusFormat"
                  },
                  {
                     "$ref": "#/$defs/StarFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  },
                  {
                     "$ref": "#/$defs/ExcludeTokenFormat"
                  },
                  {
                     "$ref": "#/$defs/AnyTokensFormat"
                  },
                  {
                     "$ref": "#/$defs/RepeatFormat"
                  },
                  {
                     "$ref": "#/$defs/DispatchFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenDispatchFormat"
                  }
               ],
               "title": "Content"
            }
         },
         "required": [
            "content"
         ],
         "title": "StarFormat",
         "type": "object"
      },
      "TagFormat": {
         "description": "A format that matches a tag: ``begin content end``.\n\nThe ``end`` field can be a single string or a list of possible end strings.\nWhen multiple end strings are provided, any of them will be accepted as a valid\nending for the tag.\n\nExamples\n--------\n\nSingle end string:\n\n.. code-block:: python\n\n    TagFormat(begin=\"<response>\", content=..., end=\"</response>\")\n\nMultiple end strings:\n\n.. code-block:: python\n\n    TagFormat(begin=\"<response>\", content=..., end=[\"</response>\", \"</answer>\"])",
         "properties": {
            "type": {
               "const": "tag",
               "default": "tag",
               "title": "Type",
               "type": "string"
            },
            "begin": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  }
               ],
               "title": "Begin"
            },
            "content": {
               "discriminator": {
                  "mapping": {
                     "any_text": "#/$defs/AnyTextFormat",
                     "any_tokens": "#/$defs/AnyTokensFormat",
                     "const_string": "#/$defs/ConstStringFormat",
                     "dispatch": "#/$defs/DispatchFormat",
                     "exclude_token": "#/$defs/ExcludeTokenFormat",
                     "grammar": "#/$defs/GrammarFormat",
                     "json_schema": "#/$defs/JSONSchemaFormat",
                     "optional": "#/$defs/OptionalFormat",
                     "or": "#/$defs/OrFormat",
                     "plus": "#/$defs/PlusFormat",
                     "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                     "regex": "#/$defs/RegexFormat",
                     "repeat": "#/$defs/RepeatFormat",
                     "sequence": "#/$defs/SequenceFormat",
                     "star": "#/$defs/StarFormat",
                     "tag": "#/$defs/TagFormat",
                     "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                     "token": "#/$defs/TokenFormat",
                     "token_dispatch": "#/$defs/TokenDispatchFormat",
                     "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                     "triggered_tags": "#/$defs/TriggeredTagsFormat"
                  },
                  "propertyName": "type"
               },
               "oneOf": [
                  {
                     "$ref": "#/$defs/AnyTextFormat"
                  },
                  {
                     "$ref": "#/$defs/ConstStringFormat"
                  },
                  {
                     "$ref": "#/$defs/JSONSchemaFormat"
                  },
                  {
                     "$ref": "#/$defs/GrammarFormat"
                  },
                  {
                     "$ref": "#/$defs/RegexFormat"
                  },
                  {
                     "$ref": "#/$defs/QwenXMLParameterFormat"
                  },
                  {
                     "$ref": "#/$defs/OrFormat"
                  },
                  {
                     "$ref": "#/$defs/SequenceFormat"
                  },
                  {
                     "$ref": "#/$defs/TagFormat"
                  },
                  {
                     "$ref": "#/$defs/TriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenTriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TagsWithSeparatorFormat"
                  },
                  {
                     "$ref": "#/$defs/OptionalFormat"
                  },
                  {
                     "$ref": "#/$defs/PlusFormat"
                  },
                  {
                     "$ref": "#/$defs/StarFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  },
                  {
                     "$ref": "#/$defs/ExcludeTokenFormat"
                  },
                  {
                     "$ref": "#/$defs/AnyTokensFormat"
                  },
                  {
                     "$ref": "#/$defs/RepeatFormat"
                  },
                  {
                     "$ref": "#/$defs/DispatchFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenDispatchFormat"
                  }
               ],
               "title": "Content"
            },
            "end": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "items": {
                        "type": "string"
                     },
                     "type": "array"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  }
               ],
               "title": "End"
            }
         },
         "required": [
            "begin",
            "content",
            "end"
         ],
         "title": "TagFormat",
         "type": "object"
      },
      "TagsWithSeparatorFormat": {
         "description": "A format that matches a tags with separator. It can match zero, one, or more tags, separated\nby the separator, with no other text allowed.\n\nExamples\n--------\n\n.. code-block:: python\n\n    structural_tag = TagsWithSeparatorFormat(\n        tags=[\n            TagFormat(begin=\"<function=func1>\", content=JSONSchemaFormat(json_schema=...), end=\"</function>\"),\n            TagFormat(begin=\"<function=func2>\", content=JSONSchemaFormat(json_schema=...), end=\"</function>\"),\n        ],\n        separator=\",\",\n        at_least_one=False,\n        stop_after_first=False,\n    )\n\nThe above structural tag can accept an empty string, or the following outputs::\n\n    <function=func1>{\"name\": \"John\", \"age\": 30}</function>\n    <function=func1>{\"name\": \"John\", \"age\": 30}</function>,<function=func2>{\"name\": \"Jane\", \"age\": 25}</function>\n    <function=func1>{\"name\": \"John\", \"age\": 30}</function>,<function=func2>{\"name\": \"Jane\", \"age\": 25}</function>,<function=func1>{\"name\": \"John\", \"age\": 30}</function>",
         "properties": {
            "type": {
               "const": "tags_with_separator",
               "default": "tags_with_separator",
               "title": "Type",
               "type": "string"
            },
            "tags": {
               "items": {
                  "$ref": "#/$defs/TagFormat"
               },
               "title": "Tags",
               "type": "array"
            },
            "separator": {
               "title": "Separator",
               "type": "string"
            },
            "at_least_one": {
               "default": false,
               "title": "At Least One",
               "type": "boolean"
            },
            "stop_after_first": {
               "default": false,
               "title": "Stop After First",
               "type": "boolean"
            }
         },
         "required": [
            "tags",
            "separator"
         ],
         "title": "TagsWithSeparatorFormat",
         "type": "object"
      },
      "TokenDispatchFormat": {
         "description": "Matches certain patterns in free-form text.\nWhen certain tokens are generated, the following content must follow the corresponding format.\nCertain tokens can be excluded from being generated in the free-form part.\n\nThe user specifies a list of (pattern token, formats). The LLM can generate any free-form text, but\nwhen a pattern is matched in the text, the following output must follow the corresponding format.\nThe ``loop`` field controls whether the matching of this structure ends after accepting the first\npattern and format. If False, it ends. If true, the matching continues, and this format will\ncontinue to allow free-form text and detect the next pattern to be generated.\nThe ``excludes`` field controls the strings that cannot be generated in the free-form text.\nIt can also control the end of the format:\n``SequenceFormat(DispatchFormat(..., excludes=\"\"), ConstStringFormat(\"\"))``\nor\n``TagFormat(begin=..., content=DispatchFormat(..., excludes=\"\"), end=\"\")``\nends the matching of the format when LLM generates <end>.",
         "properties": {
            "type": {
               "const": "token_dispatch",
               "default": "token_dispatch",
               "title": "Type",
               "type": "string"
            },
            "rules": {
               "items": {
                  "maxItems": 2,
                  "minItems": 2,
                  "prefixItems": [
                     {
                        "anyOf": [
                           {
                              "type": "integer"
                           },
                           {
                              "type": "string"
                           }
                        ]
                     },
                     {
                        "discriminator": {
                           "mapping": {
                              "any_text": "#/$defs/AnyTextFormat",
                              "any_tokens": "#/$defs/AnyTokensFormat",
                              "const_string": "#/$defs/ConstStringFormat",
                              "dispatch": "#/$defs/DispatchFormat",
                              "exclude_token": "#/$defs/ExcludeTokenFormat",
                              "grammar": "#/$defs/GrammarFormat",
                              "json_schema": "#/$defs/JSONSchemaFormat",
                              "optional": "#/$defs/OptionalFormat",
                              "or": "#/$defs/OrFormat",
                              "plus": "#/$defs/PlusFormat",
                              "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                              "regex": "#/$defs/RegexFormat",
                              "repeat": "#/$defs/RepeatFormat",
                              "sequence": "#/$defs/SequenceFormat",
                              "star": "#/$defs/StarFormat",
                              "tag": "#/$defs/TagFormat",
                              "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                              "token": "#/$defs/TokenFormat",
                              "token_dispatch": "#/$defs/TokenDispatchFormat",
                              "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                              "triggered_tags": "#/$defs/TriggeredTagsFormat"
                           },
                           "propertyName": "type"
                        },
                        "oneOf": [
                           {
                              "$ref": "#/$defs/AnyTextFormat"
                           },
                           {
                              "$ref": "#/$defs/ConstStringFormat"
                           },
                           {
                              "$ref": "#/$defs/JSONSchemaFormat"
                           },
                           {
                              "$ref": "#/$defs/GrammarFormat"
                           },
                           {
                              "$ref": "#/$defs/RegexFormat"
                           },
                           {
                              "$ref": "#/$defs/QwenXMLParameterFormat"
                           },
                           {
                              "$ref": "#/$defs/OrFormat"
                           },
                           {
                              "$ref": "#/$defs/SequenceFormat"
                           },
                           {
                              "$ref": "#/$defs/TagFormat"
                           },
                           {
                              "$ref": "#/$defs/TriggeredTagsFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenTriggeredTagsFormat"
                           },
                           {
                              "$ref": "#/$defs/TagsWithSeparatorFormat"
                           },
                           {
                              "$ref": "#/$defs/OptionalFormat"
                           },
                           {
                              "$ref": "#/$defs/PlusFormat"
                           },
                           {
                              "$ref": "#/$defs/StarFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenFormat"
                           },
                           {
                              "$ref": "#/$defs/ExcludeTokenFormat"
                           },
                           {
                              "$ref": "#/$defs/AnyTokensFormat"
                           },
                           {
                              "$ref": "#/$defs/RepeatFormat"
                           },
                           {
                              "$ref": "#/$defs/DispatchFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenDispatchFormat"
                           }
                        ]
                     }
                  ],
                  "type": "array"
               },
               "title": "Rules",
               "type": "array"
            },
            "loop": {
               "default": true,
               "title": "Loop",
               "type": "boolean"
            },
            "exclude_tokens": {
               "default": [],
               "items": {
                  "anyOf": [
                     {
                        "type": "integer"
                     },
                     {
                        "type": "string"
                     }
                  ]
               },
               "title": "Exclude Tokens",
               "type": "array"
            }
         },
         "required": [
            "rules"
         ],
         "title": "TokenDispatchFormat",
         "type": "object"
      },
      "TokenFormat": {
         "description": "A format that matches a single token by ID or string representation.",
         "properties": {
            "type": {
               "const": "token",
               "default": "token",
               "title": "Type",
               "type": "string"
            },
            "token": {
               "anyOf": [
                  {
                     "type": "integer"
                  },
                  {
                     "type": "string"
                  }
               ],
               "title": "Token"
            }
         },
         "required": [
            "token"
         ],
         "title": "TokenFormat",
         "type": "object"
      },
      "TokenTriggeredTagsFormat": {
         "description": "A format that dispatches to tags based on token-level triggers.\n\nSimilar to TriggeredTagsFormat but uses token IDs instead of string triggers.\nTags must use ``TokenFormat`` ``begin`` fields, not strings.\nFor string-level dispatch, use ``TriggeredTagsFormat`` instead.",
         "properties": {
            "type": {
               "const": "token_triggered_tags",
               "default": "token_triggered_tags",
               "title": "Type",
               "type": "string"
            },
            "trigger_tokens": {
               "items": {
                  "anyOf": [
                     {
                        "type": "integer"
                     },
                     {
                        "type": "string"
                     }
                  ]
               },
               "title": "Trigger Tokens",
               "type": "array"
            },
            "tags": {
               "items": {
                  "$ref": "#/$defs/TagFormat"
               },
               "title": "Tags",
               "type": "array"
            },
            "exclude_tokens": {
               "default": [],
               "items": {
                  "anyOf": [
                     {
                        "type": "integer"
                     },
                     {
                        "type": "string"
                     }
                  ]
               },
               "title": "Exclude Tokens",
               "type": "array"
            },
            "at_least_one": {
               "default": false,
               "title": "At Least One",
               "type": "boolean"
            },
            "stop_after_first": {
               "default": false,
               "title": "Stop After First",
               "type": "boolean"
            }
         },
         "required": [
            "trigger_tokens",
            "tags"
         ],
         "title": "TokenTriggeredTagsFormat",
         "type": "object"
      },
      "TriggeredTagsFormat": {
         "description": "A format that matches triggered tags. It can allow any output until a trigger is\nencountered, then dispatch to the corresponding tag; when the end tag is encountered, the\ngrammar will allow any following output, until the next trigger is encountered.\n\nEach tag should be matched by exactly one trigger. \"matching\" means the trigger should be a\nprefix of the begin tag.\n\nTags must use **string** ``begin`` fields, not ``TokenFormat``.\nFor token-level dispatch, use ``TokenTriggeredTagsFormat`` instead.\n\nExamples\n--------\n\n.. code-block:: python\n\n    structural_tag = TriggeredTagsFormat(\n        triggers=[\"<function=\"],\n        tags=[\n            TagFormat(\n                begin=\"<function=func1>\",\n                content=JSONSchemaFormat(json_schema=...),\n                end=\"</function>\",\n            ),\n            TagFormat(\n                begin=\"<function=func2>\",\n                content=JSONSchemaFormat(json_schema=...),\n                end=\"</function>\",\n            ),\n        ],\n        at_least_one=False,\n        stop_after_first=False,\n    )\n\nThe above structural tag can accept the following outputs::\n\n    <function=func1>{\"name\": \"John\", \"age\": 30}</function>\n    <function=func2>{\"name\": \"Jane\", \"age\": 25}</function>\n    any_text<function=func1>{\"name\": \"John\", \"age\": 30}</function>any_text1<function=func2>{\"name\": \"Jane\", \"age\": 25}</function>any_text2",
         "properties": {
            "type": {
               "const": "triggered_tags",
               "default": "triggered_tags",
               "title": "Type",
               "type": "string"
            },
            "triggers": {
               "items": {
                  "type": "string"
               },
               "title": "Triggers",
               "type": "array"
            },
            "tags": {
               "items": {
                  "$ref": "#/$defs/TagFormat"
               },
               "title": "Tags",
               "type": "array"
            },
            "at_least_one": {
               "default": false,
               "title": "At Least One",
               "type": "boolean"
            },
            "stop_after_first": {
               "default": false,
               "title": "Stop After First",
               "type": "boolean"
            },
            "excludes": {
               "default": [],
               "items": {
                  "type": "string"
               },
               "title": "Excludes",
               "type": "array"
            }
         },
         "required": [
            "triggers",
            "tags"
         ],
         "title": "TriggeredTagsFormat",
         "type": "object"
      }
   },
   "$ref": "#/$defs/OrFormat"
}

field type: Literal['or'] = 'or'

The type of the format.

field elements: List[Format] [Required]

The elements of the or.

pydantic model xgrammar.structural_tag.TagFormat[source]

Bases: BaseModel

A format that matches a tag: begin content end.

The end field can be a single string or a list of possible end strings. When multiple end strings are provided, any of them will be accepted as a valid ending for the tag.

Examples

Single end string:

TagFormat(begin="<response>", content=..., end="</response>")

Multiple end strings:

TagFormat(begin="<response>", content=..., end=["</response>", "</answer>"])

Show JSON schema
{
   "$defs": {
      "AnyTextFormat": {
         "description": "A format that matches any text.",
         "properties": {
            "type": {
               "const": "any_text",
               "default": "any_text",
               "title": "Type",
               "type": "string"
            },
            "excludes": {
               "default": [],
               "items": {
                  "type": "string"
               },
               "title": "Excludes",
               "type": "array"
            }
         },
         "title": "AnyTextFormat",
         "type": "object"
      },
      "AnyTokensFormat": {
         "description": "A format that matches zero or more tokens, excluding those in the given set.",
         "properties": {
            "type": {
               "const": "any_tokens",
               "default": "any_tokens",
               "title": "Type",
               "type": "string"
            },
            "exclude_tokens": {
               "default": [],
               "items": {
                  "anyOf": [
                     {
                        "type": "integer"
                     },
                     {
                        "type": "string"
                     }
                  ]
               },
               "title": "Exclude Tokens",
               "type": "array"
            }
         },
         "title": "AnyTokensFormat",
         "type": "object"
      },
      "ConstStringFormat": {
         "description": "A format that matches a constant string.",
         "properties": {
            "type": {
               "const": "const_string",
               "default": "const_string",
               "title": "Type",
               "type": "string"
            },
            "value": {
               "title": "Value",
               "type": "string"
            }
         },
         "required": [
            "value"
         ],
         "title": "ConstStringFormat",
         "type": "object"
      },
      "DispatchFormat": {
         "description": "Matches certain patterns in free-form text.\nWhen certain strings are generated, the following content must follow the corresponding format.\nCertain strings can be excluded from being generated in the free-form part.\n\nThe user specifies a list of (pattern, formats). The LLM can generate any free-form text, but\nwhen a pattern is matched in the text, the following output must follow the corresponding format.\nThe ``loop`` field controls whether the matching of this structure ends after accepting the first\npattern and format. If False, it ends. If true, the matching continues, and this format will\ncontinue to allow free-form text and detect the next pattern to be generated.\nThe ``excludes`` field controls the strings that cannot be generated in the free-form text.\nIt can also control the end of the format:\n``SequenceFormat(DispatchFormat(..., excludes=\"\"), ConstStringFormat(\"\"))``\nor\n``TagFormat(begin=..., content=DispatchFormat(..., excludes=\"\"), end=\"\")``\nends the matching of the format when LLM generates <end>.",
         "properties": {
            "type": {
               "const": "dispatch",
               "default": "dispatch",
               "title": "Type",
               "type": "string"
            },
            "rules": {
               "items": {
                  "maxItems": 2,
                  "minItems": 2,
                  "prefixItems": [
                     {
                        "type": "string"
                     },
                     {
                        "discriminator": {
                           "mapping": {
                              "any_text": "#/$defs/AnyTextFormat",
                              "any_tokens": "#/$defs/AnyTokensFormat",
                              "const_string": "#/$defs/ConstStringFormat",
                              "dispatch": "#/$defs/DispatchFormat",
                              "exclude_token": "#/$defs/ExcludeTokenFormat",
                              "grammar": "#/$defs/GrammarFormat",
                              "json_schema": "#/$defs/JSONSchemaFormat",
                              "optional": "#/$defs/OptionalFormat",
                              "or": "#/$defs/OrFormat",
                              "plus": "#/$defs/PlusFormat",
                              "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                              "regex": "#/$defs/RegexFormat",
                              "repeat": "#/$defs/RepeatFormat",
                              "sequence": "#/$defs/SequenceFormat",
                              "star": "#/$defs/StarFormat",
                              "tag": "#/$defs/TagFormat",
                              "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                              "token": "#/$defs/TokenFormat",
                              "token_dispatch": "#/$defs/TokenDispatchFormat",
                              "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                              "triggered_tags": "#/$defs/TriggeredTagsFormat"
                           },
                           "propertyName": "type"
                        },
                        "oneOf": [
                           {
                              "$ref": "#/$defs/AnyTextFormat"
                           },
                           {
                              "$ref": "#/$defs/ConstStringFormat"
                           },
                           {
                              "$ref": "#/$defs/JSONSchemaFormat"
                           },
                           {
                              "$ref": "#/$defs/GrammarFormat"
                           },
                           {
                              "$ref": "#/$defs/RegexFormat"
                           },
                           {
                              "$ref": "#/$defs/QwenXMLParameterFormat"
                           },
                           {
                              "$ref": "#/$defs/OrFormat"
                           },
                           {
                              "$ref": "#/$defs/SequenceFormat"
                           },
                           {
                              "$ref": "#/$defs/TagFormat"
                           },
                           {
                              "$ref": "#/$defs/TriggeredTagsFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenTriggeredTagsFormat"
                           },
                           {
                              "$ref": "#/$defs/TagsWithSeparatorFormat"
                           },
                           {
                              "$ref": "#/$defs/OptionalFormat"
                           },
                           {
                              "$ref": "#/$defs/PlusFormat"
                           },
                           {
                              "$ref": "#/$defs/StarFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenFormat"
                           },
                           {
                              "$ref": "#/$defs/ExcludeTokenFormat"
                           },
                           {
                              "$ref": "#/$defs/AnyTokensFormat"
                           },
                           {
                              "$ref": "#/$defs/RepeatFormat"
                           },
                           {
                              "$ref": "#/$defs/DispatchFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenDispatchFormat"
                           }
                        ]
                     }
                  ],
                  "type": "array"
               },
               "title": "Rules",
               "type": "array"
            },
            "loop": {
               "default": true,
               "title": "Loop",
               "type": "boolean"
            },
            "excludes": {
               "default": [],
               "items": {
                  "type": "string"
               },
               "title": "Excludes",
               "type": "array"
            }
         },
         "required": [
            "rules"
         ],
         "title": "DispatchFormat",
         "type": "object"
      },
      "ExcludeTokenFormat": {
         "description": "A format that matches a single token, excluding those in the given set.",
         "properties": {
            "type": {
               "const": "exclude_token",
               "default": "exclude_token",
               "title": "Type",
               "type": "string"
            },
            "exclude_tokens": {
               "default": [],
               "items": {
                  "anyOf": [
                     {
                        "type": "integer"
                     },
                     {
                        "type": "string"
                     }
                  ]
               },
               "title": "Exclude Tokens",
               "type": "array"
            }
         },
         "title": "ExcludeTokenFormat",
         "type": "object"
      },
      "GrammarFormat": {
         "description": "A format that matches an ebnf grammar.",
         "properties": {
            "type": {
               "const": "grammar",
               "default": "grammar",
               "title": "Type",
               "type": "string"
            },
            "grammar": {
               "title": "Grammar",
               "type": "string"
            }
         },
         "required": [
            "grammar"
         ],
         "title": "GrammarFormat",
         "type": "object"
      },
      "JSONSchemaFormat": {
         "description": "A format that matches a JSON schema.",
         "properties": {
            "type": {
               "const": "json_schema",
               "default": "json_schema",
               "title": "Type",
               "type": "string"
            },
            "json_schema": {
               "anyOf": [
                  {
                     "type": "boolean"
                  },
                  {
                     "additionalProperties": true,
                     "type": "object"
                  }
               ],
               "title": "Json Schema"
            },
            "style": {
               "default": "json",
               "enum": [
                  "json",
                  "qwen_xml",
                  "minimax_xml",
                  "deepseek_xml",
                  "glm_xml"
               ],
               "title": "Style",
               "type": "string"
            }
         },
         "required": [
            "json_schema"
         ],
         "title": "JSONSchemaFormat",
         "type": "object"
      },
      "OptionalFormat": {
         "description": "A format that matches the content 0 or 1 time (EBNF optional).\n\nSemantics: the inner format may appear once or not at all.",
         "properties": {
            "type": {
               "const": "optional",
               "default": "optional",
               "title": "Type",
               "type": "string"
            },
            "content": {
               "discriminator": {
                  "mapping": {
                     "any_text": "#/$defs/AnyTextFormat",
                     "any_tokens": "#/$defs/AnyTokensFormat",
                     "const_string": "#/$defs/ConstStringFormat",
                     "dispatch": "#/$defs/DispatchFormat",
                     "exclude_token": "#/$defs/ExcludeTokenFormat",
                     "grammar": "#/$defs/GrammarFormat",
                     "json_schema": "#/$defs/JSONSchemaFormat",
                     "optional": "#/$defs/OptionalFormat",
                     "or": "#/$defs/OrFormat",
                     "plus": "#/$defs/PlusFormat",
                     "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                     "regex": "#/$defs/RegexFormat",
                     "repeat": "#/$defs/RepeatFormat",
                     "sequence": "#/$defs/SequenceFormat",
                     "star": "#/$defs/StarFormat",
                     "tag": "#/$defs/TagFormat",
                     "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                     "token": "#/$defs/TokenFormat",
                     "token_dispatch": "#/$defs/TokenDispatchFormat",
                     "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                     "triggered_tags": "#/$defs/TriggeredTagsFormat"
                  },
                  "propertyName": "type"
               },
               "oneOf": [
                  {
                     "$ref": "#/$defs/AnyTextFormat"
                  },
                  {
                     "$ref": "#/$defs/ConstStringFormat"
                  },
                  {
                     "$ref": "#/$defs/JSONSchemaFormat"
                  },
                  {
                     "$ref": "#/$defs/GrammarFormat"
                  },
                  {
                     "$ref": "#/$defs/RegexFormat"
                  },
                  {
                     "$ref": "#/$defs/QwenXMLParameterFormat"
                  },
                  {
                     "$ref": "#/$defs/OrFormat"
                  },
                  {
                     "$ref": "#/$defs/SequenceFormat"
                  },
                  {
                     "$ref": "#/$defs/TagFormat"
                  },
                  {
                     "$ref": "#/$defs/TriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenTriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TagsWithSeparatorFormat"
                  },
                  {
                     "$ref": "#/$defs/OptionalFormat"
                  },
                  {
                     "$ref": "#/$defs/PlusFormat"
                  },
                  {
                     "$ref": "#/$defs/StarFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  },
                  {
                     "$ref": "#/$defs/ExcludeTokenFormat"
                  },
                  {
                     "$ref": "#/$defs/AnyTokensFormat"
                  },
                  {
                     "$ref": "#/$defs/RepeatFormat"
                  },
                  {
                     "$ref": "#/$defs/DispatchFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenDispatchFormat"
                  }
               ],
               "title": "Content"
            }
         },
         "required": [
            "content"
         ],
         "title": "OptionalFormat",
         "type": "object"
      },
      "OrFormat": {
         "description": "A format that matches one of the formats.",
         "properties": {
            "type": {
               "const": "or",
               "default": "or",
               "title": "Type",
               "type": "string"
            },
            "elements": {
               "items": {
                  "discriminator": {
                     "mapping": {
                        "any_text": "#/$defs/AnyTextFormat",
                        "any_tokens": "#/$defs/AnyTokensFormat",
                        "const_string": "#/$defs/ConstStringFormat",
                        "dispatch": "#/$defs/DispatchFormat",
                        "exclude_token": "#/$defs/ExcludeTokenFormat",
                        "grammar": "#/$defs/GrammarFormat",
                        "json_schema": "#/$defs/JSONSchemaFormat",
                        "optional": "#/$defs/OptionalFormat",
                        "or": "#/$defs/OrFormat",
                        "plus": "#/$defs/PlusFormat",
                        "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                        "regex": "#/$defs/RegexFormat",
                        "repeat": "#/$defs/RepeatFormat",
                        "sequence": "#/$defs/SequenceFormat",
                        "star": "#/$defs/StarFormat",
                        "tag": "#/$defs/TagFormat",
                        "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                        "token": "#/$defs/TokenFormat",
                        "token_dispatch": "#/$defs/TokenDispatchFormat",
                        "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                        "triggered_tags": "#/$defs/TriggeredTagsFormat"
                     },
                     "propertyName": "type"
                  },
                  "oneOf": [
                     {
                        "$ref": "#/$defs/AnyTextFormat"
                     },
                     {
                        "$ref": "#/$defs/ConstStringFormat"
                     },
                     {
                        "$ref": "#/$defs/JSONSchemaFormat"
                     },
                     {
                        "$ref": "#/$defs/GrammarFormat"
                     },
                     {
                        "$ref": "#/$defs/RegexFormat"
                     },
                     {
                        "$ref": "#/$defs/QwenXMLParameterFormat"
                     },
                     {
                        "$ref": "#/$defs/OrFormat"
                     },
                     {
                        "$ref": "#/$defs/SequenceFormat"
                     },
                     {
                        "$ref": "#/$defs/TagFormat"
                     },
                     {
                        "$ref": "#/$defs/TriggeredTagsFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenTriggeredTagsFormat"
                     },
                     {
                        "$ref": "#/$defs/TagsWithSeparatorFormat"
                     },
                     {
                        "$ref": "#/$defs/OptionalFormat"
                     },
                     {
                        "$ref": "#/$defs/PlusFormat"
                     },
                     {
                        "$ref": "#/$defs/StarFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenFormat"
                     },
                     {
                        "$ref": "#/$defs/ExcludeTokenFormat"
                     },
                     {
                        "$ref": "#/$defs/AnyTokensFormat"
                     },
                     {
                        "$ref": "#/$defs/RepeatFormat"
                     },
                     {
                        "$ref": "#/$defs/DispatchFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenDispatchFormat"
                     }
                  ]
               },
               "title": "Elements",
               "type": "array"
            }
         },
         "required": [
            "elements"
         ],
         "title": "OrFormat",
         "type": "object"
      },
      "PlusFormat": {
         "description": "A format that matches the content 1 or more times (EBNF plus).\n\nSemantics: the inner format must appear at least once.",
         "properties": {
            "type": {
               "const": "plus",
               "default": "plus",
               "title": "Type",
               "type": "string"
            },
            "content": {
               "discriminator": {
                  "mapping": {
                     "any_text": "#/$defs/AnyTextFormat",
                     "any_tokens": "#/$defs/AnyTokensFormat",
                     "const_string": "#/$defs/ConstStringFormat",
                     "dispatch": "#/$defs/DispatchFormat",
                     "exclude_token": "#/$defs/ExcludeTokenFormat",
                     "grammar": "#/$defs/GrammarFormat",
                     "json_schema": "#/$defs/JSONSchemaFormat",
                     "optional": "#/$defs/OptionalFormat",
                     "or": "#/$defs/OrFormat",
                     "plus": "#/$defs/PlusFormat",
                     "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                     "regex": "#/$defs/RegexFormat",
                     "repeat": "#/$defs/RepeatFormat",
                     "sequence": "#/$defs/SequenceFormat",
                     "star": "#/$defs/StarFormat",
                     "tag": "#/$defs/TagFormat",
                     "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                     "token": "#/$defs/TokenFormat",
                     "token_dispatch": "#/$defs/TokenDispatchFormat",
                     "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                     "triggered_tags": "#/$defs/TriggeredTagsFormat"
                  },
                  "propertyName": "type"
               },
               "oneOf": [
                  {
                     "$ref": "#/$defs/AnyTextFormat"
                  },
                  {
                     "$ref": "#/$defs/ConstStringFormat"
                  },
                  {
                     "$ref": "#/$defs/JSONSchemaFormat"
                  },
                  {
                     "$ref": "#/$defs/GrammarFormat"
                  },
                  {
                     "$ref": "#/$defs/RegexFormat"
                  },
                  {
                     "$ref": "#/$defs/QwenXMLParameterFormat"
                  },
                  {
                     "$ref": "#/$defs/OrFormat"
                  },
                  {
                     "$ref": "#/$defs/SequenceFormat"
                  },
                  {
                     "$ref": "#/$defs/TagFormat"
                  },
                  {
                     "$ref": "#/$defs/TriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenTriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TagsWithSeparatorFormat"
                  },
                  {
                     "$ref": "#/$defs/OptionalFormat"
                  },
                  {
                     "$ref": "#/$defs/PlusFormat"
                  },
                  {
                     "$ref": "#/$defs/StarFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  },
                  {
                     "$ref": "#/$defs/ExcludeTokenFormat"
                  },
                  {
                     "$ref": "#/$defs/AnyTokensFormat"
                  },
                  {
                     "$ref": "#/$defs/RepeatFormat"
                  },
                  {
                     "$ref": "#/$defs/DispatchFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenDispatchFormat"
                  }
               ],
               "title": "Content"
            }
         },
         "required": [
            "content"
         ],
         "title": "PlusFormat",
         "type": "object"
      },
      "QwenXMLParameterFormat": {
         "description": "Deprecated. Use :class:`JSONSchemaFormat` with ``style=\"qwen_xml\"`` instead.\n\nThis format remains available so existing serialized structural tags with\n``{\"type\": \"qwen_xml_parameter\"}`` can still be loaded.\n\nExamples\n--------\nUse the replacement format for new structural tags:\n\n.. code-block:: python\n\n    structural_tag = JSONSchemaFormat(\n        json_schema={\n            \"type\": \"object\",\n            \"properties\": {\"name\": {\"type\": \"string\"}, \"age\": {\"type\": \"integer\"}},\n            \"required\": [\"name\", \"age\"],\n        },\n        style=\"qwen_xml\",\n    )\n\nThe above structural tag can accept the following outputs::\n\n    <parameter=name>Bob</parameter><parameter=age>100</parameter>\n    <parameter=name>\"Bob&lt;\"</parameter><parameter=age>100</parameter>",
         "properties": {
            "type": {
               "const": "qwen_xml_parameter",
               "default": "qwen_xml_parameter",
               "title": "Type",
               "type": "string"
            },
            "json_schema": {
               "anyOf": [
                  {
                     "type": "boolean"
                  },
                  {
                     "additionalProperties": true,
                     "type": "object"
                  }
               ],
               "title": "Json Schema"
            }
         },
         "required": [
            "json_schema"
         ],
         "title": "QwenXMLParameterFormat",
         "type": "object"
      },
      "RegexFormat": {
         "description": "A format that matches a regex pattern.",
         "properties": {
            "type": {
               "const": "regex",
               "default": "regex",
               "title": "Type",
               "type": "string"
            },
            "pattern": {
               "title": "Pattern",
               "type": "string"
            }
         },
         "required": [
            "pattern"
         ],
         "title": "RegexFormat",
         "type": "object"
      },
      "RepeatFormat": {
         "description": "A format that matches the content between min and max times (inclusive).\n\nUse max=-1 for unbounded upper limit (e.g. \"at least min times\").",
         "properties": {
            "type": {
               "const": "repeat",
               "default": "repeat",
               "title": "Type",
               "type": "string"
            },
            "min": {
               "title": "Min",
               "type": "integer"
            },
            "max": {
               "title": "Max",
               "type": "integer"
            },
            "content": {
               "discriminator": {
                  "mapping": {
                     "any_text": "#/$defs/AnyTextFormat",
                     "any_tokens": "#/$defs/AnyTokensFormat",
                     "const_string": "#/$defs/ConstStringFormat",
                     "dispatch": "#/$defs/DispatchFormat",
                     "exclude_token": "#/$defs/ExcludeTokenFormat",
                     "grammar": "#/$defs/GrammarFormat",
                     "json_schema": "#/$defs/JSONSchemaFormat",
                     "optional": "#/$defs/OptionalFormat",
                     "or": "#/$defs/OrFormat",
                     "plus": "#/$defs/PlusFormat",
                     "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                     "regex": "#/$defs/RegexFormat",
                     "repeat": "#/$defs/RepeatFormat",
                     "sequence": "#/$defs/SequenceFormat",
                     "star": "#/$defs/StarFormat",
                     "tag": "#/$defs/TagFormat",
                     "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                     "token": "#/$defs/TokenFormat",
                     "token_dispatch": "#/$defs/TokenDispatchFormat",
                     "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                     "triggered_tags": "#/$defs/TriggeredTagsFormat"
                  },
                  "propertyName": "type"
               },
               "oneOf": [
                  {
                     "$ref": "#/$defs/AnyTextFormat"
                  },
                  {
                     "$ref": "#/$defs/ConstStringFormat"
                  },
                  {
                     "$ref": "#/$defs/JSONSchemaFormat"
                  },
                  {
                     "$ref": "#/$defs/GrammarFormat"
                  },
                  {
                     "$ref": "#/$defs/RegexFormat"
                  },
                  {
                     "$ref": "#/$defs/QwenXMLParameterFormat"
                  },
                  {
                     "$ref": "#/$defs/OrFormat"
                  },
                  {
                     "$ref": "#/$defs/SequenceFormat"
                  },
                  {
                     "$ref": "#/$defs/TagFormat"
                  },
                  {
                     "$ref": "#/$defs/TriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenTriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TagsWithSeparatorFormat"
                  },
                  {
                     "$ref": "#/$defs/OptionalFormat"
                  },
                  {
                     "$ref": "#/$defs/PlusFormat"
                  },
                  {
                     "$ref": "#/$defs/StarFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  },
                  {
                     "$ref": "#/$defs/ExcludeTokenFormat"
                  },
                  {
                     "$ref": "#/$defs/AnyTokensFormat"
                  },
                  {
                     "$ref": "#/$defs/RepeatFormat"
                  },
                  {
                     "$ref": "#/$defs/DispatchFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenDispatchFormat"
                  }
               ],
               "title": "Content"
            }
         },
         "required": [
            "min",
            "max",
            "content"
         ],
         "title": "RepeatFormat",
         "type": "object"
      },
      "SequenceFormat": {
         "description": "A format that matches a sequence of formats.",
         "properties": {
            "type": {
               "const": "sequence",
               "default": "sequence",
               "title": "Type",
               "type": "string"
            },
            "elements": {
               "items": {
                  "discriminator": {
                     "mapping": {
                        "any_text": "#/$defs/AnyTextFormat",
                        "any_tokens": "#/$defs/AnyTokensFormat",
                        "const_string": "#/$defs/ConstStringFormat",
                        "dispatch": "#/$defs/DispatchFormat",
                        "exclude_token": "#/$defs/ExcludeTokenFormat",
                        "grammar": "#/$defs/GrammarFormat",
                        "json_schema": "#/$defs/JSONSchemaFormat",
                        "optional": "#/$defs/OptionalFormat",
                        "or": "#/$defs/OrFormat",
                        "plus": "#/$defs/PlusFormat",
                        "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                        "regex": "#/$defs/RegexFormat",
                        "repeat": "#/$defs/RepeatFormat",
                        "sequence": "#/$defs/SequenceFormat",
                        "star": "#/$defs/StarFormat",
                        "tag": "#/$defs/TagFormat",
                        "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                        "token": "#/$defs/TokenFormat",
                        "token_dispatch": "#/$defs/TokenDispatchFormat",
                        "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                        "triggered_tags": "#/$defs/TriggeredTagsFormat"
                     },
                     "propertyName": "type"
                  },
                  "oneOf": [
                     {
                        "$ref": "#/$defs/AnyTextFormat"
                     },
                     {
                        "$ref": "#/$defs/ConstStringFormat"
                     },
                     {
                        "$ref": "#/$defs/JSONSchemaFormat"
                     },
                     {
                        "$ref": "#/$defs/GrammarFormat"
                     },
                     {
                        "$ref": "#/$defs/RegexFormat"
                     },
                     {
                        "$ref": "#/$defs/QwenXMLParameterFormat"
                     },
                     {
                        "$ref": "#/$defs/OrFormat"
                     },
                     {
                        "$ref": "#/$defs/SequenceFormat"
                     },
                     {
                        "$ref": "#/$defs/TagFormat"
                     },
                     {
                        "$ref": "#/$defs/TriggeredTagsFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenTriggeredTagsFormat"
                     },
                     {
                        "$ref": "#/$defs/TagsWithSeparatorFormat"
                     },
                     {
                        "$ref": "#/$defs/OptionalFormat"
                     },
                     {
                        "$ref": "#/$defs/PlusFormat"
                     },
                     {
                        "$ref": "#/$defs/StarFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenFormat"
                     },
                     {
                        "$ref": "#/$defs/ExcludeTokenFormat"
                     },
                     {
                        "$ref": "#/$defs/AnyTokensFormat"
                     },
                     {
                        "$ref": "#/$defs/RepeatFormat"
                     },
                     {
                        "$ref": "#/$defs/DispatchFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenDispatchFormat"
                     }
                  ]
               },
               "title": "Elements",
               "type": "array"
            }
         },
         "required": [
            "elements"
         ],
         "title": "SequenceFormat",
         "type": "object"
      },
      "StarFormat": {
         "description": "A format that matches the content 0 or more times (EBNF star).\n\nSemantics: the inner format may appear any number of times.",
         "properties": {
            "type": {
               "const": "star",
               "default": "star",
               "title": "Type",
               "type": "string"
            },
            "content": {
               "discriminator": {
                  "mapping": {
                     "any_text": "#/$defs/AnyTextFormat",
                     "any_tokens": "#/$defs/AnyTokensFormat",
                     "const_string": "#/$defs/ConstStringFormat",
                     "dispatch": "#/$defs/DispatchFormat",
                     "exclude_token": "#/$defs/ExcludeTokenFormat",
                     "grammar": "#/$defs/GrammarFormat",
                     "json_schema": "#/$defs/JSONSchemaFormat",
                     "optional": "#/$defs/OptionalFormat",
                     "or": "#/$defs/OrFormat",
                     "plus": "#/$defs/PlusFormat",
                     "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                     "regex": "#/$defs/RegexFormat",
                     "repeat": "#/$defs/RepeatFormat",
                     "sequence": "#/$defs/SequenceFormat",
                     "star": "#/$defs/StarFormat",
                     "tag": "#/$defs/TagFormat",
                     "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                     "token": "#/$defs/TokenFormat",
                     "token_dispatch": "#/$defs/TokenDispatchFormat",
                     "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                     "triggered_tags": "#/$defs/TriggeredTagsFormat"
                  },
                  "propertyName": "type"
               },
               "oneOf": [
                  {
                     "$ref": "#/$defs/AnyTextFormat"
                  },
                  {
                     "$ref": "#/$defs/ConstStringFormat"
                  },
                  {
                     "$ref": "#/$defs/JSONSchemaFormat"
                  },
                  {
                     "$ref": "#/$defs/GrammarFormat"
                  },
                  {
                     "$ref": "#/$defs/RegexFormat"
                  },
                  {
                     "$ref": "#/$defs/QwenXMLParameterFormat"
                  },
                  {
                     "$ref": "#/$defs/OrFormat"
                  },
                  {
                     "$ref": "#/$defs/SequenceFormat"
                  },
                  {
                     "$ref": "#/$defs/TagFormat"
                  },
                  {
                     "$ref": "#/$defs/TriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenTriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TagsWithSeparatorFormat"
                  },
                  {
                     "$ref": "#/$defs/OptionalFormat"
                  },
                  {
                     "$ref": "#/$defs/PlusFormat"
                  },
                  {
                     "$ref": "#/$defs/StarFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  },
                  {
                     "$ref": "#/$defs/ExcludeTokenFormat"
                  },
                  {
                     "$ref": "#/$defs/AnyTokensFormat"
                  },
                  {
                     "$ref": "#/$defs/RepeatFormat"
                  },
                  {
                     "$ref": "#/$defs/DispatchFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenDispatchFormat"
                  }
               ],
               "title": "Content"
            }
         },
         "required": [
            "content"
         ],
         "title": "StarFormat",
         "type": "object"
      },
      "TagFormat": {
         "description": "A format that matches a tag: ``begin content end``.\n\nThe ``end`` field can be a single string or a list of possible end strings.\nWhen multiple end strings are provided, any of them will be accepted as a valid\nending for the tag.\n\nExamples\n--------\n\nSingle end string:\n\n.. code-block:: python\n\n    TagFormat(begin=\"<response>\", content=..., end=\"</response>\")\n\nMultiple end strings:\n\n.. code-block:: python\n\n    TagFormat(begin=\"<response>\", content=..., end=[\"</response>\", \"</answer>\"])",
         "properties": {
            "type": {
               "const": "tag",
               "default": "tag",
               "title": "Type",
               "type": "string"
            },
            "begin": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  }
               ],
               "title": "Begin"
            },
            "content": {
               "discriminator": {
                  "mapping": {
                     "any_text": "#/$defs/AnyTextFormat",
                     "any_tokens": "#/$defs/AnyTokensFormat",
                     "const_string": "#/$defs/ConstStringFormat",
                     "dispatch": "#/$defs/DispatchFormat",
                     "exclude_token": "#/$defs/ExcludeTokenFormat",
                     "grammar": "#/$defs/GrammarFormat",
                     "json_schema": "#/$defs/JSONSchemaFormat",
                     "optional": "#/$defs/OptionalFormat",
                     "or": "#/$defs/OrFormat",
                     "plus": "#/$defs/PlusFormat",
                     "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                     "regex": "#/$defs/RegexFormat",
                     "repeat": "#/$defs/RepeatFormat",
                     "sequence": "#/$defs/SequenceFormat",
                     "star": "#/$defs/StarFormat",
                     "tag": "#/$defs/TagFormat",
                     "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                     "token": "#/$defs/TokenFormat",
                     "token_dispatch": "#/$defs/TokenDispatchFormat",
                     "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                     "triggered_tags": "#/$defs/TriggeredTagsFormat"
                  },
                  "propertyName": "type"
               },
               "oneOf": [
                  {
                     "$ref": "#/$defs/AnyTextFormat"
                  },
                  {
                     "$ref": "#/$defs/ConstStringFormat"
                  },
                  {
                     "$ref": "#/$defs/JSONSchemaFormat"
                  },
                  {
                     "$ref": "#/$defs/GrammarFormat"
                  },
                  {
                     "$ref": "#/$defs/RegexFormat"
                  },
                  {
                     "$ref": "#/$defs/QwenXMLParameterFormat"
                  },
                  {
                     "$ref": "#/$defs/OrFormat"
                  },
                  {
                     "$ref": "#/$defs/SequenceFormat"
                  },
                  {
                     "$ref": "#/$defs/TagFormat"
                  },
                  {
                     "$ref": "#/$defs/TriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenTriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TagsWithSeparatorFormat"
                  },
                  {
                     "$ref": "#/$defs/OptionalFormat"
                  },
                  {
                     "$ref": "#/$defs/PlusFormat"
                  },
                  {
                     "$ref": "#/$defs/StarFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  },
                  {
                     "$ref": "#/$defs/ExcludeTokenFormat"
                  },
                  {
                     "$ref": "#/$defs/AnyTokensFormat"
                  },
                  {
                     "$ref": "#/$defs/RepeatFormat"
                  },
                  {
                     "$ref": "#/$defs/DispatchFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenDispatchFormat"
                  }
               ],
               "title": "Content"
            },
            "end": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "items": {
                        "type": "string"
                     },
                     "type": "array"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  }
               ],
               "title": "End"
            }
         },
         "required": [
            "begin",
            "content",
            "end"
         ],
         "title": "TagFormat",
         "type": "object"
      },
      "TagsWithSeparatorFormat": {
         "description": "A format that matches a tags with separator. It can match zero, one, or more tags, separated\nby the separator, with no other text allowed.\n\nExamples\n--------\n\n.. code-block:: python\n\n    structural_tag = TagsWithSeparatorFormat(\n        tags=[\n            TagFormat(begin=\"<function=func1>\", content=JSONSchemaFormat(json_schema=...), end=\"</function>\"),\n            TagFormat(begin=\"<function=func2>\", content=JSONSchemaFormat(json_schema=...), end=\"</function>\"),\n        ],\n        separator=\",\",\n        at_least_one=False,\n        stop_after_first=False,\n    )\n\nThe above structural tag can accept an empty string, or the following outputs::\n\n    <function=func1>{\"name\": \"John\", \"age\": 30}</function>\n    <function=func1>{\"name\": \"John\", \"age\": 30}</function>,<function=func2>{\"name\": \"Jane\", \"age\": 25}</function>\n    <function=func1>{\"name\": \"John\", \"age\": 30}</function>,<function=func2>{\"name\": \"Jane\", \"age\": 25}</function>,<function=func1>{\"name\": \"John\", \"age\": 30}</function>",
         "properties": {
            "type": {
               "const": "tags_with_separator",
               "default": "tags_with_separator",
               "title": "Type",
               "type": "string"
            },
            "tags": {
               "items": {
                  "$ref": "#/$defs/TagFormat"
               },
               "title": "Tags",
               "type": "array"
            },
            "separator": {
               "title": "Separator",
               "type": "string"
            },
            "at_least_one": {
               "default": false,
               "title": "At Least One",
               "type": "boolean"
            },
            "stop_after_first": {
               "default": false,
               "title": "Stop After First",
               "type": "boolean"
            }
         },
         "required": [
            "tags",
            "separator"
         ],
         "title": "TagsWithSeparatorFormat",
         "type": "object"
      },
      "TokenDispatchFormat": {
         "description": "Matches certain patterns in free-form text.\nWhen certain tokens are generated, the following content must follow the corresponding format.\nCertain tokens can be excluded from being generated in the free-form part.\n\nThe user specifies a list of (pattern token, formats). The LLM can generate any free-form text, but\nwhen a pattern is matched in the text, the following output must follow the corresponding format.\nThe ``loop`` field controls whether the matching of this structure ends after accepting the first\npattern and format. If False, it ends. If true, the matching continues, and this format will\ncontinue to allow free-form text and detect the next pattern to be generated.\nThe ``excludes`` field controls the strings that cannot be generated in the free-form text.\nIt can also control the end of the format:\n``SequenceFormat(DispatchFormat(..., excludes=\"\"), ConstStringFormat(\"\"))``\nor\n``TagFormat(begin=..., content=DispatchFormat(..., excludes=\"\"), end=\"\")``\nends the matching of the format when LLM generates <end>.",
         "properties": {
            "type": {
               "const": "token_dispatch",
               "default": "token_dispatch",
               "title": "Type",
               "type": "string"
            },
            "rules": {
               "items": {
                  "maxItems": 2,
                  "minItems": 2,
                  "prefixItems": [
                     {
                        "anyOf": [
                           {
                              "type": "integer"
                           },
                           {
                              "type": "string"
                           }
                        ]
                     },
                     {
                        "discriminator": {
                           "mapping": {
                              "any_text": "#/$defs/AnyTextFormat",
                              "any_tokens": "#/$defs/AnyTokensFormat",
                              "const_string": "#/$defs/ConstStringFormat",
                              "dispatch": "#/$defs/DispatchFormat",
                              "exclude_token": "#/$defs/ExcludeTokenFormat",
                              "grammar": "#/$defs/GrammarFormat",
                              "json_schema": "#/$defs/JSONSchemaFormat",
                              "optional": "#/$defs/OptionalFormat",
                              "or": "#/$defs/OrFormat",
                              "plus": "#/$defs/PlusFormat",
                              "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                              "regex": "#/$defs/RegexFormat",
                              "repeat": "#/$defs/RepeatFormat",
                              "sequence": "#/$defs/SequenceFormat",
                              "star": "#/$defs/StarFormat",
                              "tag": "#/$defs/TagFormat",
                              "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                              "token": "#/$defs/TokenFormat",
                              "token_dispatch": "#/$defs/TokenDispatchFormat",
                              "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                              "triggered_tags": "#/$defs/TriggeredTagsFormat"
                           },
                           "propertyName": "type"
                        },
                        "oneOf": [
                           {
                              "$ref": "#/$defs/AnyTextFormat"
                           },
                           {
                              "$ref": "#/$defs/ConstStringFormat"
                           },
                           {
                              "$ref": "#/$defs/JSONSchemaFormat"
                           },
                           {
                              "$ref": "#/$defs/GrammarFormat"
                           },
                           {
                              "$ref": "#/$defs/RegexFormat"
                           },
                           {
                              "$ref": "#/$defs/QwenXMLParameterFormat"
                           },
                           {
                              "$ref": "#/$defs/OrFormat"
                           },
                           {
                              "$ref": "#/$defs/SequenceFormat"
                           },
                           {
                              "$ref": "#/$defs/TagFormat"
                           },
                           {
                              "$ref": "#/$defs/TriggeredTagsFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenTriggeredTagsFormat"
                           },
                           {
                              "$ref": "#/$defs/TagsWithSeparatorFormat"
                           },
                           {
                              "$ref": "#/$defs/OptionalFormat"
                           },
                           {
                              "$ref": "#/$defs/PlusFormat"
                           },
                           {
                              "$ref": "#/$defs/StarFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenFormat"
                           },
                           {
                              "$ref": "#/$defs/ExcludeTokenFormat"
                           },
                           {
                              "$ref": "#/$defs/AnyTokensFormat"
                           },
                           {
                              "$ref": "#/$defs/RepeatFormat"
                           },
                           {
                              "$ref": "#/$defs/DispatchFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenDispatchFormat"
                           }
                        ]
                     }
                  ],
                  "type": "array"
               },
               "title": "Rules",
               "type": "array"
            },
            "loop": {
               "default": true,
               "title": "Loop",
               "type": "boolean"
            },
            "exclude_tokens": {
               "default": [],
               "items": {
                  "anyOf": [
                     {
                        "type": "integer"
                     },
                     {
                        "type": "string"
                     }
                  ]
               },
               "title": "Exclude Tokens",
               "type": "array"
            }
         },
         "required": [
            "rules"
         ],
         "title": "TokenDispatchFormat",
         "type": "object"
      },
      "TokenFormat": {
         "description": "A format that matches a single token by ID or string representation.",
         "properties": {
            "type": {
               "const": "token",
               "default": "token",
               "title": "Type",
               "type": "string"
            },
            "token": {
               "anyOf": [
                  {
                     "type": "integer"
                  },
                  {
                     "type": "string"
                  }
               ],
               "title": "Token"
            }
         },
         "required": [
            "token"
         ],
         "title": "TokenFormat",
         "type": "object"
      },
      "TokenTriggeredTagsFormat": {
         "description": "A format that dispatches to tags based on token-level triggers.\n\nSimilar to TriggeredTagsFormat but uses token IDs instead of string triggers.\nTags must use ``TokenFormat`` ``begin`` fields, not strings.\nFor string-level dispatch, use ``TriggeredTagsFormat`` instead.",
         "properties": {
            "type": {
               "const": "token_triggered_tags",
               "default": "token_triggered_tags",
               "title": "Type",
               "type": "string"
            },
            "trigger_tokens": {
               "items": {
                  "anyOf": [
                     {
                        "type": "integer"
                     },
                     {
                        "type": "string"
                     }
                  ]
               },
               "title": "Trigger Tokens",
               "type": "array"
            },
            "tags": {
               "items": {
                  "$ref": "#/$defs/TagFormat"
               },
               "title": "Tags",
               "type": "array"
            },
            "exclude_tokens": {
               "default": [],
               "items": {
                  "anyOf": [
                     {
                        "type": "integer"
                     },
                     {
                        "type": "string"
                     }
                  ]
               },
               "title": "Exclude Tokens",
               "type": "array"
            },
            "at_least_one": {
               "default": false,
               "title": "At Least One",
               "type": "boolean"
            },
            "stop_after_first": {
               "default": false,
               "title": "Stop After First",
               "type": "boolean"
            }
         },
         "required": [
            "trigger_tokens",
            "tags"
         ],
         "title": "TokenTriggeredTagsFormat",
         "type": "object"
      },
      "TriggeredTagsFormat": {
         "description": "A format that matches triggered tags. It can allow any output until a trigger is\nencountered, then dispatch to the corresponding tag; when the end tag is encountered, the\ngrammar will allow any following output, until the next trigger is encountered.\n\nEach tag should be matched by exactly one trigger. \"matching\" means the trigger should be a\nprefix of the begin tag.\n\nTags must use **string** ``begin`` fields, not ``TokenFormat``.\nFor token-level dispatch, use ``TokenTriggeredTagsFormat`` instead.\n\nExamples\n--------\n\n.. code-block:: python\n\n    structural_tag = TriggeredTagsFormat(\n        triggers=[\"<function=\"],\n        tags=[\n            TagFormat(\n                begin=\"<function=func1>\",\n                content=JSONSchemaFormat(json_schema=...),\n                end=\"</function>\",\n            ),\n            TagFormat(\n                begin=\"<function=func2>\",\n                content=JSONSchemaFormat(json_schema=...),\n                end=\"</function>\",\n            ),\n        ],\n        at_least_one=False,\n        stop_after_first=False,\n    )\n\nThe above structural tag can accept the following outputs::\n\n    <function=func1>{\"name\": \"John\", \"age\": 30}</function>\n    <function=func2>{\"name\": \"Jane\", \"age\": 25}</function>\n    any_text<function=func1>{\"name\": \"John\", \"age\": 30}</function>any_text1<function=func2>{\"name\": \"Jane\", \"age\": 25}</function>any_text2",
         "properties": {
            "type": {
               "const": "triggered_tags",
               "default": "triggered_tags",
               "title": "Type",
               "type": "string"
            },
            "triggers": {
               "items": {
                  "type": "string"
               },
               "title": "Triggers",
               "type": "array"
            },
            "tags": {
               "items": {
                  "$ref": "#/$defs/TagFormat"
               },
               "title": "Tags",
               "type": "array"
            },
            "at_least_one": {
               "default": false,
               "title": "At Least One",
               "type": "boolean"
            },
            "stop_after_first": {
               "default": false,
               "title": "Stop After First",
               "type": "boolean"
            },
            "excludes": {
               "default": [],
               "items": {
                  "type": "string"
               },
               "title": "Excludes",
               "type": "array"
            }
         },
         "required": [
            "triggers",
            "tags"
         ],
         "title": "TriggeredTagsFormat",
         "type": "object"
      }
   },
   "$ref": "#/$defs/TagFormat"
}

field type: Literal['tag'] = 'tag'

The type of the format.

field begin: Union[str, TokenFormat] [Required]

The begin tag. Can be a string or a TokenFormat.

field content: Format [Required]

The content of the tag. It can be any of the formats.

field end: Union[str, List[str], TokenFormat] [Required]

The end tag(s). Can be a string, list of strings, or a TokenFormat.

pydantic model xgrammar.structural_tag.TriggeredTagsFormat[source]

Bases: BaseModel

A format that matches triggered tags. It can allow any output until a trigger is encountered, then dispatch to the corresponding tag; when the end tag is encountered, the grammar will allow any following output, until the next trigger is encountered.

Each tag should be matched by exactly one trigger. “matching” means the trigger should be a prefix of the begin tag.

Tags must use string begin fields, not TokenFormat. For token-level dispatch, use TokenTriggeredTagsFormat instead.

Examples

structural_tag = TriggeredTagsFormat(
    triggers=["<function="],
    tags=[
        TagFormat(
            begin="<function=func1>",
            content=JSONSchemaFormat(json_schema=...),
            end="</function>",
        ),
        TagFormat(
            begin="<function=func2>",
            content=JSONSchemaFormat(json_schema=...),
            end="</function>",
        ),
    ],
    at_least_one=False,
    stop_after_first=False,
)

The above structural tag can accept the following outputs:

<function=func1>{"name": "John", "age": 30}</function>
<function=func2>{"name": "Jane", "age": 25}</function>
any_text<function=func1>{"name": "John", "age": 30}</function>any_text1<function=func2>{"name": "Jane", "age": 25}</function>any_text2

Show JSON schema
{
   "$defs": {
      "AnyTextFormat": {
         "description": "A format that matches any text.",
         "properties": {
            "type": {
               "const": "any_text",
               "default": "any_text",
               "title": "Type",
               "type": "string"
            },
            "excludes": {
               "default": [],
               "items": {
                  "type": "string"
               },
               "title": "Excludes",
               "type": "array"
            }
         },
         "title": "AnyTextFormat",
         "type": "object"
      },
      "AnyTokensFormat": {
         "description": "A format that matches zero or more tokens, excluding those in the given set.",
         "properties": {
            "type": {
               "const": "any_tokens",
               "default": "any_tokens",
               "title": "Type",
               "type": "string"
            },
            "exclude_tokens": {
               "default": [],
               "items": {
                  "anyOf": [
                     {
                        "type": "integer"
                     },
                     {
                        "type": "string"
                     }
                  ]
               },
               "title": "Exclude Tokens",
               "type": "array"
            }
         },
         "title": "AnyTokensFormat",
         "type": "object"
      },
      "ConstStringFormat": {
         "description": "A format that matches a constant string.",
         "properties": {
            "type": {
               "const": "const_string",
               "default": "const_string",
               "title": "Type",
               "type": "string"
            },
            "value": {
               "title": "Value",
               "type": "string"
            }
         },
         "required": [
            "value"
         ],
         "title": "ConstStringFormat",
         "type": "object"
      },
      "DispatchFormat": {
         "description": "Matches certain patterns in free-form text.\nWhen certain strings are generated, the following content must follow the corresponding format.\nCertain strings can be excluded from being generated in the free-form part.\n\nThe user specifies a list of (pattern, formats). The LLM can generate any free-form text, but\nwhen a pattern is matched in the text, the following output must follow the corresponding format.\nThe ``loop`` field controls whether the matching of this structure ends after accepting the first\npattern and format. If False, it ends. If true, the matching continues, and this format will\ncontinue to allow free-form text and detect the next pattern to be generated.\nThe ``excludes`` field controls the strings that cannot be generated in the free-form text.\nIt can also control the end of the format:\n``SequenceFormat(DispatchFormat(..., excludes=\"\"), ConstStringFormat(\"\"))``\nor\n``TagFormat(begin=..., content=DispatchFormat(..., excludes=\"\"), end=\"\")``\nends the matching of the format when LLM generates <end>.",
         "properties": {
            "type": {
               "const": "dispatch",
               "default": "dispatch",
               "title": "Type",
               "type": "string"
            },
            "rules": {
               "items": {
                  "maxItems": 2,
                  "minItems": 2,
                  "prefixItems": [
                     {
                        "type": "string"
                     },
                     {
                        "discriminator": {
                           "mapping": {
                              "any_text": "#/$defs/AnyTextFormat",
                              "any_tokens": "#/$defs/AnyTokensFormat",
                              "const_string": "#/$defs/ConstStringFormat",
                              "dispatch": "#/$defs/DispatchFormat",
                              "exclude_token": "#/$defs/ExcludeTokenFormat",
                              "grammar": "#/$defs/GrammarFormat",
                              "json_schema": "#/$defs/JSONSchemaFormat",
                              "optional": "#/$defs/OptionalFormat",
                              "or": "#/$defs/OrFormat",
                              "plus": "#/$defs/PlusFormat",
                              "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                              "regex": "#/$defs/RegexFormat",
                              "repeat": "#/$defs/RepeatFormat",
                              "sequence": "#/$defs/SequenceFormat",
                              "star": "#/$defs/StarFormat",
                              "tag": "#/$defs/TagFormat",
                              "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                              "token": "#/$defs/TokenFormat",
                              "token_dispatch": "#/$defs/TokenDispatchFormat",
                              "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                              "triggered_tags": "#/$defs/TriggeredTagsFormat"
                           },
                           "propertyName": "type"
                        },
                        "oneOf": [
                           {
                              "$ref": "#/$defs/AnyTextFormat"
                           },
                           {
                              "$ref": "#/$defs/ConstStringFormat"
                           },
                           {
                              "$ref": "#/$defs/JSONSchemaFormat"
                           },
                           {
                              "$ref": "#/$defs/GrammarFormat"
                           },
                           {
                              "$ref": "#/$defs/RegexFormat"
                           },
                           {
                              "$ref": "#/$defs/QwenXMLParameterFormat"
                           },
                           {
                              "$ref": "#/$defs/OrFormat"
                           },
                           {
                              "$ref": "#/$defs/SequenceFormat"
                           },
                           {
                              "$ref": "#/$defs/TagFormat"
                           },
                           {
                              "$ref": "#/$defs/TriggeredTagsFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenTriggeredTagsFormat"
                           },
                           {
                              "$ref": "#/$defs/TagsWithSeparatorFormat"
                           },
                           {
                              "$ref": "#/$defs/OptionalFormat"
                           },
                           {
                              "$ref": "#/$defs/PlusFormat"
                           },
                           {
                              "$ref": "#/$defs/StarFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenFormat"
                           },
                           {
                              "$ref": "#/$defs/ExcludeTokenFormat"
                           },
                           {
                              "$ref": "#/$defs/AnyTokensFormat"
                           },
                           {
                              "$ref": "#/$defs/RepeatFormat"
                           },
                           {
                              "$ref": "#/$defs/DispatchFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenDispatchFormat"
                           }
                        ]
                     }
                  ],
                  "type": "array"
               },
               "title": "Rules",
               "type": "array"
            },
            "loop": {
               "default": true,
               "title": "Loop",
               "type": "boolean"
            },
            "excludes": {
               "default": [],
               "items": {
                  "type": "string"
               },
               "title": "Excludes",
               "type": "array"
            }
         },
         "required": [
            "rules"
         ],
         "title": "DispatchFormat",
         "type": "object"
      },
      "ExcludeTokenFormat": {
         "description": "A format that matches a single token, excluding those in the given set.",
         "properties": {
            "type": {
               "const": "exclude_token",
               "default": "exclude_token",
               "title": "Type",
               "type": "string"
            },
            "exclude_tokens": {
               "default": [],
               "items": {
                  "anyOf": [
                     {
                        "type": "integer"
                     },
                     {
                        "type": "string"
                     }
                  ]
               },
               "title": "Exclude Tokens",
               "type": "array"
            }
         },
         "title": "ExcludeTokenFormat",
         "type": "object"
      },
      "GrammarFormat": {
         "description": "A format that matches an ebnf grammar.",
         "properties": {
            "type": {
               "const": "grammar",
               "default": "grammar",
               "title": "Type",
               "type": "string"
            },
            "grammar": {
               "title": "Grammar",
               "type": "string"
            }
         },
         "required": [
            "grammar"
         ],
         "title": "GrammarFormat",
         "type": "object"
      },
      "JSONSchemaFormat": {
         "description": "A format that matches a JSON schema.",
         "properties": {
            "type": {
               "const": "json_schema",
               "default": "json_schema",
               "title": "Type",
               "type": "string"
            },
            "json_schema": {
               "anyOf": [
                  {
                     "type": "boolean"
                  },
                  {
                     "additionalProperties": true,
                     "type": "object"
                  }
               ],
               "title": "Json Schema"
            },
            "style": {
               "default": "json",
               "enum": [
                  "json",
                  "qwen_xml",
                  "minimax_xml",
                  "deepseek_xml",
                  "glm_xml"
               ],
               "title": "Style",
               "type": "string"
            }
         },
         "required": [
            "json_schema"
         ],
         "title": "JSONSchemaFormat",
         "type": "object"
      },
      "OptionalFormat": {
         "description": "A format that matches the content 0 or 1 time (EBNF optional).\n\nSemantics: the inner format may appear once or not at all.",
         "properties": {
            "type": {
               "const": "optional",
               "default": "optional",
               "title": "Type",
               "type": "string"
            },
            "content": {
               "discriminator": {
                  "mapping": {
                     "any_text": "#/$defs/AnyTextFormat",
                     "any_tokens": "#/$defs/AnyTokensFormat",
                     "const_string": "#/$defs/ConstStringFormat",
                     "dispatch": "#/$defs/DispatchFormat",
                     "exclude_token": "#/$defs/ExcludeTokenFormat",
                     "grammar": "#/$defs/GrammarFormat",
                     "json_schema": "#/$defs/JSONSchemaFormat",
                     "optional": "#/$defs/OptionalFormat",
                     "or": "#/$defs/OrFormat",
                     "plus": "#/$defs/PlusFormat",
                     "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                     "regex": "#/$defs/RegexFormat",
                     "repeat": "#/$defs/RepeatFormat",
                     "sequence": "#/$defs/SequenceFormat",
                     "star": "#/$defs/StarFormat",
                     "tag": "#/$defs/TagFormat",
                     "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                     "token": "#/$defs/TokenFormat",
                     "token_dispatch": "#/$defs/TokenDispatchFormat",
                     "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                     "triggered_tags": "#/$defs/TriggeredTagsFormat"
                  },
                  "propertyName": "type"
               },
               "oneOf": [
                  {
                     "$ref": "#/$defs/AnyTextFormat"
                  },
                  {
                     "$ref": "#/$defs/ConstStringFormat"
                  },
                  {
                     "$ref": "#/$defs/JSONSchemaFormat"
                  },
                  {
                     "$ref": "#/$defs/GrammarFormat"
                  },
                  {
                     "$ref": "#/$defs/RegexFormat"
                  },
                  {
                     "$ref": "#/$defs/QwenXMLParameterFormat"
                  },
                  {
                     "$ref": "#/$defs/OrFormat"
                  },
                  {
                     "$ref": "#/$defs/SequenceFormat"
                  },
                  {
                     "$ref": "#/$defs/TagFormat"
                  },
                  {
                     "$ref": "#/$defs/TriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenTriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TagsWithSeparatorFormat"
                  },
                  {
                     "$ref": "#/$defs/OptionalFormat"
                  },
                  {
                     "$ref": "#/$defs/PlusFormat"
                  },
                  {
                     "$ref": "#/$defs/StarFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  },
                  {
                     "$ref": "#/$defs/ExcludeTokenFormat"
                  },
                  {
                     "$ref": "#/$defs/AnyTokensFormat"
                  },
                  {
                     "$ref": "#/$defs/RepeatFormat"
                  },
                  {
                     "$ref": "#/$defs/DispatchFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenDispatchFormat"
                  }
               ],
               "title": "Content"
            }
         },
         "required": [
            "content"
         ],
         "title": "OptionalFormat",
         "type": "object"
      },
      "OrFormat": {
         "description": "A format that matches one of the formats.",
         "properties": {
            "type": {
               "const": "or",
               "default": "or",
               "title": "Type",
               "type": "string"
            },
            "elements": {
               "items": {
                  "discriminator": {
                     "mapping": {
                        "any_text": "#/$defs/AnyTextFormat",
                        "any_tokens": "#/$defs/AnyTokensFormat",
                        "const_string": "#/$defs/ConstStringFormat",
                        "dispatch": "#/$defs/DispatchFormat",
                        "exclude_token": "#/$defs/ExcludeTokenFormat",
                        "grammar": "#/$defs/GrammarFormat",
                        "json_schema": "#/$defs/JSONSchemaFormat",
                        "optional": "#/$defs/OptionalFormat",
                        "or": "#/$defs/OrFormat",
                        "plus": "#/$defs/PlusFormat",
                        "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                        "regex": "#/$defs/RegexFormat",
                        "repeat": "#/$defs/RepeatFormat",
                        "sequence": "#/$defs/SequenceFormat",
                        "star": "#/$defs/StarFormat",
                        "tag": "#/$defs/TagFormat",
                        "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                        "token": "#/$defs/TokenFormat",
                        "token_dispatch": "#/$defs/TokenDispatchFormat",
                        "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                        "triggered_tags": "#/$defs/TriggeredTagsFormat"
                     },
                     "propertyName": "type"
                  },
                  "oneOf": [
                     {
                        "$ref": "#/$defs/AnyTextFormat"
                     },
                     {
                        "$ref": "#/$defs/ConstStringFormat"
                     },
                     {
                        "$ref": "#/$defs/JSONSchemaFormat"
                     },
                     {
                        "$ref": "#/$defs/GrammarFormat"
                     },
                     {
                        "$ref": "#/$defs/RegexFormat"
                     },
                     {
                        "$ref": "#/$defs/QwenXMLParameterFormat"
                     },
                     {
                        "$ref": "#/$defs/OrFormat"
                     },
                     {
                        "$ref": "#/$defs/SequenceFormat"
                     },
                     {
                        "$ref": "#/$defs/TagFormat"
                     },
                     {
                        "$ref": "#/$defs/TriggeredTagsFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenTriggeredTagsFormat"
                     },
                     {
                        "$ref": "#/$defs/TagsWithSeparatorFormat"
                     },
                     {
                        "$ref": "#/$defs/OptionalFormat"
                     },
                     {
                        "$ref": "#/$defs/PlusFormat"
                     },
                     {
                        "$ref": "#/$defs/StarFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenFormat"
                     },
                     {
                        "$ref": "#/$defs/ExcludeTokenFormat"
                     },
                     {
                        "$ref": "#/$defs/AnyTokensFormat"
                     },
                     {
                        "$ref": "#/$defs/RepeatFormat"
                     },
                     {
                        "$ref": "#/$defs/DispatchFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenDispatchFormat"
                     }
                  ]
               },
               "title": "Elements",
               "type": "array"
            }
         },
         "required": [
            "elements"
         ],
         "title": "OrFormat",
         "type": "object"
      },
      "PlusFormat": {
         "description": "A format that matches the content 1 or more times (EBNF plus).\n\nSemantics: the inner format must appear at least once.",
         "properties": {
            "type": {
               "const": "plus",
               "default": "plus",
               "title": "Type",
               "type": "string"
            },
            "content": {
               "discriminator": {
                  "mapping": {
                     "any_text": "#/$defs/AnyTextFormat",
                     "any_tokens": "#/$defs/AnyTokensFormat",
                     "const_string": "#/$defs/ConstStringFormat",
                     "dispatch": "#/$defs/DispatchFormat",
                     "exclude_token": "#/$defs/ExcludeTokenFormat",
                     "grammar": "#/$defs/GrammarFormat",
                     "json_schema": "#/$defs/JSONSchemaFormat",
                     "optional": "#/$defs/OptionalFormat",
                     "or": "#/$defs/OrFormat",
                     "plus": "#/$defs/PlusFormat",
                     "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                     "regex": "#/$defs/RegexFormat",
                     "repeat": "#/$defs/RepeatFormat",
                     "sequence": "#/$defs/SequenceFormat",
                     "star": "#/$defs/StarFormat",
                     "tag": "#/$defs/TagFormat",
                     "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                     "token": "#/$defs/TokenFormat",
                     "token_dispatch": "#/$defs/TokenDispatchFormat",
                     "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                     "triggered_tags": "#/$defs/TriggeredTagsFormat"
                  },
                  "propertyName": "type"
               },
               "oneOf": [
                  {
                     "$ref": "#/$defs/AnyTextFormat"
                  },
                  {
                     "$ref": "#/$defs/ConstStringFormat"
                  },
                  {
                     "$ref": "#/$defs/JSONSchemaFormat"
                  },
                  {
                     "$ref": "#/$defs/GrammarFormat"
                  },
                  {
                     "$ref": "#/$defs/RegexFormat"
                  },
                  {
                     "$ref": "#/$defs/QwenXMLParameterFormat"
                  },
                  {
                     "$ref": "#/$defs/OrFormat"
                  },
                  {
                     "$ref": "#/$defs/SequenceFormat"
                  },
                  {
                     "$ref": "#/$defs/TagFormat"
                  },
                  {
                     "$ref": "#/$defs/TriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenTriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TagsWithSeparatorFormat"
                  },
                  {
                     "$ref": "#/$defs/OptionalFormat"
                  },
                  {
                     "$ref": "#/$defs/PlusFormat"
                  },
                  {
                     "$ref": "#/$defs/StarFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  },
                  {
                     "$ref": "#/$defs/ExcludeTokenFormat"
                  },
                  {
                     "$ref": "#/$defs/AnyTokensFormat"
                  },
                  {
                     "$ref": "#/$defs/RepeatFormat"
                  },
                  {
                     "$ref": "#/$defs/DispatchFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenDispatchFormat"
                  }
               ],
               "title": "Content"
            }
         },
         "required": [
            "content"
         ],
         "title": "PlusFormat",
         "type": "object"
      },
      "QwenXMLParameterFormat": {
         "description": "Deprecated. Use :class:`JSONSchemaFormat` with ``style=\"qwen_xml\"`` instead.\n\nThis format remains available so existing serialized structural tags with\n``{\"type\": \"qwen_xml_parameter\"}`` can still be loaded.\n\nExamples\n--------\nUse the replacement format for new structural tags:\n\n.. code-block:: python\n\n    structural_tag = JSONSchemaFormat(\n        json_schema={\n            \"type\": \"object\",\n            \"properties\": {\"name\": {\"type\": \"string\"}, \"age\": {\"type\": \"integer\"}},\n            \"required\": [\"name\", \"age\"],\n        },\n        style=\"qwen_xml\",\n    )\n\nThe above structural tag can accept the following outputs::\n\n    <parameter=name>Bob</parameter><parameter=age>100</parameter>\n    <parameter=name>\"Bob&lt;\"</parameter><parameter=age>100</parameter>",
         "properties": {
            "type": {
               "const": "qwen_xml_parameter",
               "default": "qwen_xml_parameter",
               "title": "Type",
               "type": "string"
            },
            "json_schema": {
               "anyOf": [
                  {
                     "type": "boolean"
                  },
                  {
                     "additionalProperties": true,
                     "type": "object"
                  }
               ],
               "title": "Json Schema"
            }
         },
         "required": [
            "json_schema"
         ],
         "title": "QwenXMLParameterFormat",
         "type": "object"
      },
      "RegexFormat": {
         "description": "A format that matches a regex pattern.",
         "properties": {
            "type": {
               "const": "regex",
               "default": "regex",
               "title": "Type",
               "type": "string"
            },
            "pattern": {
               "title": "Pattern",
               "type": "string"
            }
         },
         "required": [
            "pattern"
         ],
         "title": "RegexFormat",
         "type": "object"
      },
      "RepeatFormat": {
         "description": "A format that matches the content between min and max times (inclusive).\n\nUse max=-1 for unbounded upper limit (e.g. \"at least min times\").",
         "properties": {
            "type": {
               "const": "repeat",
               "default": "repeat",
               "title": "Type",
               "type": "string"
            },
            "min": {
               "title": "Min",
               "type": "integer"
            },
            "max": {
               "title": "Max",
               "type": "integer"
            },
            "content": {
               "discriminator": {
                  "mapping": {
                     "any_text": "#/$defs/AnyTextFormat",
                     "any_tokens": "#/$defs/AnyTokensFormat",
                     "const_string": "#/$defs/ConstStringFormat",
                     "dispatch": "#/$defs/DispatchFormat",
                     "exclude_token": "#/$defs/ExcludeTokenFormat",
                     "grammar": "#/$defs/GrammarFormat",
                     "json_schema": "#/$defs/JSONSchemaFormat",
                     "optional": "#/$defs/OptionalFormat",
                     "or": "#/$defs/OrFormat",
                     "plus": "#/$defs/PlusFormat",
                     "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                     "regex": "#/$defs/RegexFormat",
                     "repeat": "#/$defs/RepeatFormat",
                     "sequence": "#/$defs/SequenceFormat",
                     "star": "#/$defs/StarFormat",
                     "tag": "#/$defs/TagFormat",
                     "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                     "token": "#/$defs/TokenFormat",
                     "token_dispatch": "#/$defs/TokenDispatchFormat",
                     "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                     "triggered_tags": "#/$defs/TriggeredTagsFormat"
                  },
                  "propertyName": "type"
               },
               "oneOf": [
                  {
                     "$ref": "#/$defs/AnyTextFormat"
                  },
                  {
                     "$ref": "#/$defs/ConstStringFormat"
                  },
                  {
                     "$ref": "#/$defs/JSONSchemaFormat"
                  },
                  {
                     "$ref": "#/$defs/GrammarFormat"
                  },
                  {
                     "$ref": "#/$defs/RegexFormat"
                  },
                  {
                     "$ref": "#/$defs/QwenXMLParameterFormat"
                  },
                  {
                     "$ref": "#/$defs/OrFormat"
                  },
                  {
                     "$ref": "#/$defs/SequenceFormat"
                  },
                  {
                     "$ref": "#/$defs/TagFormat"
                  },
                  {
                     "$ref": "#/$defs/TriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenTriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TagsWithSeparatorFormat"
                  },
                  {
                     "$ref": "#/$defs/OptionalFormat"
                  },
                  {
                     "$ref": "#/$defs/PlusFormat"
                  },
                  {
                     "$ref": "#/$defs/StarFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  },
                  {
                     "$ref": "#/$defs/ExcludeTokenFormat"
                  },
                  {
                     "$ref": "#/$defs/AnyTokensFormat"
                  },
                  {
                     "$ref": "#/$defs/RepeatFormat"
                  },
                  {
                     "$ref": "#/$defs/DispatchFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenDispatchFormat"
                  }
               ],
               "title": "Content"
            }
         },
         "required": [
            "min",
            "max",
            "content"
         ],
         "title": "RepeatFormat",
         "type": "object"
      },
      "SequenceFormat": {
         "description": "A format that matches a sequence of formats.",
         "properties": {
            "type": {
               "const": "sequence",
               "default": "sequence",
               "title": "Type",
               "type": "string"
            },
            "elements": {
               "items": {
                  "discriminator": {
                     "mapping": {
                        "any_text": "#/$defs/AnyTextFormat",
                        "any_tokens": "#/$defs/AnyTokensFormat",
                        "const_string": "#/$defs/ConstStringFormat",
                        "dispatch": "#/$defs/DispatchFormat",
                        "exclude_token": "#/$defs/ExcludeTokenFormat",
                        "grammar": "#/$defs/GrammarFormat",
                        "json_schema": "#/$defs/JSONSchemaFormat",
                        "optional": "#/$defs/OptionalFormat",
                        "or": "#/$defs/OrFormat",
                        "plus": "#/$defs/PlusFormat",
                        "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                        "regex": "#/$defs/RegexFormat",
                        "repeat": "#/$defs/RepeatFormat",
                        "sequence": "#/$defs/SequenceFormat",
                        "star": "#/$defs/StarFormat",
                        "tag": "#/$defs/TagFormat",
                        "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                        "token": "#/$defs/TokenFormat",
                        "token_dispatch": "#/$defs/TokenDispatchFormat",
                        "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                        "triggered_tags": "#/$defs/TriggeredTagsFormat"
                     },
                     "propertyName": "type"
                  },
                  "oneOf": [
                     {
                        "$ref": "#/$defs/AnyTextFormat"
                     },
                     {
                        "$ref": "#/$defs/ConstStringFormat"
                     },
                     {
                        "$ref": "#/$defs/JSONSchemaFormat"
                     },
                     {
                        "$ref": "#/$defs/GrammarFormat"
                     },
                     {
                        "$ref": "#/$defs/RegexFormat"
                     },
                     {
                        "$ref": "#/$defs/QwenXMLParameterFormat"
                     },
                     {
                        "$ref": "#/$defs/OrFormat"
                     },
                     {
                        "$ref": "#/$defs/SequenceFormat"
                     },
                     {
                        "$ref": "#/$defs/TagFormat"
                     },
                     {
                        "$ref": "#/$defs/TriggeredTagsFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenTriggeredTagsFormat"
                     },
                     {
                        "$ref": "#/$defs/TagsWithSeparatorFormat"
                     },
                     {
                        "$ref": "#/$defs/OptionalFormat"
                     },
                     {
                        "$ref": "#/$defs/PlusFormat"
                     },
                     {
                        "$ref": "#/$defs/StarFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenFormat"
                     },
                     {
                        "$ref": "#/$defs/ExcludeTokenFormat"
                     },
                     {
                        "$ref": "#/$defs/AnyTokensFormat"
                     },
                     {
                        "$ref": "#/$defs/RepeatFormat"
                     },
                     {
                        "$ref": "#/$defs/DispatchFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenDispatchFormat"
                     }
                  ]
               },
               "title": "Elements",
               "type": "array"
            }
         },
         "required": [
            "elements"
         ],
         "title": "SequenceFormat",
         "type": "object"
      },
      "StarFormat": {
         "description": "A format that matches the content 0 or more times (EBNF star).\n\nSemantics: the inner format may appear any number of times.",
         "properties": {
            "type": {
               "const": "star",
               "default": "star",
               "title": "Type",
               "type": "string"
            },
            "content": {
               "discriminator": {
                  "mapping": {
                     "any_text": "#/$defs/AnyTextFormat",
                     "any_tokens": "#/$defs/AnyTokensFormat",
                     "const_string": "#/$defs/ConstStringFormat",
                     "dispatch": "#/$defs/DispatchFormat",
                     "exclude_token": "#/$defs/ExcludeTokenFormat",
                     "grammar": "#/$defs/GrammarFormat",
                     "json_schema": "#/$defs/JSONSchemaFormat",
                     "optional": "#/$defs/OptionalFormat",
                     "or": "#/$defs/OrFormat",
                     "plus": "#/$defs/PlusFormat",
                     "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                     "regex": "#/$defs/RegexFormat",
                     "repeat": "#/$defs/RepeatFormat",
                     "sequence": "#/$defs/SequenceFormat",
                     "star": "#/$defs/StarFormat",
                     "tag": "#/$defs/TagFormat",
                     "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                     "token": "#/$defs/TokenFormat",
                     "token_dispatch": "#/$defs/TokenDispatchFormat",
                     "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                     "triggered_tags": "#/$defs/TriggeredTagsFormat"
                  },
                  "propertyName": "type"
               },
               "oneOf": [
                  {
                     "$ref": "#/$defs/AnyTextFormat"
                  },
                  {
                     "$ref": "#/$defs/ConstStringFormat"
                  },
                  {
                     "$ref": "#/$defs/JSONSchemaFormat"
                  },
                  {
                     "$ref": "#/$defs/GrammarFormat"
                  },
                  {
                     "$ref": "#/$defs/RegexFormat"
                  },
                  {
                     "$ref": "#/$defs/QwenXMLParameterFormat"
                  },
                  {
                     "$ref": "#/$defs/OrFormat"
                  },
                  {
                     "$ref": "#/$defs/SequenceFormat"
                  },
                  {
                     "$ref": "#/$defs/TagFormat"
                  },
                  {
                     "$ref": "#/$defs/TriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenTriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TagsWithSeparatorFormat"
                  },
                  {
                     "$ref": "#/$defs/OptionalFormat"
                  },
                  {
                     "$ref": "#/$defs/PlusFormat"
                  },
                  {
                     "$ref": "#/$defs/StarFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  },
                  {
                     "$ref": "#/$defs/ExcludeTokenFormat"
                  },
                  {
                     "$ref": "#/$defs/AnyTokensFormat"
                  },
                  {
                     "$ref": "#/$defs/RepeatFormat"
                  },
                  {
                     "$ref": "#/$defs/DispatchFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenDispatchFormat"
                  }
               ],
               "title": "Content"
            }
         },
         "required": [
            "content"
         ],
         "title": "StarFormat",
         "type": "object"
      },
      "TagFormat": {
         "description": "A format that matches a tag: ``begin content end``.\n\nThe ``end`` field can be a single string or a list of possible end strings.\nWhen multiple end strings are provided, any of them will be accepted as a valid\nending for the tag.\n\nExamples\n--------\n\nSingle end string:\n\n.. code-block:: python\n\n    TagFormat(begin=\"<response>\", content=..., end=\"</response>\")\n\nMultiple end strings:\n\n.. code-block:: python\n\n    TagFormat(begin=\"<response>\", content=..., end=[\"</response>\", \"</answer>\"])",
         "properties": {
            "type": {
               "const": "tag",
               "default": "tag",
               "title": "Type",
               "type": "string"
            },
            "begin": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  }
               ],
               "title": "Begin"
            },
            "content": {
               "discriminator": {
                  "mapping": {
                     "any_text": "#/$defs/AnyTextFormat",
                     "any_tokens": "#/$defs/AnyTokensFormat",
                     "const_string": "#/$defs/ConstStringFormat",
                     "dispatch": "#/$defs/DispatchFormat",
                     "exclude_token": "#/$defs/ExcludeTokenFormat",
                     "grammar": "#/$defs/GrammarFormat",
                     "json_schema": "#/$defs/JSONSchemaFormat",
                     "optional": "#/$defs/OptionalFormat",
                     "or": "#/$defs/OrFormat",
                     "plus": "#/$defs/PlusFormat",
                     "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                     "regex": "#/$defs/RegexFormat",
                     "repeat": "#/$defs/RepeatFormat",
                     "sequence": "#/$defs/SequenceFormat",
                     "star": "#/$defs/StarFormat",
                     "tag": "#/$defs/TagFormat",
                     "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                     "token": "#/$defs/TokenFormat",
                     "token_dispatch": "#/$defs/TokenDispatchFormat",
                     "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                     "triggered_tags": "#/$defs/TriggeredTagsFormat"
                  },
                  "propertyName": "type"
               },
               "oneOf": [
                  {
                     "$ref": "#/$defs/AnyTextFormat"
                  },
                  {
                     "$ref": "#/$defs/ConstStringFormat"
                  },
                  {
                     "$ref": "#/$defs/JSONSchemaFormat"
                  },
                  {
                     "$ref": "#/$defs/GrammarFormat"
                  },
                  {
                     "$ref": "#/$defs/RegexFormat"
                  },
                  {
                     "$ref": "#/$defs/QwenXMLParameterFormat"
                  },
                  {
                     "$ref": "#/$defs/OrFormat"
                  },
                  {
                     "$ref": "#/$defs/SequenceFormat"
                  },
                  {
                     "$ref": "#/$defs/TagFormat"
                  },
                  {
                     "$ref": "#/$defs/TriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenTriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TagsWithSeparatorFormat"
                  },
                  {
                     "$ref": "#/$defs/OptionalFormat"
                  },
                  {
                     "$ref": "#/$defs/PlusFormat"
                  },
                  {
                     "$ref": "#/$defs/StarFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  },
                  {
                     "$ref": "#/$defs/ExcludeTokenFormat"
                  },
                  {
                     "$ref": "#/$defs/AnyTokensFormat"
                  },
                  {
                     "$ref": "#/$defs/RepeatFormat"
                  },
                  {
                     "$ref": "#/$defs/DispatchFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenDispatchFormat"
                  }
               ],
               "title": "Content"
            },
            "end": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "items": {
                        "type": "string"
                     },
                     "type": "array"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  }
               ],
               "title": "End"
            }
         },
         "required": [
            "begin",
            "content",
            "end"
         ],
         "title": "TagFormat",
         "type": "object"
      },
      "TagsWithSeparatorFormat": {
         "description": "A format that matches a tags with separator. It can match zero, one, or more tags, separated\nby the separator, with no other text allowed.\n\nExamples\n--------\n\n.. code-block:: python\n\n    structural_tag = TagsWithSeparatorFormat(\n        tags=[\n            TagFormat(begin=\"<function=func1>\", content=JSONSchemaFormat(json_schema=...), end=\"</function>\"),\n            TagFormat(begin=\"<function=func2>\", content=JSONSchemaFormat(json_schema=...), end=\"</function>\"),\n        ],\n        separator=\",\",\n        at_least_one=False,\n        stop_after_first=False,\n    )\n\nThe above structural tag can accept an empty string, or the following outputs::\n\n    <function=func1>{\"name\": \"John\", \"age\": 30}</function>\n    <function=func1>{\"name\": \"John\", \"age\": 30}</function>,<function=func2>{\"name\": \"Jane\", \"age\": 25}</function>\n    <function=func1>{\"name\": \"John\", \"age\": 30}</function>,<function=func2>{\"name\": \"Jane\", \"age\": 25}</function>,<function=func1>{\"name\": \"John\", \"age\": 30}</function>",
         "properties": {
            "type": {
               "const": "tags_with_separator",
               "default": "tags_with_separator",
               "title": "Type",
               "type": "string"
            },
            "tags": {
               "items": {
                  "$ref": "#/$defs/TagFormat"
               },
               "title": "Tags",
               "type": "array"
            },
            "separator": {
               "title": "Separator",
               "type": "string"
            },
            "at_least_one": {
               "default": false,
               "title": "At Least One",
               "type": "boolean"
            },
            "stop_after_first": {
               "default": false,
               "title": "Stop After First",
               "type": "boolean"
            }
         },
         "required": [
            "tags",
            "separator"
         ],
         "title": "TagsWithSeparatorFormat",
         "type": "object"
      },
      "TokenDispatchFormat": {
         "description": "Matches certain patterns in free-form text.\nWhen certain tokens are generated, the following content must follow the corresponding format.\nCertain tokens can be excluded from being generated in the free-form part.\n\nThe user specifies a list of (pattern token, formats). The LLM can generate any free-form text, but\nwhen a pattern is matched in the text, the following output must follow the corresponding format.\nThe ``loop`` field controls whether the matching of this structure ends after accepting the first\npattern and format. If False, it ends. If true, the matching continues, and this format will\ncontinue to allow free-form text and detect the next pattern to be generated.\nThe ``excludes`` field controls the strings that cannot be generated in the free-form text.\nIt can also control the end of the format:\n``SequenceFormat(DispatchFormat(..., excludes=\"\"), ConstStringFormat(\"\"))``\nor\n``TagFormat(begin=..., content=DispatchFormat(..., excludes=\"\"), end=\"\")``\nends the matching of the format when LLM generates <end>.",
         "properties": {
            "type": {
               "const": "token_dispatch",
               "default": "token_dispatch",
               "title": "Type",
               "type": "string"
            },
            "rules": {
               "items": {
                  "maxItems": 2,
                  "minItems": 2,
                  "prefixItems": [
                     {
                        "anyOf": [
                           {
                              "type": "integer"
                           },
                           {
                              "type": "string"
                           }
                        ]
                     },
                     {
                        "discriminator": {
                           "mapping": {
                              "any_text": "#/$defs/AnyTextFormat",
                              "any_tokens": "#/$defs/AnyTokensFormat",
                              "const_string": "#/$defs/ConstStringFormat",
                              "dispatch": "#/$defs/DispatchFormat",
                              "exclude_token": "#/$defs/ExcludeTokenFormat",
                              "grammar": "#/$defs/GrammarFormat",
                              "json_schema": "#/$defs/JSONSchemaFormat",
                              "optional": "#/$defs/OptionalFormat",
                              "or": "#/$defs/OrFormat",
                              "plus": "#/$defs/PlusFormat",
                              "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                              "regex": "#/$defs/RegexFormat",
                              "repeat": "#/$defs/RepeatFormat",
                              "sequence": "#/$defs/SequenceFormat",
                              "star": "#/$defs/StarFormat",
                              "tag": "#/$defs/TagFormat",
                              "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                              "token": "#/$defs/TokenFormat",
                              "token_dispatch": "#/$defs/TokenDispatchFormat",
                              "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                              "triggered_tags": "#/$defs/TriggeredTagsFormat"
                           },
                           "propertyName": "type"
                        },
                        "oneOf": [
                           {
                              "$ref": "#/$defs/AnyTextFormat"
                           },
                           {
                              "$ref": "#/$defs/ConstStringFormat"
                           },
                           {
                              "$ref": "#/$defs/JSONSchemaFormat"
                           },
                           {
                              "$ref": "#/$defs/GrammarFormat"
                           },
                           {
                              "$ref": "#/$defs/RegexFormat"
                           },
                           {
                              "$ref": "#/$defs/QwenXMLParameterFormat"
                           },
                           {
                              "$ref": "#/$defs/OrFormat"
                           },
                           {
                              "$ref": "#/$defs/SequenceFormat"
                           },
                           {
                              "$ref": "#/$defs/TagFormat"
                           },
                           {
                              "$ref": "#/$defs/TriggeredTagsFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenTriggeredTagsFormat"
                           },
                           {
                              "$ref": "#/$defs/TagsWithSeparatorFormat"
                           },
                           {
                              "$ref": "#/$defs/OptionalFormat"
                           },
                           {
                              "$ref": "#/$defs/PlusFormat"
                           },
                           {
                              "$ref": "#/$defs/StarFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenFormat"
                           },
                           {
                              "$ref": "#/$defs/ExcludeTokenFormat"
                           },
                           {
                              "$ref": "#/$defs/AnyTokensFormat"
                           },
                           {
                              "$ref": "#/$defs/RepeatFormat"
                           },
                           {
                              "$ref": "#/$defs/DispatchFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenDispatchFormat"
                           }
                        ]
                     }
                  ],
                  "type": "array"
               },
               "title": "Rules",
               "type": "array"
            },
            "loop": {
               "default": true,
               "title": "Loop",
               "type": "boolean"
            },
            "exclude_tokens": {
               "default": [],
               "items": {
                  "anyOf": [
                     {
                        "type": "integer"
                     },
                     {
                        "type": "string"
                     }
                  ]
               },
               "title": "Exclude Tokens",
               "type": "array"
            }
         },
         "required": [
            "rules"
         ],
         "title": "TokenDispatchFormat",
         "type": "object"
      },
      "TokenFormat": {
         "description": "A format that matches a single token by ID or string representation.",
         "properties": {
            "type": {
               "const": "token",
               "default": "token",
               "title": "Type",
               "type": "string"
            },
            "token": {
               "anyOf": [
                  {
                     "type": "integer"
                  },
                  {
                     "type": "string"
                  }
               ],
               "title": "Token"
            }
         },
         "required": [
            "token"
         ],
         "title": "TokenFormat",
         "type": "object"
      },
      "TokenTriggeredTagsFormat": {
         "description": "A format that dispatches to tags based on token-level triggers.\n\nSimilar to TriggeredTagsFormat but uses token IDs instead of string triggers.\nTags must use ``TokenFormat`` ``begin`` fields, not strings.\nFor string-level dispatch, use ``TriggeredTagsFormat`` instead.",
         "properties": {
            "type": {
               "const": "token_triggered_tags",
               "default": "token_triggered_tags",
               "title": "Type",
               "type": "string"
            },
            "trigger_tokens": {
               "items": {
                  "anyOf": [
                     {
                        "type": "integer"
                     },
                     {
                        "type": "string"
                     }
                  ]
               },
               "title": "Trigger Tokens",
               "type": "array"
            },
            "tags": {
               "items": {
                  "$ref": "#/$defs/TagFormat"
               },
               "title": "Tags",
               "type": "array"
            },
            "exclude_tokens": {
               "default": [],
               "items": {
                  "anyOf": [
                     {
                        "type": "integer"
                     },
                     {
                        "type": "string"
                     }
                  ]
               },
               "title": "Exclude Tokens",
               "type": "array"
            },
            "at_least_one": {
               "default": false,
               "title": "At Least One",
               "type": "boolean"
            },
            "stop_after_first": {
               "default": false,
               "title": "Stop After First",
               "type": "boolean"
            }
         },
         "required": [
            "trigger_tokens",
            "tags"
         ],
         "title": "TokenTriggeredTagsFormat",
         "type": "object"
      },
      "TriggeredTagsFormat": {
         "description": "A format that matches triggered tags. It can allow any output until a trigger is\nencountered, then dispatch to the corresponding tag; when the end tag is encountered, the\ngrammar will allow any following output, until the next trigger is encountered.\n\nEach tag should be matched by exactly one trigger. \"matching\" means the trigger should be a\nprefix of the begin tag.\n\nTags must use **string** ``begin`` fields, not ``TokenFormat``.\nFor token-level dispatch, use ``TokenTriggeredTagsFormat`` instead.\n\nExamples\n--------\n\n.. code-block:: python\n\n    structural_tag = TriggeredTagsFormat(\n        triggers=[\"<function=\"],\n        tags=[\n            TagFormat(\n                begin=\"<function=func1>\",\n                content=JSONSchemaFormat(json_schema=...),\n                end=\"</function>\",\n            ),\n            TagFormat(\n                begin=\"<function=func2>\",\n                content=JSONSchemaFormat(json_schema=...),\n                end=\"</function>\",\n            ),\n        ],\n        at_least_one=False,\n        stop_after_first=False,\n    )\n\nThe above structural tag can accept the following outputs::\n\n    <function=func1>{\"name\": \"John\", \"age\": 30}</function>\n    <function=func2>{\"name\": \"Jane\", \"age\": 25}</function>\n    any_text<function=func1>{\"name\": \"John\", \"age\": 30}</function>any_text1<function=func2>{\"name\": \"Jane\", \"age\": 25}</function>any_text2",
         "properties": {
            "type": {
               "const": "triggered_tags",
               "default": "triggered_tags",
               "title": "Type",
               "type": "string"
            },
            "triggers": {
               "items": {
                  "type": "string"
               },
               "title": "Triggers",
               "type": "array"
            },
            "tags": {
               "items": {
                  "$ref": "#/$defs/TagFormat"
               },
               "title": "Tags",
               "type": "array"
            },
            "at_least_one": {
               "default": false,
               "title": "At Least One",
               "type": "boolean"
            },
            "stop_after_first": {
               "default": false,
               "title": "Stop After First",
               "type": "boolean"
            },
            "excludes": {
               "default": [],
               "items": {
                  "type": "string"
               },
               "title": "Excludes",
               "type": "array"
            }
         },
         "required": [
            "triggers",
            "tags"
         ],
         "title": "TriggeredTagsFormat",
         "type": "object"
      }
   },
   "$ref": "#/$defs/TriggeredTagsFormat"
}

field type: Literal['triggered_tags'] = 'triggered_tags'

The type of the format.

field triggers: List[str] [Required]

The triggers of the triggered tags.

field tags: List[TagFormat] [Required]

The tags of the triggered tags.

field at_least_one: bool = False

Whether at least one of the tags must be generated.

field stop_after_first: bool = False

Whether to stop after the first tag is generated.

field excludes: List[str] = []

List of strings that should not appear in the matched text.

pydantic model xgrammar.structural_tag.TagsWithSeparatorFormat[source]

Bases: BaseModel

A format that matches a tags with separator. It can match zero, one, or more tags, separated by the separator, with no other text allowed.

Examples

structural_tag = TagsWithSeparatorFormat(
    tags=[
        TagFormat(begin="<function=func1>", content=JSONSchemaFormat(json_schema=...), end="</function>"),
        TagFormat(begin="<function=func2>", content=JSONSchemaFormat(json_schema=...), end="</function>"),
    ],
    separator=",",
    at_least_one=False,
    stop_after_first=False,
)

The above structural tag can accept an empty string, or the following outputs:

<function=func1>{"name": "John", "age": 30}</function>
<function=func1>{"name": "John", "age": 30}</function>,<function=func2>{"name": "Jane", "age": 25}</function>
<function=func1>{"name": "John", "age": 30}</function>,<function=func2>{"name": "Jane", "age": 25}</function>,<function=func1>{"name": "John", "age": 30}</function>

Show JSON schema
{
   "$defs": {
      "AnyTextFormat": {
         "description": "A format that matches any text.",
         "properties": {
            "type": {
               "const": "any_text",
               "default": "any_text",
               "title": "Type",
               "type": "string"
            },
            "excludes": {
               "default": [],
               "items": {
                  "type": "string"
               },
               "title": "Excludes",
               "type": "array"
            }
         },
         "title": "AnyTextFormat",
         "type": "object"
      },
      "AnyTokensFormat": {
         "description": "A format that matches zero or more tokens, excluding those in the given set.",
         "properties": {
            "type": {
               "const": "any_tokens",
               "default": "any_tokens",
               "title": "Type",
               "type": "string"
            },
            "exclude_tokens": {
               "default": [],
               "items": {
                  "anyOf": [
                     {
                        "type": "integer"
                     },
                     {
                        "type": "string"
                     }
                  ]
               },
               "title": "Exclude Tokens",
               "type": "array"
            }
         },
         "title": "AnyTokensFormat",
         "type": "object"
      },
      "ConstStringFormat": {
         "description": "A format that matches a constant string.",
         "properties": {
            "type": {
               "const": "const_string",
               "default": "const_string",
               "title": "Type",
               "type": "string"
            },
            "value": {
               "title": "Value",
               "type": "string"
            }
         },
         "required": [
            "value"
         ],
         "title": "ConstStringFormat",
         "type": "object"
      },
      "DispatchFormat": {
         "description": "Matches certain patterns in free-form text.\nWhen certain strings are generated, the following content must follow the corresponding format.\nCertain strings can be excluded from being generated in the free-form part.\n\nThe user specifies a list of (pattern, formats). The LLM can generate any free-form text, but\nwhen a pattern is matched in the text, the following output must follow the corresponding format.\nThe ``loop`` field controls whether the matching of this structure ends after accepting the first\npattern and format. If False, it ends. If true, the matching continues, and this format will\ncontinue to allow free-form text and detect the next pattern to be generated.\nThe ``excludes`` field controls the strings that cannot be generated in the free-form text.\nIt can also control the end of the format:\n``SequenceFormat(DispatchFormat(..., excludes=\"\"), ConstStringFormat(\"\"))``\nor\n``TagFormat(begin=..., content=DispatchFormat(..., excludes=\"\"), end=\"\")``\nends the matching of the format when LLM generates <end>.",
         "properties": {
            "type": {
               "const": "dispatch",
               "default": "dispatch",
               "title": "Type",
               "type": "string"
            },
            "rules": {
               "items": {
                  "maxItems": 2,
                  "minItems": 2,
                  "prefixItems": [
                     {
                        "type": "string"
                     },
                     {
                        "discriminator": {
                           "mapping": {
                              "any_text": "#/$defs/AnyTextFormat",
                              "any_tokens": "#/$defs/AnyTokensFormat",
                              "const_string": "#/$defs/ConstStringFormat",
                              "dispatch": "#/$defs/DispatchFormat",
                              "exclude_token": "#/$defs/ExcludeTokenFormat",
                              "grammar": "#/$defs/GrammarFormat",
                              "json_schema": "#/$defs/JSONSchemaFormat",
                              "optional": "#/$defs/OptionalFormat",
                              "or": "#/$defs/OrFormat",
                              "plus": "#/$defs/PlusFormat",
                              "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                              "regex": "#/$defs/RegexFormat",
                              "repeat": "#/$defs/RepeatFormat",
                              "sequence": "#/$defs/SequenceFormat",
                              "star": "#/$defs/StarFormat",
                              "tag": "#/$defs/TagFormat",
                              "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                              "token": "#/$defs/TokenFormat",
                              "token_dispatch": "#/$defs/TokenDispatchFormat",
                              "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                              "triggered_tags": "#/$defs/TriggeredTagsFormat"
                           },
                           "propertyName": "type"
                        },
                        "oneOf": [
                           {
                              "$ref": "#/$defs/AnyTextFormat"
                           },
                           {
                              "$ref": "#/$defs/ConstStringFormat"
                           },
                           {
                              "$ref": "#/$defs/JSONSchemaFormat"
                           },
                           {
                              "$ref": "#/$defs/GrammarFormat"
                           },
                           {
                              "$ref": "#/$defs/RegexFormat"
                           },
                           {
                              "$ref": "#/$defs/QwenXMLParameterFormat"
                           },
                           {
                              "$ref": "#/$defs/OrFormat"
                           },
                           {
                              "$ref": "#/$defs/SequenceFormat"
                           },
                           {
                              "$ref": "#/$defs/TagFormat"
                           },
                           {
                              "$ref": "#/$defs/TriggeredTagsFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenTriggeredTagsFormat"
                           },
                           {
                              "$ref": "#/$defs/TagsWithSeparatorFormat"
                           },
                           {
                              "$ref": "#/$defs/OptionalFormat"
                           },
                           {
                              "$ref": "#/$defs/PlusFormat"
                           },
                           {
                              "$ref": "#/$defs/StarFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenFormat"
                           },
                           {
                              "$ref": "#/$defs/ExcludeTokenFormat"
                           },
                           {
                              "$ref": "#/$defs/AnyTokensFormat"
                           },
                           {
                              "$ref": "#/$defs/RepeatFormat"
                           },
                           {
                              "$ref": "#/$defs/DispatchFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenDispatchFormat"
                           }
                        ]
                     }
                  ],
                  "type": "array"
               },
               "title": "Rules",
               "type": "array"
            },
            "loop": {
               "default": true,
               "title": "Loop",
               "type": "boolean"
            },
            "excludes": {
               "default": [],
               "items": {
                  "type": "string"
               },
               "title": "Excludes",
               "type": "array"
            }
         },
         "required": [
            "rules"
         ],
         "title": "DispatchFormat",
         "type": "object"
      },
      "ExcludeTokenFormat": {
         "description": "A format that matches a single token, excluding those in the given set.",
         "properties": {
            "type": {
               "const": "exclude_token",
               "default": "exclude_token",
               "title": "Type",
               "type": "string"
            },
            "exclude_tokens": {
               "default": [],
               "items": {
                  "anyOf": [
                     {
                        "type": "integer"
                     },
                     {
                        "type": "string"
                     }
                  ]
               },
               "title": "Exclude Tokens",
               "type": "array"
            }
         },
         "title": "ExcludeTokenFormat",
         "type": "object"
      },
      "GrammarFormat": {
         "description": "A format that matches an ebnf grammar.",
         "properties": {
            "type": {
               "const": "grammar",
               "default": "grammar",
               "title": "Type",
               "type": "string"
            },
            "grammar": {
               "title": "Grammar",
               "type": "string"
            }
         },
         "required": [
            "grammar"
         ],
         "title": "GrammarFormat",
         "type": "object"
      },
      "JSONSchemaFormat": {
         "description": "A format that matches a JSON schema.",
         "properties": {
            "type": {
               "const": "json_schema",
               "default": "json_schema",
               "title": "Type",
               "type": "string"
            },
            "json_schema": {
               "anyOf": [
                  {
                     "type": "boolean"
                  },
                  {
                     "additionalProperties": true,
                     "type": "object"
                  }
               ],
               "title": "Json Schema"
            },
            "style": {
               "default": "json",
               "enum": [
                  "json",
                  "qwen_xml",
                  "minimax_xml",
                  "deepseek_xml",
                  "glm_xml"
               ],
               "title": "Style",
               "type": "string"
            }
         },
         "required": [
            "json_schema"
         ],
         "title": "JSONSchemaFormat",
         "type": "object"
      },
      "OptionalFormat": {
         "description": "A format that matches the content 0 or 1 time (EBNF optional).\n\nSemantics: the inner format may appear once or not at all.",
         "properties": {
            "type": {
               "const": "optional",
               "default": "optional",
               "title": "Type",
               "type": "string"
            },
            "content": {
               "discriminator": {
                  "mapping": {
                     "any_text": "#/$defs/AnyTextFormat",
                     "any_tokens": "#/$defs/AnyTokensFormat",
                     "const_string": "#/$defs/ConstStringFormat",
                     "dispatch": "#/$defs/DispatchFormat",
                     "exclude_token": "#/$defs/ExcludeTokenFormat",
                     "grammar": "#/$defs/GrammarFormat",
                     "json_schema": "#/$defs/JSONSchemaFormat",
                     "optional": "#/$defs/OptionalFormat",
                     "or": "#/$defs/OrFormat",
                     "plus": "#/$defs/PlusFormat",
                     "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                     "regex": "#/$defs/RegexFormat",
                     "repeat": "#/$defs/RepeatFormat",
                     "sequence": "#/$defs/SequenceFormat",
                     "star": "#/$defs/StarFormat",
                     "tag": "#/$defs/TagFormat",
                     "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                     "token": "#/$defs/TokenFormat",
                     "token_dispatch": "#/$defs/TokenDispatchFormat",
                     "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                     "triggered_tags": "#/$defs/TriggeredTagsFormat"
                  },
                  "propertyName": "type"
               },
               "oneOf": [
                  {
                     "$ref": "#/$defs/AnyTextFormat"
                  },
                  {
                     "$ref": "#/$defs/ConstStringFormat"
                  },
                  {
                     "$ref": "#/$defs/JSONSchemaFormat"
                  },
                  {
                     "$ref": "#/$defs/GrammarFormat"
                  },
                  {
                     "$ref": "#/$defs/RegexFormat"
                  },
                  {
                     "$ref": "#/$defs/QwenXMLParameterFormat"
                  },
                  {
                     "$ref": "#/$defs/OrFormat"
                  },
                  {
                     "$ref": "#/$defs/SequenceFormat"
                  },
                  {
                     "$ref": "#/$defs/TagFormat"
                  },
                  {
                     "$ref": "#/$defs/TriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenTriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TagsWithSeparatorFormat"
                  },
                  {
                     "$ref": "#/$defs/OptionalFormat"
                  },
                  {
                     "$ref": "#/$defs/PlusFormat"
                  },
                  {
                     "$ref": "#/$defs/StarFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  },
                  {
                     "$ref": "#/$defs/ExcludeTokenFormat"
                  },
                  {
                     "$ref": "#/$defs/AnyTokensFormat"
                  },
                  {
                     "$ref": "#/$defs/RepeatFormat"
                  },
                  {
                     "$ref": "#/$defs/DispatchFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenDispatchFormat"
                  }
               ],
               "title": "Content"
            }
         },
         "required": [
            "content"
         ],
         "title": "OptionalFormat",
         "type": "object"
      },
      "OrFormat": {
         "description": "A format that matches one of the formats.",
         "properties": {
            "type": {
               "const": "or",
               "default": "or",
               "title": "Type",
               "type": "string"
            },
            "elements": {
               "items": {
                  "discriminator": {
                     "mapping": {
                        "any_text": "#/$defs/AnyTextFormat",
                        "any_tokens": "#/$defs/AnyTokensFormat",
                        "const_string": "#/$defs/ConstStringFormat",
                        "dispatch": "#/$defs/DispatchFormat",
                        "exclude_token": "#/$defs/ExcludeTokenFormat",
                        "grammar": "#/$defs/GrammarFormat",
                        "json_schema": "#/$defs/JSONSchemaFormat",
                        "optional": "#/$defs/OptionalFormat",
                        "or": "#/$defs/OrFormat",
                        "plus": "#/$defs/PlusFormat",
                        "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                        "regex": "#/$defs/RegexFormat",
                        "repeat": "#/$defs/RepeatFormat",
                        "sequence": "#/$defs/SequenceFormat",
                        "star": "#/$defs/StarFormat",
                        "tag": "#/$defs/TagFormat",
                        "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                        "token": "#/$defs/TokenFormat",
                        "token_dispatch": "#/$defs/TokenDispatchFormat",
                        "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                        "triggered_tags": "#/$defs/TriggeredTagsFormat"
                     },
                     "propertyName": "type"
                  },
                  "oneOf": [
                     {
                        "$ref": "#/$defs/AnyTextFormat"
                     },
                     {
                        "$ref": "#/$defs/ConstStringFormat"
                     },
                     {
                        "$ref": "#/$defs/JSONSchemaFormat"
                     },
                     {
                        "$ref": "#/$defs/GrammarFormat"
                     },
                     {
                        "$ref": "#/$defs/RegexFormat"
                     },
                     {
                        "$ref": "#/$defs/QwenXMLParameterFormat"
                     },
                     {
                        "$ref": "#/$defs/OrFormat"
                     },
                     {
                        "$ref": "#/$defs/SequenceFormat"
                     },
                     {
                        "$ref": "#/$defs/TagFormat"
                     },
                     {
                        "$ref": "#/$defs/TriggeredTagsFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenTriggeredTagsFormat"
                     },
                     {
                        "$ref": "#/$defs/TagsWithSeparatorFormat"
                     },
                     {
                        "$ref": "#/$defs/OptionalFormat"
                     },
                     {
                        "$ref": "#/$defs/PlusFormat"
                     },
                     {
                        "$ref": "#/$defs/StarFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenFormat"
                     },
                     {
                        "$ref": "#/$defs/ExcludeTokenFormat"
                     },
                     {
                        "$ref": "#/$defs/AnyTokensFormat"
                     },
                     {
                        "$ref": "#/$defs/RepeatFormat"
                     },
                     {
                        "$ref": "#/$defs/DispatchFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenDispatchFormat"
                     }
                  ]
               },
               "title": "Elements",
               "type": "array"
            }
         },
         "required": [
            "elements"
         ],
         "title": "OrFormat",
         "type": "object"
      },
      "PlusFormat": {
         "description": "A format that matches the content 1 or more times (EBNF plus).\n\nSemantics: the inner format must appear at least once.",
         "properties": {
            "type": {
               "const": "plus",
               "default": "plus",
               "title": "Type",
               "type": "string"
            },
            "content": {
               "discriminator": {
                  "mapping": {
                     "any_text": "#/$defs/AnyTextFormat",
                     "any_tokens": "#/$defs/AnyTokensFormat",
                     "const_string": "#/$defs/ConstStringFormat",
                     "dispatch": "#/$defs/DispatchFormat",
                     "exclude_token": "#/$defs/ExcludeTokenFormat",
                     "grammar": "#/$defs/GrammarFormat",
                     "json_schema": "#/$defs/JSONSchemaFormat",
                     "optional": "#/$defs/OptionalFormat",
                     "or": "#/$defs/OrFormat",
                     "plus": "#/$defs/PlusFormat",
                     "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                     "regex": "#/$defs/RegexFormat",
                     "repeat": "#/$defs/RepeatFormat",
                     "sequence": "#/$defs/SequenceFormat",
                     "star": "#/$defs/StarFormat",
                     "tag": "#/$defs/TagFormat",
                     "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                     "token": "#/$defs/TokenFormat",
                     "token_dispatch": "#/$defs/TokenDispatchFormat",
                     "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                     "triggered_tags": "#/$defs/TriggeredTagsFormat"
                  },
                  "propertyName": "type"
               },
               "oneOf": [
                  {
                     "$ref": "#/$defs/AnyTextFormat"
                  },
                  {
                     "$ref": "#/$defs/ConstStringFormat"
                  },
                  {
                     "$ref": "#/$defs/JSONSchemaFormat"
                  },
                  {
                     "$ref": "#/$defs/GrammarFormat"
                  },
                  {
                     "$ref": "#/$defs/RegexFormat"
                  },
                  {
                     "$ref": "#/$defs/QwenXMLParameterFormat"
                  },
                  {
                     "$ref": "#/$defs/OrFormat"
                  },
                  {
                     "$ref": "#/$defs/SequenceFormat"
                  },
                  {
                     "$ref": "#/$defs/TagFormat"
                  },
                  {
                     "$ref": "#/$defs/TriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenTriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TagsWithSeparatorFormat"
                  },
                  {
                     "$ref": "#/$defs/OptionalFormat"
                  },
                  {
                     "$ref": "#/$defs/PlusFormat"
                  },
                  {
                     "$ref": "#/$defs/StarFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  },
                  {
                     "$ref": "#/$defs/ExcludeTokenFormat"
                  },
                  {
                     "$ref": "#/$defs/AnyTokensFormat"
                  },
                  {
                     "$ref": "#/$defs/RepeatFormat"
                  },
                  {
                     "$ref": "#/$defs/DispatchFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenDispatchFormat"
                  }
               ],
               "title": "Content"
            }
         },
         "required": [
            "content"
         ],
         "title": "PlusFormat",
         "type": "object"
      },
      "QwenXMLParameterFormat": {
         "description": "Deprecated. Use :class:`JSONSchemaFormat` with ``style=\"qwen_xml\"`` instead.\n\nThis format remains available so existing serialized structural tags with\n``{\"type\": \"qwen_xml_parameter\"}`` can still be loaded.\n\nExamples\n--------\nUse the replacement format for new structural tags:\n\n.. code-block:: python\n\n    structural_tag = JSONSchemaFormat(\n        json_schema={\n            \"type\": \"object\",\n            \"properties\": {\"name\": {\"type\": \"string\"}, \"age\": {\"type\": \"integer\"}},\n            \"required\": [\"name\", \"age\"],\n        },\n        style=\"qwen_xml\",\n    )\n\nThe above structural tag can accept the following outputs::\n\n    <parameter=name>Bob</parameter><parameter=age>100</parameter>\n    <parameter=name>\"Bob&lt;\"</parameter><parameter=age>100</parameter>",
         "properties": {
            "type": {
               "const": "qwen_xml_parameter",
               "default": "qwen_xml_parameter",
               "title": "Type",
               "type": "string"
            },
            "json_schema": {
               "anyOf": [
                  {
                     "type": "boolean"
                  },
                  {
                     "additionalProperties": true,
                     "type": "object"
                  }
               ],
               "title": "Json Schema"
            }
         },
         "required": [
            "json_schema"
         ],
         "title": "QwenXMLParameterFormat",
         "type": "object"
      },
      "RegexFormat": {
         "description": "A format that matches a regex pattern.",
         "properties": {
            "type": {
               "const": "regex",
               "default": "regex",
               "title": "Type",
               "type": "string"
            },
            "pattern": {
               "title": "Pattern",
               "type": "string"
            }
         },
         "required": [
            "pattern"
         ],
         "title": "RegexFormat",
         "type": "object"
      },
      "RepeatFormat": {
         "description": "A format that matches the content between min and max times (inclusive).\n\nUse max=-1 for unbounded upper limit (e.g. \"at least min times\").",
         "properties": {
            "type": {
               "const": "repeat",
               "default": "repeat",
               "title": "Type",
               "type": "string"
            },
            "min": {
               "title": "Min",
               "type": "integer"
            },
            "max": {
               "title": "Max",
               "type": "integer"
            },
            "content": {
               "discriminator": {
                  "mapping": {
                     "any_text": "#/$defs/AnyTextFormat",
                     "any_tokens": "#/$defs/AnyTokensFormat",
                     "const_string": "#/$defs/ConstStringFormat",
                     "dispatch": "#/$defs/DispatchFormat",
                     "exclude_token": "#/$defs/ExcludeTokenFormat",
                     "grammar": "#/$defs/GrammarFormat",
                     "json_schema": "#/$defs/JSONSchemaFormat",
                     "optional": "#/$defs/OptionalFormat",
                     "or": "#/$defs/OrFormat",
                     "plus": "#/$defs/PlusFormat",
                     "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                     "regex": "#/$defs/RegexFormat",
                     "repeat": "#/$defs/RepeatFormat",
                     "sequence": "#/$defs/SequenceFormat",
                     "star": "#/$defs/StarFormat",
                     "tag": "#/$defs/TagFormat",
                     "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                     "token": "#/$defs/TokenFormat",
                     "token_dispatch": "#/$defs/TokenDispatchFormat",
                     "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                     "triggered_tags": "#/$defs/TriggeredTagsFormat"
                  },
                  "propertyName": "type"
               },
               "oneOf": [
                  {
                     "$ref": "#/$defs/AnyTextFormat"
                  },
                  {
                     "$ref": "#/$defs/ConstStringFormat"
                  },
                  {
                     "$ref": "#/$defs/JSONSchemaFormat"
                  },
                  {
                     "$ref": "#/$defs/GrammarFormat"
                  },
                  {
                     "$ref": "#/$defs/RegexFormat"
                  },
                  {
                     "$ref": "#/$defs/QwenXMLParameterFormat"
                  },
                  {
                     "$ref": "#/$defs/OrFormat"
                  },
                  {
                     "$ref": "#/$defs/SequenceFormat"
                  },
                  {
                     "$ref": "#/$defs/TagFormat"
                  },
                  {
                     "$ref": "#/$defs/TriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenTriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TagsWithSeparatorFormat"
                  },
                  {
                     "$ref": "#/$defs/OptionalFormat"
                  },
                  {
                     "$ref": "#/$defs/PlusFormat"
                  },
                  {
                     "$ref": "#/$defs/StarFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  },
                  {
                     "$ref": "#/$defs/ExcludeTokenFormat"
                  },
                  {
                     "$ref": "#/$defs/AnyTokensFormat"
                  },
                  {
                     "$ref": "#/$defs/RepeatFormat"
                  },
                  {
                     "$ref": "#/$defs/DispatchFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenDispatchFormat"
                  }
               ],
               "title": "Content"
            }
         },
         "required": [
            "min",
            "max",
            "content"
         ],
         "title": "RepeatFormat",
         "type": "object"
      },
      "SequenceFormat": {
         "description": "A format that matches a sequence of formats.",
         "properties": {
            "type": {
               "const": "sequence",
               "default": "sequence",
               "title": "Type",
               "type": "string"
            },
            "elements": {
               "items": {
                  "discriminator": {
                     "mapping": {
                        "any_text": "#/$defs/AnyTextFormat",
                        "any_tokens": "#/$defs/AnyTokensFormat",
                        "const_string": "#/$defs/ConstStringFormat",
                        "dispatch": "#/$defs/DispatchFormat",
                        "exclude_token": "#/$defs/ExcludeTokenFormat",
                        "grammar": "#/$defs/GrammarFormat",
                        "json_schema": "#/$defs/JSONSchemaFormat",
                        "optional": "#/$defs/OptionalFormat",
                        "or": "#/$defs/OrFormat",
                        "plus": "#/$defs/PlusFormat",
                        "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                        "regex": "#/$defs/RegexFormat",
                        "repeat": "#/$defs/RepeatFormat",
                        "sequence": "#/$defs/SequenceFormat",
                        "star": "#/$defs/StarFormat",
                        "tag": "#/$defs/TagFormat",
                        "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                        "token": "#/$defs/TokenFormat",
                        "token_dispatch": "#/$defs/TokenDispatchFormat",
                        "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                        "triggered_tags": "#/$defs/TriggeredTagsFormat"
                     },
                     "propertyName": "type"
                  },
                  "oneOf": [
                     {
                        "$ref": "#/$defs/AnyTextFormat"
                     },
                     {
                        "$ref": "#/$defs/ConstStringFormat"
                     },
                     {
                        "$ref": "#/$defs/JSONSchemaFormat"
                     },
                     {
                        "$ref": "#/$defs/GrammarFormat"
                     },
                     {
                        "$ref": "#/$defs/RegexFormat"
                     },
                     {
                        "$ref": "#/$defs/QwenXMLParameterFormat"
                     },
                     {
                        "$ref": "#/$defs/OrFormat"
                     },
                     {
                        "$ref": "#/$defs/SequenceFormat"
                     },
                     {
                        "$ref": "#/$defs/TagFormat"
                     },
                     {
                        "$ref": "#/$defs/TriggeredTagsFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenTriggeredTagsFormat"
                     },
                     {
                        "$ref": "#/$defs/TagsWithSeparatorFormat"
                     },
                     {
                        "$ref": "#/$defs/OptionalFormat"
                     },
                     {
                        "$ref": "#/$defs/PlusFormat"
                     },
                     {
                        "$ref": "#/$defs/StarFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenFormat"
                     },
                     {
                        "$ref": "#/$defs/ExcludeTokenFormat"
                     },
                     {
                        "$ref": "#/$defs/AnyTokensFormat"
                     },
                     {
                        "$ref": "#/$defs/RepeatFormat"
                     },
                     {
                        "$ref": "#/$defs/DispatchFormat"
                     },
                     {
                        "$ref": "#/$defs/TokenDispatchFormat"
                     }
                  ]
               },
               "title": "Elements",
               "type": "array"
            }
         },
         "required": [
            "elements"
         ],
         "title": "SequenceFormat",
         "type": "object"
      },
      "StarFormat": {
         "description": "A format that matches the content 0 or more times (EBNF star).\n\nSemantics: the inner format may appear any number of times.",
         "properties": {
            "type": {
               "const": "star",
               "default": "star",
               "title": "Type",
               "type": "string"
            },
            "content": {
               "discriminator": {
                  "mapping": {
                     "any_text": "#/$defs/AnyTextFormat",
                     "any_tokens": "#/$defs/AnyTokensFormat",
                     "const_string": "#/$defs/ConstStringFormat",
                     "dispatch": "#/$defs/DispatchFormat",
                     "exclude_token": "#/$defs/ExcludeTokenFormat",
                     "grammar": "#/$defs/GrammarFormat",
                     "json_schema": "#/$defs/JSONSchemaFormat",
                     "optional": "#/$defs/OptionalFormat",
                     "or": "#/$defs/OrFormat",
                     "plus": "#/$defs/PlusFormat",
                     "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                     "regex": "#/$defs/RegexFormat",
                     "repeat": "#/$defs/RepeatFormat",
                     "sequence": "#/$defs/SequenceFormat",
                     "star": "#/$defs/StarFormat",
                     "tag": "#/$defs/TagFormat",
                     "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                     "token": "#/$defs/TokenFormat",
                     "token_dispatch": "#/$defs/TokenDispatchFormat",
                     "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                     "triggered_tags": "#/$defs/TriggeredTagsFormat"
                  },
                  "propertyName": "type"
               },
               "oneOf": [
                  {
                     "$ref": "#/$defs/AnyTextFormat"
                  },
                  {
                     "$ref": "#/$defs/ConstStringFormat"
                  },
                  {
                     "$ref": "#/$defs/JSONSchemaFormat"
                  },
                  {
                     "$ref": "#/$defs/GrammarFormat"
                  },
                  {
                     "$ref": "#/$defs/RegexFormat"
                  },
                  {
                     "$ref": "#/$defs/QwenXMLParameterFormat"
                  },
                  {
                     "$ref": "#/$defs/OrFormat"
                  },
                  {
                     "$ref": "#/$defs/SequenceFormat"
                  },
                  {
                     "$ref": "#/$defs/TagFormat"
                  },
                  {
                     "$ref": "#/$defs/TriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenTriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TagsWithSeparatorFormat"
                  },
                  {
                     "$ref": "#/$defs/OptionalFormat"
                  },
                  {
                     "$ref": "#/$defs/PlusFormat"
                  },
                  {
                     "$ref": "#/$defs/StarFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  },
                  {
                     "$ref": "#/$defs/ExcludeTokenFormat"
                  },
                  {
                     "$ref": "#/$defs/AnyTokensFormat"
                  },
                  {
                     "$ref": "#/$defs/RepeatFormat"
                  },
                  {
                     "$ref": "#/$defs/DispatchFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenDispatchFormat"
                  }
               ],
               "title": "Content"
            }
         },
         "required": [
            "content"
         ],
         "title": "StarFormat",
         "type": "object"
      },
      "TagFormat": {
         "description": "A format that matches a tag: ``begin content end``.\n\nThe ``end`` field can be a single string or a list of possible end strings.\nWhen multiple end strings are provided, any of them will be accepted as a valid\nending for the tag.\n\nExamples\n--------\n\nSingle end string:\n\n.. code-block:: python\n\n    TagFormat(begin=\"<response>\", content=..., end=\"</response>\")\n\nMultiple end strings:\n\n.. code-block:: python\n\n    TagFormat(begin=\"<response>\", content=..., end=[\"</response>\", \"</answer>\"])",
         "properties": {
            "type": {
               "const": "tag",
               "default": "tag",
               "title": "Type",
               "type": "string"
            },
            "begin": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  }
               ],
               "title": "Begin"
            },
            "content": {
               "discriminator": {
                  "mapping": {
                     "any_text": "#/$defs/AnyTextFormat",
                     "any_tokens": "#/$defs/AnyTokensFormat",
                     "const_string": "#/$defs/ConstStringFormat",
                     "dispatch": "#/$defs/DispatchFormat",
                     "exclude_token": "#/$defs/ExcludeTokenFormat",
                     "grammar": "#/$defs/GrammarFormat",
                     "json_schema": "#/$defs/JSONSchemaFormat",
                     "optional": "#/$defs/OptionalFormat",
                     "or": "#/$defs/OrFormat",
                     "plus": "#/$defs/PlusFormat",
                     "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                     "regex": "#/$defs/RegexFormat",
                     "repeat": "#/$defs/RepeatFormat",
                     "sequence": "#/$defs/SequenceFormat",
                     "star": "#/$defs/StarFormat",
                     "tag": "#/$defs/TagFormat",
                     "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                     "token": "#/$defs/TokenFormat",
                     "token_dispatch": "#/$defs/TokenDispatchFormat",
                     "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                     "triggered_tags": "#/$defs/TriggeredTagsFormat"
                  },
                  "propertyName": "type"
               },
               "oneOf": [
                  {
                     "$ref": "#/$defs/AnyTextFormat"
                  },
                  {
                     "$ref": "#/$defs/ConstStringFormat"
                  },
                  {
                     "$ref": "#/$defs/JSONSchemaFormat"
                  },
                  {
                     "$ref": "#/$defs/GrammarFormat"
                  },
                  {
                     "$ref": "#/$defs/RegexFormat"
                  },
                  {
                     "$ref": "#/$defs/QwenXMLParameterFormat"
                  },
                  {
                     "$ref": "#/$defs/OrFormat"
                  },
                  {
                     "$ref": "#/$defs/SequenceFormat"
                  },
                  {
                     "$ref": "#/$defs/TagFormat"
                  },
                  {
                     "$ref": "#/$defs/TriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenTriggeredTagsFormat"
                  },
                  {
                     "$ref": "#/$defs/TagsWithSeparatorFormat"
                  },
                  {
                     "$ref": "#/$defs/OptionalFormat"
                  },
                  {
                     "$ref": "#/$defs/PlusFormat"
                  },
                  {
                     "$ref": "#/$defs/StarFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  },
                  {
                     "$ref": "#/$defs/ExcludeTokenFormat"
                  },
                  {
                     "$ref": "#/$defs/AnyTokensFormat"
                  },
                  {
                     "$ref": "#/$defs/RepeatFormat"
                  },
                  {
                     "$ref": "#/$defs/DispatchFormat"
                  },
                  {
                     "$ref": "#/$defs/TokenDispatchFormat"
                  }
               ],
               "title": "Content"
            },
            "end": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "items": {
                        "type": "string"
                     },
                     "type": "array"
                  },
                  {
                     "$ref": "#/$defs/TokenFormat"
                  }
               ],
               "title": "End"
            }
         },
         "required": [
            "begin",
            "content",
            "end"
         ],
         "title": "TagFormat",
         "type": "object"
      },
      "TagsWithSeparatorFormat": {
         "description": "A format that matches a tags with separator. It can match zero, one, or more tags, separated\nby the separator, with no other text allowed.\n\nExamples\n--------\n\n.. code-block:: python\n\n    structural_tag = TagsWithSeparatorFormat(\n        tags=[\n            TagFormat(begin=\"<function=func1>\", content=JSONSchemaFormat(json_schema=...), end=\"</function>\"),\n            TagFormat(begin=\"<function=func2>\", content=JSONSchemaFormat(json_schema=...), end=\"</function>\"),\n        ],\n        separator=\",\",\n        at_least_one=False,\n        stop_after_first=False,\n    )\n\nThe above structural tag can accept an empty string, or the following outputs::\n\n    <function=func1>{\"name\": \"John\", \"age\": 30}</function>\n    <function=func1>{\"name\": \"John\", \"age\": 30}</function>,<function=func2>{\"name\": \"Jane\", \"age\": 25}</function>\n    <function=func1>{\"name\": \"John\", \"age\": 30}</function>,<function=func2>{\"name\": \"Jane\", \"age\": 25}</function>,<function=func1>{\"name\": \"John\", \"age\": 30}</function>",
         "properties": {
            "type": {
               "const": "tags_with_separator",
               "default": "tags_with_separator",
               "title": "Type",
               "type": "string"
            },
            "tags": {
               "items": {
                  "$ref": "#/$defs/TagFormat"
               },
               "title": "Tags",
               "type": "array"
            },
            "separator": {
               "title": "Separator",
               "type": "string"
            },
            "at_least_one": {
               "default": false,
               "title": "At Least One",
               "type": "boolean"
            },
            "stop_after_first": {
               "default": false,
               "title": "Stop After First",
               "type": "boolean"
            }
         },
         "required": [
            "tags",
            "separator"
         ],
         "title": "TagsWithSeparatorFormat",
         "type": "object"
      },
      "TokenDispatchFormat": {
         "description": "Matches certain patterns in free-form text.\nWhen certain tokens are generated, the following content must follow the corresponding format.\nCertain tokens can be excluded from being generated in the free-form part.\n\nThe user specifies a list of (pattern token, formats). The LLM can generate any free-form text, but\nwhen a pattern is matched in the text, the following output must follow the corresponding format.\nThe ``loop`` field controls whether the matching of this structure ends after accepting the first\npattern and format. If False, it ends. If true, the matching continues, and this format will\ncontinue to allow free-form text and detect the next pattern to be generated.\nThe ``excludes`` field controls the strings that cannot be generated in the free-form text.\nIt can also control the end of the format:\n``SequenceFormat(DispatchFormat(..., excludes=\"\"), ConstStringFormat(\"\"))``\nor\n``TagFormat(begin=..., content=DispatchFormat(..., excludes=\"\"), end=\"\")``\nends the matching of the format when LLM generates <end>.",
         "properties": {
            "type": {
               "const": "token_dispatch",
               "default": "token_dispatch",
               "title": "Type",
               "type": "string"
            },
            "rules": {
               "items": {
                  "maxItems": 2,
                  "minItems": 2,
                  "prefixItems": [
                     {
                        "anyOf": [
                           {
                              "type": "integer"
                           },
                           {
                              "type": "string"
                           }
                        ]
                     },
                     {
                        "discriminator": {
                           "mapping": {
                              "any_text": "#/$defs/AnyTextFormat",
                              "any_tokens": "#/$defs/AnyTokensFormat",
                              "const_string": "#/$defs/ConstStringFormat",
                              "dispatch": "#/$defs/DispatchFormat",
                              "exclude_token": "#/$defs/ExcludeTokenFormat",
                              "grammar": "#/$defs/GrammarFormat",
                              "json_schema": "#/$defs/JSONSchemaFormat",
                              "optional": "#/$defs/OptionalFormat",
                              "or": "#/$defs/OrFormat",
                              "plus": "#/$defs/PlusFormat",
                              "qwen_xml_parameter": "#/$defs/QwenXMLParameterFormat",
                              "regex": "#/$defs/RegexFormat",
                              "repeat": "#/$defs/RepeatFormat",
                              "sequence": "#/$defs/SequenceFormat",
                              "star": "#/$defs/StarFormat",
                              "tag": "#/$defs/TagFormat",
                              "tags_with_separator": "#/$defs/TagsWithSeparatorFormat",
                              "token": "#/$defs/TokenFormat",
                              "token_dispatch": "#/$defs/TokenDispatchFormat",
                              "token_triggered_tags": "#/$defs/TokenTriggeredTagsFormat",
                              "triggered_tags": "#/$defs/TriggeredTagsFormat"
                           },
                           "propertyName": "type"
                        },
                        "oneOf": [
                           {
                              "$ref": "#/$defs/AnyTextFormat"
                           },
                           {
                              "$ref": "#/$defs/ConstStringFormat"
                           },
                           {
                              "$ref": "#/$defs/JSONSchemaFormat"
                           },
                           {
                              "$ref": "#/$defs/GrammarFormat"
                           },
                           {
                              "$ref": "#/$defs/RegexFormat"
                           },
                           {
                              "$ref": "#/$defs/QwenXMLParameterFormat"
                           },
                           {
                              "$ref": "#/$defs/OrFormat"
                           },
                           {
                              "$ref": "#/$defs/SequenceFormat"
                           },
                           {
                              "$ref": "#/$defs/TagFormat"
                           },
                           {
                              "$ref": "#/$defs/TriggeredTagsFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenTriggeredTagsFormat"
                           },
                           {
                              "$ref": "#/$defs/TagsWithSeparatorFormat"
                           },
                           {
                              "$ref": "#/$defs/OptionalFormat"
                           },
                           {
                              "$ref": "#/$defs/PlusFormat"
                           },
                           {
                              "$ref": "#/$defs/StarFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenFormat"
                           },
                           {
                              "$ref": "#/$defs/ExcludeTokenFormat"
                           },
                           {
                              "$ref": "#/$defs/AnyTokensFormat"
                           },
                           {
                              "$ref": "#/$defs/RepeatFormat"
                           },
                           {
                              "$ref": "#/$defs/DispatchFormat"
                           },
                           {
                              "$ref": "#/$defs/TokenDispatchFormat"
                           }
                        ]
                     }
                  ],
                  "type": "array"
               },
               "title": "Rules",
               "type": "array"
            },
            "loop": {
               "default": true,
               "title": "Loop",
               "type": "boolean"
            },
            "exclude_tokens": {
               "default": [],
               "items": {
                  "anyOf": [
                     {
                        "type": "integer"
                     },
                     {
                        "type": "string"
                     }
                  ]
               },
               "title": "Exclude Tokens",
               "type": "array"
            }
         },
         "required": [
            "rules"
         ],
         "title": "TokenDispatchFormat",
         "type": "object"
      },
      "TokenFormat": {
         "description": "A format that matches a single token by ID or string representation.",
         "properties": {
            "type": {
               "const": "token",
               "default": "token",
               "title": "Type",
               "type": "string"
            },
            "token": {
               "anyOf": [
                  {
                     "type": "integer"
                  },
                  {
                     "type": "string"
                  }
               ],
               "title": "Token"
            }
         },
         "required": [
            "token"
         ],
         "title": "TokenFormat",
         "type": "object"
      },
      "TokenTriggeredTagsFormat": {
         "description": "A format that dispatches to tags based on token-level triggers.\n\nSimilar to TriggeredTagsFormat but uses token IDs instead of string triggers.\nTags must use ``TokenFormat`` ``begin`` fields, not strings.\nFor string-level dispatch, use ``TriggeredTagsFormat`` instead.",
         "properties": {
            "type": {
               "const": "token_triggered_tags",
               "default": "token_triggered_tags",
               "title": "Type",
               "type": "string"
            },
            "trigger_tokens": {
               "items": {
                  "anyOf": [
                     {
                        "type": "integer"
                     },
                     {
                        "type": "string"
                     }
                  ]
               },
               "title": "Trigger Tokens",
               "type": "array"
            },
            "tags": {
               "items": {
                  "$ref": "#/$defs/TagFormat"
               },
               "title": "Tags",
               "type": "array"
            },
            "exclude_tokens": {
               "default": [],
               "items": {
                  "anyOf": [
                     {
                        "type": "integer"
                     },
                     {
                        "type": "string"
                     }
                  ]
               },
               "title": "Exclude Tokens",
               "type": "array"
            },
            "at_least_one": {
               "default": false,
               "title": "At Least One",
               "type": "boolean"
            },
            "stop_after_first": {
               "default": false,
               "title": "Stop After First",
               "type": "boolean"
            }
         },
         "required": [
            "trigger_tokens",
            "tags"
         ],
         "title": "TokenTriggeredTagsFormat",
         "type": "object"
      },
      "TriggeredTagsFormat": {
         "description": "A format that matches triggered tags. It can allow any output until a trigger is\nencountered, then dispatch to the corresponding tag; when the end tag is encountered, the\ngrammar will allow any following output, until the next trigger is encountered.\n\nEach tag should be matched by exactly one trigger. \"matching\" means the trigger should be a\nprefix of the begin tag.\n\nTags must use **string** ``begin`` fields, not ``TokenFormat``.\nFor token-level dispatch, use ``TokenTriggeredTagsFormat`` instead.\n\nExamples\n--------\n\n.. code-block:: python\n\n    structural_tag = TriggeredTagsFormat(\n        triggers=[\"<function=\"],\n        tags=[\n            TagFormat(\n                begin=\"<function=func1>\",\n                content=JSONSchemaFormat(json_schema=...),\n                end=\"</function>\",\n            ),\n            TagFormat(\n                begin=\"<function=func2>\",\n                content=JSONSchemaFormat(json_schema=...),\n                end=\"</function>\",\n            ),\n        ],\n        at_least_one=False,\n        stop_after_first=False,\n    )\n\nThe above structural tag can accept the following outputs::\n\n    <function=func1>{\"name\": \"John\", \"age\": 30}</function>\n    <function=func2>{\"name\": \"Jane\", \"age\": 25}</function>\n    any_text<function=func1>{\"name\": \"John\", \"age\": 30}</function>any_text1<function=func2>{\"name\": \"Jane\", \"age\": 25}</function>any_text2",
         "properties": {
            "type": {
               "const": "triggered_tags",
               "default": "triggered_tags",
               "title": "Type",
               "type": "string"
            },
            "triggers": {
               "items": {
                  "type": "string"
               },
               "title": "Triggers",
               "type": "array"
            },
            "tags": {
               "items": {
                  "$ref": "#/$defs/TagFormat"
               },
               "title": "Tags",
               "type": "array"
            },
            "at_least_one": {
               "default": false,
               "title": "At Least One",
               "type": "boolean"
            },
            "stop_after_first": {
               "default": false,
               "title": "Stop After First",
               "type": "boolean"
            },
            "excludes": {
               "default": [],
               "items": {
                  "type": "string"
               },
               "title": "Excludes",
               "type": "array"
            }
         },
         "required": [
            "triggers",
            "tags"
         ],
         "title": "TriggeredTagsFormat",
         "type": "object"
      }
   },
   "$ref": "#/$defs/TagsWithSeparatorFormat"
}

field type: Literal['tags_with_separator'] = 'tags_with_separator'

The type of the format.

field tags: List[TagFormat] [Required]

The tags of the tags with separator.

field separator: str [Required]

The separator of the tags with separator.

field at_least_one: bool = False

Whether at least one of the tags must be matched.

field stop_after_first: bool = False

Whether to stop after the first tag is matched.