JSON mode (structured output)
JSON mode forces a language model to emit only syntactically valid JSON, usually conforming to a schema you supply.
Most major APIs (OpenAI `response_format`, Anthropic via tool-use, Gemini `response_schema`) let you guarantee the model's reply parses as JSON, and increasingly that it matches a JSON Schema. Constrained decoding makes this deterministic — the model literally cannot emit invalid syntax — eliminating retry loops for downstream code. Use it for extraction, classification, form-filling, and tool-call arguments. The trade-off is slightly more rigid responses and occasional schema confusion on complex nested structures.
When to use json mode (structured output)
- Feeding model output into deterministic downstream code.
- Extraction tasks (resume → JSON, invoice → JSON).
- Form-style UIs where the model fills fields.
Common mistakes
- Over-specifying — deeply nested schemas confuse smaller models.
- Using JSON mode without specifying the schema — "valid JSON" alone still drifts.
FAQ
What is json mode (structured output)?
JSON mode forces a language model to emit only syntactically valid JSON, usually conforming to a schema you supply.
When should I use json mode (structured output)?
Feeding model output into deterministic downstream code. Extraction tasks (resume → JSON, invoice → JSON). Form-style UIs where the model fills fields.
What are the most common mistakes with json mode (structured output)?
Over-specifying — deeply nested schemas confuse smaller models. Using JSON mode without specifying the schema — "valid JSON" alone still drifts.
Related terms
- Function calling (tool use) — Function calling lets a language model emit a structured request to invoke a developer-defined tool, enabling reliable JSON output and agent workflows.
- Structured output — Structured output is any production prompt pattern that forces a language model to return data in a deterministic, machine-parseable form (JSON, XML, custom).
- System prompt — A system prompt is the high-priority instruction block that defines a model's role, constraints, and default behaviors for an entire conversation.
Last updated: 2026-06-01. Raw markdown: https://promtable.com/glossary/json-mode.md.