Skip to content

vllm.v1.structured_output.backend_guidance

Classes:

Functions:

GuidanceBackend dataclass

Bases: StructuredOutputBackend

Methods:

is_tokenizer_supported(tokenizer) staticmethod

Check if tokenizer is supported by guidance backend.

TODO(arpera): guidance backend does NOT support some types of tokenizers so, we MUST verify tokenizer before using guidance The problem is that guidance API does not provide a way to validate tokenizer before building LLTokenizer So, we have to do it manually here in vLLM. This is ofcourse very bad, we duplicate complex logic that can change arbitrary in future. Our check here is based on guidance source code on function from_tokenizer implementation: https://github.com/guidance-ai/llguidance/blob/main/python/llguidance/hf.py#L29-L47 If you want to contribute to vLLM, please, add to llguidance API function to implement this check there. In that case we will remove this check from vLLM. That kind of work is really appreciated!

GuidanceGrammar dataclass

Bases: StructuredOutputGrammar

Methods:

  • accept_tokens –

    Accepts a list of tokens and advances the parser.

  • validate_tokens –

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

accept_tokens(request_id, tokens)

Accepts a list of tokens and advances the parser.

Returns True if the parser was advanced successfully. Returns False if the parser failed to advance.

validate_tokens(tokens)

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

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

has_guidance_unsupported_json_features(schema)

Check if JSON schema contains features unsupported by guidance/llguidance.