Structured output is any technique that forces a language model to return data matching a predefined schema, such as JSON, XML, or a custom grammar, instead of free-form prose.
Structured output constrains token generation so the final response conforms to a developer-supplied schema. Implementations range from logit-level masking to grammar-based samplers and post-generation parsing with repair.
That single constraint changes what models are useful for. Free-form text is fine for chat, but downstream systems need predictable fields, types, and nesting. Structured output removes the parsing fragility that comes from asking a model to 'return JSON please' without enforcement.
Think of it like this. Think of a form with labeled boxes instead of an open notebook. The model still writes the answers, but it has to put each answer in the right box with the right format.
The runtime builds a grammar or JSON schema before decoding. During generation, invalid tokens are masked or the sampler is guided to stay inside the grammar. After generation, the result is parsed and rejected if it does not match. Some providers repair malformed output by retrying only the invalid portion.
"Asking for JSON is enough." Models frequently emit invalid JSON without enforcement. "Structured output is slower." The overhead is usually small compared to the cost of parsing failures downstream. "Grammar is only for code." Any repeatable output format benefits from schema constraints.
Removes parsing fragility, but strict grammars can reduce output quality if the schema conflicts with natural phrasing. Best for APIs, agents, and data pipelines; less critical for human-facing chat.