vllm.v1.structured_output.utils
¶
Classes:
-
OutlinesDiskCache–SQLite-backed cache for outlines_core.Index objects.
-
OutlinesVocabulary–Wrapper class for
outlines_core.Vocabulary,
Functions:
-
compile_regex_with_timeout–Run a regex compilation callable with a timeout.
-
get_outlines_cache–Get the Cache instance to be used for index caching.
-
get_outlines_cache_path–Get the context object that contains previously-computed return values.
-
get_outlines_vocabulary–Get the
Vocabularyobject for a given tokenizer. -
grammar_is_likely_lark–Check if grammar appears to use Lark syntax.
-
strip_speculative_padding–Drop speculative-decoding padding from a token block.
OutlinesDiskCache
¶
SQLite-backed cache for outlines_core.Index objects.
Uses outlines_core's native binary serialization (via Rust serde) instead of pickle, eliminating arbitrary code execution risk on deserialization.
Source code in vllm/v1/structured_output/utils.py
OutlinesVocabulary
¶
Wrapper class for outlines_core.Vocabulary,
which allows us to store a hash with the vocabulary
Source code in vllm/v1/structured_output/utils.py
_reduced_vocabulary(tokenizer)
¶
Create a map from vocabulary tokens to lists of equivalent token ids.
Returns:
Source code in vllm/v1/structured_output/utils.py
compile_regex_with_timeout(fn, pattern)
¶
Run a regex compilation callable with a timeout.
Prevents ReDoS attacks where adversarial regex patterns (e.g. nested
quantifiers like (a+)+b) cause exponential DFA state-space explosion,
hanging the inference worker indefinitely.
Parameters:
-
(fn¶Callable[[str], _T]) –Single-argument callable that takes the pattern and performs the regex compilation.
-
(pattern¶str) –The regex pattern string, passed to fn and included in timeout error messages.
Raises:
-
ValueError–If compilation exceeds the configured timeout.
Source code in vllm/v1/structured_output/utils.py
get_outlines_cache()
¶
Get the Cache instance to be used for index caching.
Source code in vllm/v1/structured_output/utils.py
get_outlines_cache_path()
¶
Get the context object that contains previously-computed return values.
Source code in vllm/v1/structured_output/utils.py
get_outlines_vocabulary(tokenizer)
¶
Get the Vocabulary object for a given tokenizer.
Source code in vllm/v1/structured_output/utils.py
grammar_is_likely_lark(grammar_str)
¶
Check if grammar appears to use Lark syntax.
Parameters:
Returns:
-
bool(bool) –True if grammar appears to be in Lark format, False otherwise
Examples:
Source code in vllm/v1/structured_output/utils.py
strip_speculative_padding(token_ids)
¶
Drop speculative-decoding padding from a token block.
ngram and other speculative backends pad rejected draft positions with a -1 sentinel. Structured-output grammars treat every entry as a real token id, so the sentinels (and everything after the first one) are removed here, before tokens reach any backend, rather than inside a single backend.