# `vllm_mlx.tool_parsers.mistral_tool_parser`

Mistral tool call parser for vllm-mlx.

[View the complete module source at #L1-L512](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/mistral_tool_parser.py#L1-L512).

## 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.tool_parsers.mistral_tool_parser
    options:
      members:
        - ALPHANUMERIC
        - _TOOL_NAME_PATTERN
        - generate_mistral_tool_id
        - _is_plain_tool_name
        - MistralToolParser
      filters: []
      show_if_no_docstring: true

## 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.

<details class="api-contract" id="contract-vllm_mlx.tool_parsers.mistral_tool_parser.generate_mistral_tool_id" markdown="1">
<summary><code>vllm_mlx.tool_parsers.mistral_tool_parser.generate_mistral_tool_id</code> · function</summary>

```python
vllm_mlx.tool_parsers.mistral_tool_parser.generate_mistral_tool_id() -> str
```

Generate a random Mistral-compatible tool call ID.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Type: `str`
- Direct return expressions: `''.join(choices(ALPHANUMERIC, k=9))`

**Exceptions and behavior**

Function `generate_mistral_tool_id` calls `''.join`, `choices`; returns `''.join(choices(ALPHANUMERIC, k=9))`.
No direct `raise` statement appears in this definition.

[View source #L34-L40](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/mistral_tool_parser.py#L34-L40).

</details>

<details class="api-contract" id="contract-vllm_mlx.tool_parsers.mistral_tool_parser._is_plain_tool_name" markdown="1">
<summary><code>vllm_mlx.tool_parsers.mistral_tool_parser._is_plain_tool_name</code> · function</summary>

```python
vllm_mlx.tool_parsers.mistral_tool_parser._is_plain_tool_name(name: str) -> bool
```

Return True for names that are safe to dispatch as function calls.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `str` | `yes` | `none` | Required positional or keyword input. |

**Returns**

- Type: `bool`
- Direct return expressions: `bool(_TOOL_NAME_PATTERN.match(name))`

**Exceptions and behavior**

Function `_is_plain_tool_name` calls `bool`, `_TOOL_NAME_PATTERN.match`; returns `bool(_TOOL_NAME_PATTERN.match(name))`.
No direct `raise` statement appears in this definition.

[View source #L43-L45](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/mistral_tool_parser.py#L43-L45).

</details>

<details class="api-contract" id="contract-vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser" markdown="1">
<summary><code>vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser</code> · class</summary>

```python
vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser(tokenizer = None)
```

Tool call parser for Mistral models.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `tokenizer` | `not annotated` | `no` | `None` | Optional positional or keyword input; defaults to `None`. |

**Returns**

- Constructs: `vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser`

**Exceptions and behavior**

Class `MistralToolParser` derives from `ToolParser` and declares 8 direct member(s).
No direct `raise` statement appears in this definition.

[View source #L49-L512](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/mistral_tool_parser.py#L49-L512).

</details>

<details class="api-contract" id="contract-vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser.__init__" markdown="1">
<summary><code>vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser.__init__</code> · method</summary>

```python
vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser.__init__(tokenizer = None) -> not annotated
```

Method `MistralToolParser.__init__` updates `self.bot_token_id`, `self._args_started`, `self._args_in_string`, `self._args_escaped`; calls `super().__init__`, `super`, `self.vocab.get`.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `tokenizer` | `not annotated` | `no` | `None` | Optional positional or keyword input; defaults to `None`. |

**Returns**

- Type: `not annotated`

**Exceptions and behavior**

Method `MistralToolParser.__init__` updates `self.bot_token_id`, `self._args_started`, `self._args_in_string`, `self._args_escaped`; calls `super().__init__`, `super`, `self.vocab.get`.
No direct `raise` statement appears in this definition.

[View source #L68-L90](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/mistral_tool_parser.py#L68-L90).

</details>

<details class="api-contract" id="contract-vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser.reset" markdown="1">
<summary><code>vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser.reset</code> · method</summary>

```python
vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser.reset() -> None
```

Reset shared and Mistral-specific streaming tool-call state.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Type: `None`

**Exceptions and behavior**

Method `MistralToolParser.reset` updates `self._args_started`, `self._args_in_string`, `self._args_escaped`, `self._name_buffer`; calls `super().reset`, `super`.
No direct `raise` statement appears in this definition.

[View source #L92-L102](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/mistral_tool_parser.py#L92-L102).

</details>

<details class="api-contract" id="contract-vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser._start_new_tool_call" markdown="1">
<summary><code>vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser._start_new_tool_call</code> · method</summary>

```python
vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser._start_new_tool_call() -> None
```

Begin a new streaming tool call: bump the index and reset the per-call name/arguments and id state.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Type: `None`

**Exceptions and behavior**

Method `MistralToolParser._start_new_tool_call` updates `self.current_tool_id`, `self._args_started`, `self._args_in_string`, `self._args_escaped`; calls `generate_mistral_tool_id`.
No direct `raise` statement appears in this definition.

[View source #L104-L114](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/mistral_tool_parser.py#L104-L114).

</details>

<details class="api-contract" id="contract-vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser._scan_args_for_new_call" markdown="1">
<summary><code>vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser._scan_args_for_new_call</code> · method</summary>

```python
vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser._scan_args_for_new_call(text: str) -> int
```

Scan an argument delta, updating the persistent JSON string state, and return the position of the first [TOOL_CALLS] marker that sits outside a string (a new call), or -1 when there is none.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `text` | `str` | `yes` | `none` | Required positional or keyword input. |

**Returns**

- Type: `int`
- Direct return expressions: `i`; `-1`

**Exceptions and behavior**

Method `MistralToolParser._scan_args_for_new_call` updates `self._args_escaped`, `self._args_in_string`; calls `len`, `text.startswith`; has 2 explicit return paths.
No direct `raise` statement appears in this definition.

[View source #L116-L146](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/mistral_tool_parser.py#L116-L146).

</details>

<details class="api-contract" id="contract-vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser._split_on_tool_call_markers" markdown="1">
<summary><code>vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser._split_on_tool_call_markers</code> · method</summary>

```python
vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser._split_on_tool_call_markers(text: str) -> list[str]
```

Split on [TOOL_CALLS] occurrences that are outside JSON strings.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `text` | `str` | `yes` | `none` | Required positional or keyword input. |

**Returns**

- Type: `list[str]`
- Direct return expressions: `[text]`; `parts`

**Exceptions and behavior**

Method `MistralToolParser._split_on_tool_call_markers` calls `text.find`, `len`, `text.startswith`, `parts.append`; has 2 explicit return paths.
No direct `raise` statement appears in this definition.

[View source #L148-L192](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/mistral_tool_parser.py#L148-L192).

</details>

<details class="api-contract" id="contract-vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser.extract_tool_calls" markdown="1">
<summary><code>vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser.extract_tool_calls</code> · method</summary>

```python
vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser.extract_tool_calls(model_output: str, request: dict[str, Any] | None = None) -> ExtractedToolCallInformation
```

Extract tool calls from a complete Mistral model response.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `model_output` | `str` | `yes` | `none` | The complete model output string |
| `request` | `dict[str, Any] \| None` | `no` | `None` | Optional request context |

**Returns**

- Type: `ExtractedToolCallInformation`
- Direct return expressions: `ExtractedToolCallInformation(tools_called=False, tool_calls=[], content=model_output)`; `ExtractedToolCallInformation(tools_called=True, tool_calls=tool_calls, content=content if content else None)`

**Exceptions and behavior**

Method `MistralToolParser.extract_tool_calls` calls `ExtractedToolCallInformation`, `self._split_on_tool_call_markers`, `content_and_raw_tool_calls[0].strip`, `raw_tool_call.strip`; has 2 explicit return paths.
No direct `raise` statement appears in this definition.

[View source #L194-L332](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/mistral_tool_parser.py#L194-L332).

</details>

<details class="api-contract" id="contract-vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser.extract_tool_calls_streaming" markdown="1">
<summary><code>vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser.extract_tool_calls_streaming</code> · method</summary>

```python
vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser.extract_tool_calls_streaming(previous_text: str, current_text: str, delta_text: str, previous_token_ids: Sequence[int] | None = None, current_token_ids: Sequence[int] | None = None, delta_token_ids: Sequence[int] | None = None, request: dict[str, Any] | None = None) -> dict[str, Any] | None
```

Extract tool calls from streaming Mistral model output.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `previous_text` | `str` | `yes` | `none` | Required positional or keyword input. |
| `current_text` | `str` | `yes` | `none` | Required positional or keyword input. |
| `delta_text` | `str` | `yes` | `none` | Required positional or keyword input. |
| `previous_token_ids` | `Sequence[int] \| None` | `no` | `None` | Optional positional or keyword input; defaults to `None`. |
| `current_token_ids` | `Sequence[int] \| None` | `no` | `None` | Optional positional or keyword input; defaults to `None`. |
| `delta_token_ids` | `Sequence[int] \| None` | `no` | `None` | Optional positional or keyword input; defaults to `None`. |
| `request` | `dict[str, Any] \| None` | `no` | `None` | Optional positional or keyword input; defaults to `None`. |

**Returns**

- Type: `dict[str, Any] | None`
- Direct return expressions: `{'tool_calls': [{'index': self.current_tool_id, 'type': 'function', 'function': {'arguments': delta_text}}]}`; `result if result else None`; `{'content': delta_text}`; `{'content': tool_delta['content']}`; `{'tool_calls': [tool_call]}`; `None`

**Exceptions and behavior**

Method `MistralToolParser.extract_tool_calls_streaming` updates `self._tool_call_id_emitted`; calls `self._scan_args_for_new_call`, `self._start_new_tool_call`, `self._parse_streaming_tool_delta`, `len`; has 6 explicit return paths.
No direct `raise` statement appears in this definition.

[View source #L334-L453](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/mistral_tool_parser.py#L334-L453).

</details>

<details class="api-contract" id="contract-vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser._parse_streaming_tool_delta" markdown="1">
<summary><code>vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser._parse_streaming_tool_delta</code> · method</summary>

```python
vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser._parse_streaming_tool_delta(text: str) -> dict[str, str] | None
```

Parse a streaming delta for tool call information.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `text` | `str` | `yes` | `none` | Required positional or keyword input. |

**Returns**

- Type: `dict[str, str] | None`
- Direct return expressions: `None`; `{'arguments': text}`; `result if result else None`; `{'content': overflowed}`

**Exceptions and behavior**

Method `MistralToolParser._parse_streaming_tool_delta` updates `self._name_buffer`, `self._args_started`, `self._name_buffer_overflow`; calls `self._name_buffer.find`, `len`, `self._name_buffer[:idx].strip`; has 4 explicit return paths.
No direct `raise` statement appears in this definition.

[View source #L455-L512](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/mistral_tool_parser.py#L455-L512).

</details>

## 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 |
| --- | --- | --- | --- | --- |
| [`generate_mistral_tool_id`](#contract-vllm_mlx.tool_parsers.mistral_tool_parser.generate_mistral_tool_id) | function | `generate_mistral_tool_id() -> str` | Generate a random Mistral-compatible tool call ID. | [#L34-L40](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/mistral_tool_parser.py#L34-L40) |
| [`_is_plain_tool_name`](#contract-vllm_mlx.tool_parsers.mistral_tool_parser._is_plain_tool_name) | function | `_is_plain_tool_name(name: str) -> bool` | Return True for names that are safe to dispatch as function calls. | [#L43-L45](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/mistral_tool_parser.py#L43-L45) |
| [`MistralToolParser`](#contract-vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser) | class | `MistralToolParser(tokenizer = None)` | Tool call parser for Mistral models. | [#L49-L512](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/mistral_tool_parser.py#L49-L512) |
| [`MistralToolParser.__init__`](#contract-vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser.__init__) | method | `MistralToolParser.__init__(tokenizer = None) -> not annotated` | Method `MistralToolParser.__init__` updates `self.bot_token_id`, `self._args_started`, `self._args_in_string`, `self._args_escaped`; calls `super().__init__`, `super`, `self.vocab.get`. | [#L68-L90](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/mistral_tool_parser.py#L68-L90) |
| [`MistralToolParser.reset`](#contract-vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser.reset) | method | `MistralToolParser.reset() -> None` | Reset shared and Mistral-specific streaming tool-call state. | [#L92-L102](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/mistral_tool_parser.py#L92-L102) |
| [`MistralToolParser._start_new_tool_call`](#contract-vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser._start_new_tool_call) | method | `MistralToolParser._start_new_tool_call() -> None` | Begin a new streaming tool call: bump the index and reset the per-call name/arguments and id state. | [#L104-L114](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/mistral_tool_parser.py#L104-L114) |
| [`MistralToolParser._scan_args_for_new_call`](#contract-vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser._scan_args_for_new_call) | method | `MistralToolParser._scan_args_for_new_call(text: str) -> int` | Scan an argument delta, updating the persistent JSON string state, and return the position of the first [TOOL_CALLS] marker that sits outside a string (a new call), or -1 when there is none. | [#L116-L146](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/mistral_tool_parser.py#L116-L146) |
| [`MistralToolParser._split_on_tool_call_markers`](#contract-vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser._split_on_tool_call_markers) | method | `MistralToolParser._split_on_tool_call_markers(text: str) -> list[str]` | Split on [TOOL_CALLS] occurrences that are outside JSON strings. | [#L148-L192](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/mistral_tool_parser.py#L148-L192) |
| [`MistralToolParser.extract_tool_calls`](#contract-vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser.extract_tool_calls) | method | `MistralToolParser.extract_tool_calls(model_output: str, request: dict[str, Any] \| None = None) -> ExtractedToolCallInformation` | Extract tool calls from a complete Mistral model response. | [#L194-L332](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/mistral_tool_parser.py#L194-L332) |
| [`MistralToolParser.extract_tool_calls_streaming`](#contract-vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser.extract_tool_calls_streaming) | method | `MistralToolParser.extract_tool_calls_streaming(previous_text: str, current_text: str, delta_text: str, previous_token_ids: Sequence[int] \| None = None, current_token_ids: Sequence[int] \| None = None, delta_token_ids: Sequence[int] \| None = None, request: dict[str, Any] \| None = None) -> dict[str, Any] \| None` | Extract tool calls from streaming Mistral model output. | [#L334-L453](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/mistral_tool_parser.py#L334-L453) |
| [`MistralToolParser._parse_streaming_tool_delta`](#contract-vllm_mlx.tool_parsers.mistral_tool_parser.MistralToolParser._parse_streaming_tool_delta) | method | `MistralToolParser._parse_streaming_tool_delta(text: str) -> dict[str, str] \| None` | Parse a streaming delta for tool call information. | [#L455-L512](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/tool_parsers/mistral_tool_parser.py#L455-L512) |
