# `vllm_mlx.reasoning.glm4_parser`

Reasoning parser for GLM-4 models (GLM-4.5-Air, GLM-4.6V, GLM-4.7, etc.).

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

## 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.glm4_parser
    options:
      members:
        - _BOX_START
        - _BOX_END
        - Glm4ReasoningParser
      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.reasoning.glm4_parser.Glm4ReasoningParser" markdown="1">
<summary><code>vllm_mlx.reasoning.glm4_parser.Glm4ReasoningParser</code> · class</summary>

```python
vllm_mlx.reasoning.glm4_parser.Glm4ReasoningParser()
```

Reasoning parser for GLM-4 models.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Constructs: `vllm_mlx.reasoning.glm4_parser.Glm4ReasoningParser`

**Exceptions and behavior**

Class `Glm4ReasoningParser` derives from `BaseThinkingReasoningParser` and declares 4 direct member(s).
No direct `raise` statement appears in this definition.

[View source #L27-L113](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/reasoning/glm4_parser.py#L27-L113).

</details>

<details class="api-contract" id="contract-vllm_mlx.reasoning.glm4_parser.Glm4ReasoningParser.start_token" markdown="1">
<summary><code>vllm_mlx.reasoning.glm4_parser.Glm4ReasoningParser.start_token</code> · method</summary>

```python
vllm_mlx.reasoning.glm4_parser.Glm4ReasoningParser.start_token() -> str
```

Return the marker that opens a GLM reasoning span.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Type: `str`
- Direct return expressions: `'<think>'`

**Exceptions and behavior**

Method `Glm4ReasoningParser.start_token` returns `'<think>'`.
No direct `raise` statement appears in this definition.

[View source #L50-L53](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/reasoning/glm4_parser.py#L50-L53).

</details>

<details class="api-contract" id="contract-vllm_mlx.reasoning.glm4_parser.Glm4ReasoningParser.end_token" markdown="1">
<summary><code>vllm_mlx.reasoning.glm4_parser.Glm4ReasoningParser.end_token</code> · method</summary>

```python
vllm_mlx.reasoning.glm4_parser.Glm4ReasoningParser.end_token() -> str
```

Return the marker that closes a GLM reasoning span.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Type: `str`
- Direct return expressions: `'</think>'`

**Exceptions and behavior**

Method `Glm4ReasoningParser.end_token` returns `'</think>'`.
No direct `raise` statement appears in this definition.

[View source #L56-L59](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/reasoning/glm4_parser.py#L56-L59).

</details>

<details class="api-contract" id="contract-vllm_mlx.reasoning.glm4_parser.Glm4ReasoningParser.extract_reasoning" markdown="1">
<summary><code>vllm_mlx.reasoning.glm4_parser.Glm4ReasoningParser.extract_reasoning</code> · method</summary>

```python
vllm_mlx.reasoning.glm4_parser.Glm4ReasoningParser.extract_reasoning(model_output: str) -> tuple[str | None, str | None]
```

Strip GLM box markers and split complete reasoning from content.

**Parameters**

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

**Returns**

- Type: `tuple[str | None, str | None]`
- Direct return expressions: `super().extract_reasoning(cleaned)`

**Exceptions and behavior**

Method `Glm4ReasoningParser.extract_reasoning` calls `model_output.replace(_BOX_START, '').replace`, `model_output.replace`, `super().extract_reasoning`, `super`; returns `super().extract_reasoning(cleaned)`.
No direct `raise` statement appears in this definition.

[View source #L61-L68](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/reasoning/glm4_parser.py#L61-L68).

</details>

<details class="api-contract" id="contract-vllm_mlx.reasoning.glm4_parser.Glm4ReasoningParser.extract_reasoning_streaming" markdown="1">
<summary><code>vllm_mlx.reasoning.glm4_parser.Glm4ReasoningParser.extract_reasoning_streaming</code> · method</summary>

```python
vllm_mlx.reasoning.glm4_parser.Glm4ReasoningParser.extract_reasoning_streaming(previous_text: str, current_text: str, delta_text: str) -> DeltaMessage | None
```

Extract reasoning from streaming delta.

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

**Returns**

- Type: `DeltaMessage | None`
- Direct return expressions: `None`; `super().extract_reasoning_streaming(previous_text, current_text, delta_text)`; `DeltaMessage(content=delta_text)`

**Exceptions and behavior**

Method `Glm4ReasoningParser.extract_reasoning_streaming` calls `delta_text.replace(_BOX_START, '').replace`, `delta_text.replace`, `super().extract_reasoning_streaming`, `super`; has 3 explicit return paths.
No direct `raise` statement appears in this definition.

[View source #L70-L113](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/reasoning/glm4_parser.py#L70-L113).

</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 |
| --- | --- | --- | --- | --- |
| [`Glm4ReasoningParser`](#contract-vllm_mlx.reasoning.glm4_parser.Glm4ReasoningParser) | class | `Glm4ReasoningParser()` | Reasoning parser for GLM-4 models. | [#L27-L113](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/reasoning/glm4_parser.py#L27-L113) |
| [`Glm4ReasoningParser.start_token`](#contract-vllm_mlx.reasoning.glm4_parser.Glm4ReasoningParser.start_token) | method | `Glm4ReasoningParser.start_token() -> str` | Return the marker that opens a GLM reasoning span. | [#L50-L53](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/reasoning/glm4_parser.py#L50-L53) |
| [`Glm4ReasoningParser.end_token`](#contract-vllm_mlx.reasoning.glm4_parser.Glm4ReasoningParser.end_token) | method | `Glm4ReasoningParser.end_token() -> str` | Return the marker that closes a GLM reasoning span. | [#L56-L59](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/reasoning/glm4_parser.py#L56-L59) |
| [`Glm4ReasoningParser.extract_reasoning`](#contract-vllm_mlx.reasoning.glm4_parser.Glm4ReasoningParser.extract_reasoning) | method | `Glm4ReasoningParser.extract_reasoning(model_output: str) -> tuple[str \| None, str \| None]` | Strip GLM box markers and split complete reasoning from content. | [#L61-L68](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/reasoning/glm4_parser.py#L61-L68) |
| [`Glm4ReasoningParser.extract_reasoning_streaming`](#contract-vllm_mlx.reasoning.glm4_parser.Glm4ReasoningParser.extract_reasoning_streaming) | method | `Glm4ReasoningParser.extract_reasoning_streaming(previous_text: str, current_text: str, delta_text: str) -> DeltaMessage \| None` | Extract reasoning from streaming delta. | [#L70-L113](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/reasoning/glm4_parser.py#L70-L113) |
