aiengineering.guideaiengineering.guide

Working SWE → AI engineer · Stop 5 of 15 lessons

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

  1. The three mechanisms. JSON mode, tool-use schemas, and provider-side constrained decoding. What each guarantees and what each doesn’t.
  2. Pydantic at the boundary. Defining the shape once, using it as both the schema and the parser. The pattern that keeps types honest.
  3. Failure modes. Truncation mid-object, extra fields, subtly wrong types. What to catch, what to retry, what to fail on.
  4. Nested and recursive schemas. Where models still struggle, and how to flatten schemas that push the limit.
  5. Enums and controlled vocabularies. The single biggest reliability win for classification.
  6. 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.

Outline

Enter to go · Esc to close