Structured output

Structured output constrains a model to return data in a shape you specified — usually JSON matching a schema — instead of prose. It turns "parse the answer and hope" into a contract the model cannot syntactically break.

Also called: JSON mode, constrained decoding · Reviewed

How does it work?

You supply a schema describing the fields you want and their types. Rather than asking politely in the prompt and validating afterwards, the decoder is restricted at each step to tokens that can still lead to a valid document — so a response that violates the schema is not merely discouraged, it is unreachable.

That is a meaningful difference from prompting for JSON. Asking produces valid JSON most of the time and fails unpredictably; constraining produces it every time, because the invalid paths were never available.

Why does it matter?

Prose is a fine output for a human and a terrible one for a program. Anything downstream of the model — a database write, a UI, another service — needs fields, and the code that extracts fields from free text is the code that breaks when the model phrases things differently.

It also makes failures honest. A missing field is visible immediately rather than surfacing later as an empty string that looked like an answer.

What do people get wrong?

Confusing valid with correct. The schema guarantees shape, not truth: a model that must return a date will return a date, including one it invented. Structured output removes parsing errors and does nothing about hallucination.

The second mistake is over-specifying. Deeply nested schemas with many optional branches give the model more ways to be confused about what belongs where, and a flatter shape is usually both easier to fill and easier to check.

Where this comes from

Learning this properly is easier with other people.

OneShopAI is where students, developers and founders work through this material together — sessions, builds and people who answer questions.