Skip to content

vllm_mlx.reasoning.mistral_parser

Reasoning parser for Mistral / Ministral reasoning models.

View the complete module source at #L1-L72.

API details

Each callable below includes its exact signature, type annotations, inputs, defaults, return contract, documented exceptions, implementation source, and parsed docstring sections when the source provides them.

vllm_mlx.reasoning.mistral_parser

Reasoning parser for Mistral / Ministral reasoning models.

Models such as Magistral and Ministral-3-*-Reasoning wrap their reasoning in [THINK]...[/THINK] delimiters (registered as special tokens in the tokenizer) and support a strict switch via 'enable_thinking=False' in chat template kwargs.

This mirrors the Qwen3 parser, which uses ..., but with the Mistral bracket-token delimiters.

Supports implicit reasoning mode where [THINK] is injected in the prompt and only [/THINK] appears in the output.

vllm_mlx.reasoning.mistral_parser.MistralReasoningParser

MistralReasoningParser(tokenizer=None)

Bases: BaseThinkingReasoningParser

Reasoning parser for Mistral/Ministral reasoning models.

Uses [THINK]...[/THINK] tokens to denote reasoning text.

Supports three scenarios: 1. Both tags in output: [THINK]reasoning[/THINK]content 2. Only closing tag (think in prompt): reasoning[/THINK]content 3. No tags: pure content

Example (normal): Input: "[THINK]Let me analyze this...[/THINK]The answer is 42." Output: reasoning="Let me analyze this...", content="The answer is 42."

Example (think in prompt): Input: "Let me analyze this...[/THINK]The answer is 42." Output: reasoning="Let me analyze this...", content="The answer is 42."

Source code in vllm_mlx/reasoning/think_parser.py
def __init__(self, tokenizer=None):
    super().__init__(tokenizer)
    # Streaming state — reset per request via reset_state()
    self._phase: str = "pre_think"  # "pre_think" | "thinking" | "content"
    self._content_started = False
    self._content_buffer = ""
    # Tool call promotion state.
    self._in_tool_call = False
    self._tool_call_buffer = ""

vllm_mlx.reasoning.mistral_parser.MistralReasoningParser.start_token property

start_token: str

Return the Mistral reasoning opening marker.

vllm_mlx.reasoning.mistral_parser.MistralReasoningParser.end_token property

end_token: str

Return the Mistral reasoning closing marker.

vllm_mlx.reasoning.mistral_parser.MistralReasoningParser.extract_reasoning

extract_reasoning(model_output: str) -> tuple[str | None, str | None]

Extract reasoning from Mistral/Ministral output.

Handles both explicit [THINK]...[/THINK] tags and implicit mode where [THINK] was in the prompt (only [/THINK] in output).

Parameters:

  • model_output (str) –

    Complete model output text.

Returns:

  • tuple[str | None, str | None]

    (reasoning, content) tuple.

Source code in vllm_mlx/reasoning/mistral_parser.py
def extract_reasoning(
    self,
    model_output: str,
) -> tuple[str | None, str | None]:
    """
    Extract reasoning from Mistral/Ministral output.

    Handles both explicit [THINK]...[/THINK] tags and implicit mode
    where [THINK] was in the prompt (only [/THINK] in output).

    Args:
        model_output: Complete model output text.

    Returns:
        (reasoning, content) tuple.
    """
    # If no end token at all, treat as pure content
    if self.end_token not in model_output:
        return None, model_output

    # Use base class implementation (handles both explicit and implicit)
    return super().extract_reasoning(model_output)

Complete contract reference

Expand any definition for its exact inputs, annotations, defaults, return contract, directly raised exceptions, source-grounded behavior, and immutable line link. This section includes private and nested definitions that ordinary API generators omit.

vllm_mlx.reasoning.mistral_parser.MistralReasoningParser · class
vllm_mlx.reasoning.mistral_parser.MistralReasoningParser()

Reasoning parser for Mistral/Ministral reasoning models.

Parameters

This callable has no explicit inputs.

Returns

  • Constructs: vllm_mlx.reasoning.mistral_parser.MistralReasoningParser

Exceptions and behavior

Class MistralReasoningParser derives from BaseThinkingReasoningParser and declares 3 direct member(s). No direct raise statement appears in this definition.

View source #L19-L72.

vllm_mlx.reasoning.mistral_parser.MistralReasoningParser.start_token · method
vllm_mlx.reasoning.mistral_parser.MistralReasoningParser.start_token() -> str

Return the Mistral reasoning opening marker.

Parameters

This callable has no explicit inputs.

Returns

  • Type: str
  • Direct return expressions: '[THINK]'

Exceptions and behavior

Method MistralReasoningParser.start_token returns '[THINK]'. No direct raise statement appears in this definition.

View source #L40-L43.

vllm_mlx.reasoning.mistral_parser.MistralReasoningParser.end_token · method
vllm_mlx.reasoning.mistral_parser.MistralReasoningParser.end_token() -> str

Return the Mistral reasoning closing marker.

Parameters

This callable has no explicit inputs.

Returns

  • Type: str
  • Direct return expressions: '[/THINK]'

Exceptions and behavior

Method MistralReasoningParser.end_token returns '[/THINK]'. No direct raise statement appears in this definition.

View source #L46-L49.

vllm_mlx.reasoning.mistral_parser.MistralReasoningParser.extract_reasoning · method
vllm_mlx.reasoning.mistral_parser.MistralReasoningParser.extract_reasoning(model_output: str) -> tuple[str | None, str | None]

Extract reasoning from Mistral/Ministral output.

Parameters

Name Type Required Default Description
model_output str yes none Complete model output text.

Returns

  • Type: tuple[str | None, str | None]
  • Direct return expressions: (None, model_output); super().extract_reasoning(model_output)

Exceptions and behavior

Method MistralReasoningParser.extract_reasoning calls super().extract_reasoning, super; has 2 explicit return paths. No direct raise statement appears in this definition.

View source #L51-L72.

Complete symbol map

This map also includes private definitions and nested helpers. The signature column exposes every explicit input even when an internal helper has no dedicated parameter prose.

Symbol Kind Signature and inputs What it does Source
MistralReasoningParser class MistralReasoningParser() Reasoning parser for Mistral/Ministral reasoning models. #L19-L72
MistralReasoningParser.start_token method MistralReasoningParser.start_token() -> str Return the Mistral reasoning opening marker. #L40-L43
MistralReasoningParser.end_token method MistralReasoningParser.end_token() -> str Return the Mistral reasoning closing marker. #L46-L49
MistralReasoningParser.extract_reasoning method MistralReasoningParser.extract_reasoning(model_output: str) -> tuple[str \| None, str \| None] Extract reasoning from Mistral/Ministral output. #L51-L72