· rangkumin.tech

Structured outputs, JSON mode or tool calling: choosing an LLM output format that will not break your parser

This AtmoRouter-authored comparison breaks down three ways to get structured output from an OpenAI-compatible LLM API: JSON mode, structured outputs with strict schemas, and tool calling, covering what each guarantees, what schemas cost in tokens, and a tested fallback pattern.

Why it matters

The key difference is the guarantee. Per OpenAI's documentation, JSON mode only ensures the output parses, not that it matches a schema, and the prompt must mention JSON. Structured outputs with strict set to true constrain decoding to your JSON Schema. Anthropic offers the same idea through output_config.format and strict tool use.

Strict mode comes with tight schema rules: every field must be required, additionalProperties must be false on every object, and there are limits on property count and nesting depth. The first request with a new schema is slower while it is processed. Output can still be cut short if the model refuses or runs out of max_tokens.

Schemas and tool definitions are billed as input tokens on every request. The article's illustrative math: a 400-token schema over 100,000 requests is 40 million input tokens, from roughly 0.14 to 20.70 dollars depending on the model, using from-prices that can change. Because schema support depends on the model, it recommends local validation on every path and a JSON mode fallback.

Sources

Choose English or Indonesian. Up to two editions a day. Unsubscribe anytime.