Skip to main content
When working with reasoning models that use special tokens like <think>...</think> to denote reasoning sections, you might want to allow free-form text within these sections while still enforcing grammar constraints on the rest of the output. SGLang provides a feature to disable grammar restrictions within reasoning sections. This is particularly useful for models that need to perform complex reasoning steps before providing a structured output. To enable this feature, use the --reasoning-parser flag which decide the think_end_token, such as </think>, when launching the server. You can also specify the reasoning parser using the --reasoning-parser flag.

Supported Models

Currently, SGLang supports the following reasoning models:
  • DeepSeek R1 series: The reasoning content is wrapped with <think> and </think> tags.
  • QwQ: The reasoning content is wrapped with <think> and </think> tags.

Usage

OpenAI Compatible API

Specify the --grammar-backend, --reasoning-parser option.
Example

JSON

you can directly define a JSON schema or use Pydantic to define and validate the response. Using Pydantic
Example
JSON Schema Directly
Example

EBNF

Example

Regular expression

Example

Structural Tag

Example

Native API and SGLang Runtime (SRT)

Note: For native API, as a work-around, you need to set require_reasoning argument to True to ensure the model will think before generating the structured output. It’s not required for chat-completion API.

JSON

Using Pydantic
Example
JSON Schema Directly
Example

EBNF

Example

Regular expression

Example

Structural Tag

Example
Example

Offline Engine API

Example

JSON

Using Pydantic
Example
JSON Schema Directly
Example

EBNF

Example

Regular expression

Example
Example
Example