Skip to content

vllm.tool_parsers.mistral_tool_parser

Classes:

MistralToolParser

Bases: MistralParserToolAdapter

Attributes:

  • bot_token (str) –

    Return the Mistral tool-call marker exposed by the legacy parser.

  • bot_token_id (int | None) –

    Return the token id for :attr:bot_token.

Source code in vllm/tool_parsers/mistral_tool_parser.py
class MistralToolParser(MistralParserToolAdapter):  # type: ignore[valid-type, misc]
    # Marked so is_mistral_tool_parser() in vllm.utils.mistral recognises
    # this adapter and lets adjust_request() fire for tool_choice="none"
    # on grammar-capable Mistral tokenizers.
    IS_MISTRAL_TOOL_PARSER = True

    # Mistral emits tool calls in the [TOOL_CALLS]name[ARGS]{...} format, not the
    # plain JSON array / bare-args that the serving layer's generic required and
    # named handlers expect. Route required/named through this parser's own
    # extraction (treated like "auto") so the [TOOL_CALLS] format is parsed
    # correctly instead of crashing or dumping the raw envelope into arguments.
    supports_required_and_named = False

    @property
    def bot_token(self) -> str:
        """Return the Mistral tool-call marker exposed by the legacy parser."""
        return self._parser_engine.bot_token

    @property
    def bot_token_id(self) -> int | None:
        """Return the token id for :attr:`bot_token`."""
        return self._parser_engine.bot_token_id

    def adjust_request(
        self,
        request: ChatCompletionRequest | ResponsesRequest,
    ) -> ChatCompletionRequest | ResponsesRequest:
        # Skip the base ToolParser tool_choice -> structured_outputs
        # conversion. Mistral enforces tool_choice via the grammar ``mode``
        # (auto/none/required/named); forwarding a tool-derived json_schema
        # would be unioned into the grammar by mistral-common, allowing raw
        # JSON in place of a real [TOOL_CALLS] call. Genuine user-provided
        # structured output on the request is still honored by the engine's
        # adjust_request.
        return self._parser_engine.adjust_request(request)

bot_token property

Return the Mistral tool-call marker exposed by the legacy parser.

bot_token_id property

Return the token id for :attr:bot_token.