vllm.parser.chat_parsing.content_parsers
¶
This file contains the parsers used by chat response parsing. Each parser takes a chunk of captured text and parses it into a single key in the output message dictionary. Functions are generally boilerplate.
Functions:
-
process_field–Run
bodythrough the field's content parser, then optionally apply the -
validate_transform_strings–Walk a transform template and reject any string that mixes a
{name}
_apply_transform(transform, scope)
¶
Recursively walk a transform template, which is used to restructure
parsed output into the actual shape we want. A dotted placeholder like
{content.args} descends into keys of the looked-up value.
Source code in vllm/parser/chat_parsing/content_parsers.py
_json(text, args)
¶
JSON parser with optional dialect knobs for LLM-emitted quirks.
args:
- unquoted_keys (bool): quote bare-identifier keys before parsing.
- string_delims ([[open, close], ...]): strings delimited by these
custom markers are pre-extracted, then restored as standard JSON strings.
- allow_non_json (bool): return stripped text if parsing fails.
Source code in vllm/parser/chat_parsing/content_parsers.py
_kv_lines(text, args)
¶
Parse line-delimited key<sep>value pairs into a dict.
Source code in vllm/parser/chat_parsing/content_parsers.py
_xml_inline(text, args)
¶
Parse shallow XML-ish tags into a dict. tag_pattern regex must have named
groups key and value. Optional value_parser recurses; merge_duplicates
collects duplicate keys into a list.
Source code in vllm/parser/chat_parsing/content_parsers.py
process_field(body, field, captures)
¶
Run body through the field's content parser, then optionally apply the
transform template. When transform_each is set, the parsed content must
be a list and the template is applied to each element (with the element's
keys unpacked into the template scope, alongside any regex captures).
field is a spec.Field; typed via duck-typing to avoid a cyclic import.
Source code in vllm/parser/chat_parsing/content_parsers.py
validate_transform_strings(scope, transform)
¶
Walk a transform template and reject any string that mixes a {name}
placeholder with literal text. Only whole-string placeholders (e.g.
"{content}") and plain literals are supported. Called from the template
loader so authors get a clear error at load time, not at parse time.