vllm.parser.mistral
¶
Classes:
-
MistralParser–Mistral parser: engine-based reasoning +
[TOOL_CALLS]tool calls. -
MistralToolCall–ToolCall with a Mistral-compatible random alphanumeric id.
-
StreamingState–Streaming parsing state for pre-v11 tool call extraction.
Functions:
-
mistral_config–Return a
ParserEngineConfigfor the Mistral output format.
MistralParser
¶
Bases: ParserEngine
Mistral parser: engine-based reasoning + [TOOL_CALLS] tool calls.
Reasoning encoding is auto-detected from the tokenizer:
"special_token"–[THINK]present in vocab (v13+)."text"– tokenizer supports grammar but has no[THINK](v11)."none"– no grammar support; reasoning disabled.
Tool calls use the [TOOL_CALLS]func_name{...} format. The opening
{ doubles as the NAME→ARGS separator and is included in the argument
buffer via an ARG_VALUE_CHUNK event on the transition (mirrors
kimi_k2, JSON args, tool_args_json=True).
When the tokenizer does not support grammar (_reasoning_encoding ==
"none"), the legacy [TOOL_CALLS]-based extraction path is used
instead of the declarative engine, handling both pre-v11 JSON-array and
v11+ funcname{args} formats.
_build_guided_schema_pre_v11(request)
¶
Build a guided JSON schema for pre-v11 required/named tool choice.
The schema enforces the Mistral-native array format
[{"name": ..., "arguments": {...}}] so the model emits a parseable
bare JSON array instead of free-form text.
Parameters:
-
(request¶ChatCompletionRequest) –The chat completion request carrying
toolsandtool_choice.
Returns:
_ensure_tool_id(slot, name)
¶
Assign a Mistral-compatible 9-char alphanumeric id to slot.
_extract_args_json(raw_args, func_name)
¶
Return the first complete JSON value in raw_args.
v11+ tool calls are emitted as name{args} with no terminator, so a
model may append ordinary text after the closing brace. Parse the first
JSON value with raw_decode and drop any trailing output, mirroring
the pre-v11 path (fixes gh#48975).
_extract_tool_calls_streaming_pre_v11_tokenizer(delta_text, delta_token_ids)
¶
Extract tool calls for pre-v11 Mistral models.
Handles [TOOL_CALLS][{"name": "add", "arguments":{"a": 3.5}}].
_handle_arg_chunk(event, deltas)
¶
Emit the opening { as an arg delta when the name is first sent.
When the TOOL_NAME→TOOL_ARGS transition fires, { arrives as an
ARG_VALUE_CHUNK before name_sent is True. The parent emits the
name delta but not the { arg delta. This override re-emits the
current chunk so streaming clients receive a valid JSON prefix.
_legacy_extract_tool_calls(model_output, request)
¶
Pre-v11 non-streaming extraction.
Handles [TOOL_CALLS][{...}] and guided bare-array formats.
_track_streamed_args_pre_v11(tool_call)
¶
Accumulate tool_call arguments into the streaming state.
MistralToolCall
¶
Bases: ToolCall
ToolCall with a Mistral-compatible random alphanumeric id.
_mistral_response_format(request)
¶
Return the OpenAI-format response format to pass to mistral-common.
structured_outputs (json, json_object) takes precedence over
response_format, as in structured_outputs_from_response_format.
_pre_v11_function_calls(parsed)
¶
Decode the JSON after a pre-v11 [TOOL_CALLS] marker.
Mirrors the streaming path: a bare object is a single call, entries that
are not call objects are skipped, a missing or non-string name becomes
"" (as in the v11+ path) and string arguments are kept as-is.
mistral_config(*, reasoning_encoding, name='mistral')
cached
¶
Return a ParserEngineConfig for the Mistral output format.
Parameters:
-
(reasoning_encoding¶Literal['special_token', 'text', 'none']) –Reasoning token format.
"special_token"– v13+[THINK]/[/THINK]special tokens placed in bothterminalsandtoken_id_terminals."text"– v11<think>/</think>plain text placed interminalsonly; notoken_id_terminalsfor think tokens."none"– no reasoning support. -
(name¶str, default:'mistral') –Name embedded in the returned config (used for debugging).
Returns:
-
ParserEngineConfig–A frozen
ParserEngineConfigwithinitial_state=CONTENT.