Best LLMs for structured output in 2026: hit rates and retry costs

By LLMTest Team · Jul 27, 2026 · 6 min read nichestructured-outputjsoncost
On this page

On this page

  1. Three approaches to schema compliance
  2. The candidates
  3. The retry cost math
  4. Subscription vs API
  5. When middleware earns its place
  6. The pick

Unschemaed JSON prompts fail 8-15% of the time in real production pipelines. The failure mode is often silent: the model wraps its output in triple-backtick fences, nests invented fields, or emits trailing commas. Your code either throws at parse time or silently ingests wrong data. Each failure doubles the token cost through a retry and adds 500-2,000ms of latency.

The three major cloud providers now ship native structured output. The implementations differ enough that the right choice depends on schema complexity, model budget, and tolerance for middleware. Here's what the options actually look like.

Three approaches to schema compliance

Constrained decoding (OpenAI structured outputs, Gemini response_schema) works by filtering the model's token sampling to exclude any token that would violate the target schema. Non-conforming JSON is blocked before it's ever generated, making structural failures architecturally impossible for well-formed schemas. The remaining failure mode is semantic: structurally valid JSON with incorrect values.

Tool use (Anthropic Claude) routes structured output through a different mechanism. You define a tool whose argument schema matches your desired output, instruct the model to call it, and the API packages the validated arguments before returning them. This relies on instruction-following rather than decode-time enforcement, but mid-tier and frontier Claude models are consistent enough in practice that schema compliance rates are comparable to constrained decoding.

JSON mode (response_format: { type: "json_object" }) asks the model to output valid JSON without enforcing a schema. Production failure rates run 2-5% on real workloads, with common failure shapes: markdown fences around the JSON block, extra fields the schema didn't define, and missing required keys. This approach is not reliable enough for any pipeline where malformed output propagates downstream.

The candidates

Model Approach Schema failure rate Input $/M Output $/M
GPT-4o-mini Constrained decoding <0.1% $0.15 $0.60
Gemini 2.5 Flash Constrained decoding <0.1% $0.15 $0.60
Claude Haiku 4.5 Tool use <0.1% ~$0.80 ~$4.00
GPT-5.5 Constrained decoding <0.1% $5.00 $30.00
Claude Opus 4.8 Tool use <0.1% $5.00 $25.00
JSON mode (any model) Prompt-only 2-5% varies varies

All four top candidates achieve near-identical schema compliance on well-formed schemas. The JSONSchemaBench evaluation (10,000 real-world JSON schemas across 21 models) found that constrained decoders and tool-use models alike cleared 96%+ on structural metrics including path recall, type safety, and structure coverage.

Where models diverge is value accuracy: whether the correct data ends up in the correct fields. On schemas with deep nesting, union types, or conditional constraints, frontier models pull ahead of budget models noticeably. On flat schemas with scalar values, GPT-4o-mini and Gemini 2.5 Flash match frontier accuracy at a fraction of the cost.

One practical note on Claude's approach: tool use is the underlying mechanism that delivers structured output on Anthropic's API. The same argument-validation loop that makes agentic tool calls reliable also makes schema compliance reliable there.

The retry cost math

At 1,000 JSON calls per day using GPT-4o-mini (400 tokens in, 150 tokens out):

  • Per call: (400 × $0.15/M) + (150 × $0.60/M) = $0.000060 + $0.000090 = $0.000150
  • With native structured output: $0.15/day, zero retry overhead
  • With JSON mode at 3% failure rate: 30 retries/day × $0.000150 = $0.0045/day extra, effectively invisible at this scale
  • Latency cost: those 30 retries at 1,000ms each add 30 extra seconds of pipeline wait daily

At 500,000 calls per month on GPT-5.5 (500 tokens in, 200 tokens out):

  • Per call: (500 × $5/M) + (200 × $30/M) = $0.00250 + $0.00600 = $0.00850
  • JSON mode at 3% failure rate: 15,000 retries × $0.00850 = $127/month in wasted token cost
  • Latency tax: 15,000 retries at 1,000ms average = 15,000 seconds (~250 minutes) of compounded pipeline delay per month

At budget model pricing, the retry overhead is noise. At frontier model pricing and real scale, it becomes a real monthly line item. That cost also excludes the engineering time to build and maintain retry logic.

The SQL generation benchmark illustrates the downstream effect well: one malformed response that wraps SQL in markdown fences breaks the entire query executor step. Schema compliance isn't just a correctness metric; it's an availability metric for any pipeline with structural dependencies.

Subscription vs API

Structured output is an API feature. Consumer subscriptions (ChatGPT Plus at $20/mo, Claude Pro at $20/mo, Gemini Advanced at $20/mo via Google One AI Premium) use the same underlying models through chat interfaces that don't expose response_format or response_schema parameters. For structured extraction workloads, you're always on the API.

Provider API pricing tier Subscription (chat only) Pricing page
OpenAI $0.15–$5/M input ChatGPT Plus ($20/mo), Pro ($200/mo) openai.com/api/pricing
Anthropic ~$0.80–$5/M input Claude Pro ($20/mo), Max ($100–200/mo) anthropic.com/pricing
Google $0.15/M input (Flash) Gemini Advanced via Google One AI Premium ($20/mo) ai.google.dev/pricing

For teams already using the API, subscription tiers don't affect structured output access; they're separate purchasing paths aimed at different use cases.

When middleware earns its place

If you're running open-weights models (Llama 4, Phi-4, Mistral) locally or through inference providers, you often don't get native constrained decoding via the API. Two options:

Instructor (Python/TypeScript) wraps any LLM call in a retry-on-validation-error loop with Pydantic or Zod schema enforcement. It handles the common failures (markdown fences, extra fields, type mismatches) and retries up to a configured limit before raising. For Ollama and similar local inference setups, this is the practical path to >99% schema compliance.

Outlines does constrained decoding for self-hosted models: the same mechanism as OpenAI's native structured outputs, but for inference infrastructure you control. Zero retries needed. The tradeoff is you need to run the inference server yourself.

Format enforcement via prompting (few-shot examples plus explicit formatting instructions) gets you to roughly 85-90% compliance on most frontier models. That may be acceptable for internal tools where occasional failures are logged and retried manually; it's not acceptable for production pipelines where bad data flows downstream without a visibility layer.

The pick

For most API builders in 2026:

  • Default pick: GPT-4o-mini or Gemini 2.5 Flash with native structured output. Both hit <0.1% schema failures at the lowest input cost on the market.
  • Complex schemas: Step up to GPT-5.5 or Claude Opus 4.8. Budget models' value accuracy drops on schemas with deep nesting, union types, or conditional fields, even when structural compliance stays high.
  • Open-weights locally: Use Instructor or Outlines. Prompt-only JSON mode is not production-reliable.
  • Avoid JSON mode on any pipeline where wrong data propagates silently. A 2-5% mismatch rate at 500,000 calls per month means 10,000-25,000 records with potentially corrupted fields every month. If JSON mode is your only option, three-tier JSON output validation in Node.js shows how to catch structural and semantic failures before they reach your database.

The LLMTest proxy logs schema validity rates and value accuracy per model per prompt template, so you can catch compliance regressions before they reach users. Once you've chosen a model and schema approach, wire up LLM prompt evaluations in CI; structured output compliance can silently degrade when prompt templates change even when the model version stays the same.

To compare models on your actual extraction workload, run a free test on LLMTest — schema pass rate, cost, and latency on your real prompts, not synthetic benchmarks.

Ship LLM features without burning your budget.

LLMTest proxies your OpenAI / Anthropic calls, tracks cost per feature, and auto-rewrites prompts to be cheaper while holding quality. Free to start.

Create a free account

Related articles

How to validate LLM JSON output in 2026: schema, semantic, retry
Three tiers of LLM JSON output validation in 2026: schema (Zod), semantic checks, and retry with reprompt. Includes cost math at 1,000 requests per day.
How to test LLM prompts in CI in 2026: a 30-line Node eval script
Catch LLM prompt regressions before users do: a 30-line Node.js eval script that runs golden-set tests on every PR and fails the build when quality drops.