Notes

Structured Output

A model that answers in flowing prose is a pleasure to read and a misery to program against. Structured output is the practice of making it answer in a machine-readable shape instead — a JSON object, a single label from a fixed list, a function call — so the software that asked can simply use the result.

Asking politely is not enough

Three approaches, in increasing order of reliability:

  • Prompt-level — describe the shape, show one example, then parse the reply and retry when it fails. Works most of the time, which is the problem.
  • Constrained decoding — at every step the sampler masks out tokens that would break the grammar, so an invalid object is not merely unlikely but unreachable. Libraries such as Outlines and guidance work this way.
  • A provider's schema mode — the same technique run server-side, where you submit a JSON Schema and the API guarantees conformance.
Where it matters, and what it cannot promise

Structured output is the seam between a model and everything around it: it turns an answer into a value a function can accept, which is what makes extraction pipelines, classifiers and tool use possible at all. Two failure modes survive the guarantee. A schema the model finds awkward — deeply nested, cryptically named, demanding fields the text does not support — degrades the content even as the shape stays perfect, because the grammar forces a value into every slot and the model invents something plausible. And valid is not correct: the parser's success says the reply is well-formed, never that it is true.

Structured output is the practice of constraining a model's answer to a machine-readable shape — a JSON object matching a schema, an enumerated label, a tool call — rather than free prose. It is what lets a model sit inside ordinary software, because the caller can parse the result instead of interpreting it. Constrained decoding enforces the shape by masking tokens that would violate the schema at each step, which guarantees a well-formed answer but never a correct one.

Ask a knowledgeable friend where to eat and you get a lovely paragraph. Hand them a form with boxes for name, cuisine and price, and you get something you can file. Structured output is handing an AI model that form. Instead of a chatty reply, it has to answer in a strict pattern of labelled fields, so the program that asked can use the answer directly rather than trying to read English. Today's systems can hold the model to the pattern, so the boxes always come back properly filled in. What they cannot promise is that the answers inside them are right.