Skip to content
Capabilities

JSON Mode (Structured Output)

Forces the model to output valid JSON instead of free-form text.

What it does

JSON mode constrains the model output to be valid JSON. This eliminates the need for fragile regex parsing. Some providers go further with "structured output" mode, where you provide a JSON Schema and the output is guaranteed to conform to it.

How it works

During token generation, the model applies a grammar constraint that only allows tokens forming valid JSON. This happens at the logit level, masking out tokens that would break JSON syntax. With schema-constrained output, additional constraints ensure required fields are present.

When to use it

Any time you need to parse model output programmatically. Data extraction from unstructured text. Building APIs where the response feeds directly into your application. Generating database records or configuration files.

Common mistakes

Using JSON mode without specifying what JSON structure you want. Not using structured output when available. Requesting deeply nested JSON structures that the model struggles with.

Default values by provider

Available in OpenAI GPT-4o+ (json_object mode + structured outputs), Anthropic Claude 3+ (tool_use with schema), Google Gemini (responseSchema parameter).

Related parameters