Curiosity · Concept
Structured Output
Structured output makes an LLM's answer machine-readable. Instead of free prose, the model emits JSON that matches a schema you supply (Pydantic, Zod, or JSON Schema), or a tool call with typed arguments. Providers guarantee conformance via constrained decoding, so downstream code can parse the result safely. This is what turns LLMs from chatbots into programmable components.
Quick reference
- Proficiency
- Beginner
- Also known as
- JSON mode, function calling, tool calling, schema-guided generation
- Prerequisites
- LLM API basics, JSON / JSON Schema
Frequently asked questions
What is structured output?
It is having an LLM produce an answer in a specified format — typically JSON matching a schema, or a tool call with typed arguments — rather than free prose. The provider enforces the structure during decoding, so your downstream code can parse the output reliably.
What's the difference between JSON mode and structured outputs?
Plain JSON mode just guarantees the output is valid JSON — any shape. Structured outputs (OpenAI) or tool-use schemas (Anthropic) also guarantee the JSON matches a supplied schema, with constrained decoding ensuring field names, types, enums, and required fields are all respected.
How does constrained decoding work?
At each token step, the decoder masks out tokens that would violate the schema — for example, after '{"name":' only string tokens are legal, after a closing brace only whitespace or end-of-message. Tools like Outlines, llguidance, or XGrammar build a finite-state machine from the schema.
Does structured output hurt model quality?
Sometimes slightly. The model can be less fluent when constrained, and overly nested or ambiguous schemas can confuse it. Best practice: keep schemas flat where possible, let the model reason in a 'thoughts' field first, and validate with Pydantic/Zod after. For complex tasks, generate reasoning then a structured answer.
Sources
- OpenAI — Structured Outputs — accessed 2026-04-20
- Anthropic — Tool use and JSON mode — accessed 2026-04-20
- Outlines — Structured generation — accessed 2026-04-20
- Instructor library — accessed 2026-04-20