AI & LLMs

Structured Outputs

also: JSON mode · constrained decoding

Forcing model output to match a schema — the difference between text you parse and data you trust.

Structured outputs make the model emit valid JSON matching a supplied schema, either by constrained decoding (masking tokens that would break the grammar) or by strict validation and retry. This is the backbone of reliable pipelines: tool calls, extraction, classification, anything a program consumes downstream. If code parses model output with regexes, you wanted structured outputs.

Worked example: constraining generation to a JSON schema (grammar/constrained decoding) guarantees parseable, schema-valid output — so ‘return {name, age}’ actually returns valid JSON every time, not prose that occasionally breaks your parser. Gotcha: the constraint enforces shape, not correctness — fields can still be wrong or hallucinated, and over-tight schemas can hurt quality by fighting the model, so validate values, not just structure.