2 · Talking to Models › Phase 3 › Lesson 3 of 4
Structured output you can trust
What this lesson covers
“Give me JSON” is the first thing every real system asks a model for. Getting it reliably is a solved problem now — but only if you know which of the three mechanisms to use.
The outline
- The three mechanisms. JSON mode, tool-use schemas, and provider-side constrained decoding. What each guarantees and what each doesn’t.
- Pydantic at the boundary. Defining the shape once, using it as both the schema and the parser. The pattern that keeps types honest.
- Failure modes. Truncation mid-object, extra fields, subtly wrong types. What to catch, what to retry, what to fail on.
- Nested and recursive schemas. Where models still struggle, and how to flatten schemas that push the limit.
- Enums and controlled vocabularies. The single biggest reliability win for classification.
- When “structured output” is the wrong tool. Free-form answers, chained reasoning, and cases where forcing JSON makes the answer worse.
Coming soon
In outline.