Loading...
Loading...
Get guaranteed, schema-valid JSON from AI models. Compare JSON mode, strict schema enforcement, and tool-use approaches across GPT-4o, Claude, Gemini, and open-source models.
20+
Models with JSON mode
6+
Supporting strict schema
<0.1%
Error rate (strict mode)
4
Approaches available
| Model | JSON mode | Schema | Strict | Pydantic / Zod | Input /1M | Output /1M |
|---|---|---|---|---|---|---|
GPT-4oBest structured output OpenAI | ✓ | ✓ | ✓ | First-class (parse) | $2.50 | $10.00 |
GPT-4o miniBest value OpenAI | ✓ | ✓ | ✓ | First-class (parse) | $0.15 | $0.60 |
Claude Sonnet 4.6Best via tools Anthropic | — | ✓ | — | Via tool use | $3.00 | $15.00 |
Anthropic | — | ✓ | — | Via tool use | $5.00 | $25.00 |
Gemini 2.0 FlashMost affordable | ✓ | ✓ | ✓ | Via responseSchema | $0.10 | $0.40 |
| ✓ | ✓ | ✓ | Via responseSchema | $3.50 | $10.50 | |
Mistral | ✓ | — | — | Prompt-based | $2.00 | $6.00 |
Meta (open) | ✓ | — | — | Outlines / LM Format Enforcer | $0.59 | $0.79 |
Most reliable structured output with strict JSON schema mode. The `.parse()` SDK method validates responses against Pydantic/Zod schemas automatically. Near-zero malformed JSON rate.
Same structured output quality as GPT-4o at 17× lower cost. Ideal for high-volume extraction pipelines. Strict schema mode is production-ready.
Claude has no native JSON mode, but structured output via tool use is highly reliable. Define a tool with your schema and ask Claude to call it — consistently accurate JSON.
Most capable model for complex schema extraction — especially for nested objects and conditional structures. Use when output accuracy matters more than cost.
Cheapest model with strict schema enforcement. Gemini's responseSchema parameter accepts OpenAPI-compatible JSON schema. Great for high-volume document processing.
Handles extremely complex schemas over long documents. 2M context window enables end-to-end extraction of large codebases, legal documents, or financial reports.
JSON mode available but no strict schema enforcement. Works well for simple extraction with clear schema instructions in the prompt. GDPR-friendly EU hosting available.
JSON mode works but schema accuracy drops on complex structures. Pair with Outlines or LM Format Enforcer for guaranteed schema compliance when self-hosting.
Ask the model to respond in JSON. Guarantees valid JSON but no schema enforcement — the model decides the structure. Best for flexible extraction.
You provide a JSON schema; the model is constrained to match it exactly. Near-zero invalid responses. Best for production pipelines.
Define a tool with your schema as parameters. The model calls the tool to return structured data. Works with all major providers including Anthropic.
At the inference level, tokens are masked to enforce grammar. Guarantees 100% valid output. Available via self-hosted models with Outlines or vLLM guided generation.
JSON mode guarantees the response is valid JSON but does not enforce a specific schema — the model decides the structure. Structured output (also called JSON schema mode) constrains the model to match your exact schema, with strict enforcement. OpenAI introduced strict schema mode in 2024; GPT-4o and GPT-4o mini both support it. For production systems, use strict schema mode.
Claude does not have a dedicated JSON mode. The recommended approach is to use tool use: define a tool with your desired schema as the parameters, then ask Claude to call that tool. This reliably produces valid, schema-matching JSON. Alternatively, you can instruct Claude in the system prompt to respond in JSON — this works but has a slightly higher error rate than the tool use approach.
OpenAI's Python SDK includes a `.parse()` method that accepts a Pydantic model class. The SDK automatically converts it to a JSON schema, sends it to the API with strict mode, and parses the response back into a typed Pydantic object. This eliminates boilerplate JSON parsing and gives you full type safety in Python. Equivalent functionality is available in TypeScript via Zod with the OpenAI SDK.
With strict schema mode, all fields in the schema must be present in the output. To make a field optional, use a union type with null: `{ "type": ["string", "null"] }`. The model will return the string value or null. Avoid deeply nested optional structures — they can confuse the model and reduce output quality even with schema constraints.
Constrained decoding (grammar-based generation) works at the token sampling level — invalid tokens are masked before they can be generated. This gives 100% schema compliance regardless of model capability. Libraries like Outlines and LM Format Enforcer implement this for self-hosted models. Use it when you need guaranteed compliance and are running your own inference stack. API-based providers do not expose this level of control.