Skip to content

vllm.v1.structured_output.backend_xgrammar

Classes:

Functions:

XgrammarBackend dataclass

Bases: StructuredOutputBackend

_filter_special_tokens(tokenizer, tokenizer_info) staticmethod

Filter ALL special tokens from tokenizer_info

XgrammarGrammar dataclass

Bases: StructuredOutputGrammar

Methods:

  • accept_tokens –

    Accepts a list of tokens and advances the FSM.

  • validate_tokens –

    Checks if the list of tokens are accepted by the FSM in sequence.

accept_tokens(request_id, tokens)

Accepts a list of tokens and advances the FSM.

Returns True if all grammar-constrained tokens were accepted. Tokens after termination are ignored. Returns False if the FSM failed to advance.

validate_tokens(tokens)

Checks if the list of tokens are accepted by the FSM in sequence. Will not advance the FSM.

Returns the prefix list of tokens that are accepted by the FSM.

_schema_types(schema)

Normalize a scalar or list-valued JSON Schema type.

has_xgrammar_unsupported_json_features(schema)

Check if JSON schema contains features unsupported by xgrammar.

validate_xgrammar_grammar(sampling_params)

Validate that the request is supported by structured output.

Raises VLLMValidationError if the request is not supported.