Skip to main content

Lesson 6 · 10 min

Structured output (JSON & schemas)

How to make the model produce JSON that actually parses.

Why JSON breaks

Four failure modes:

  1. Markdown fences — model wraps JSON in json ...
  2. Trailing commas / single quotes — invalid JSON
  3. Hallucinated keys — extra fields the schema doesn't expect
  4. Truncation — model runs out of tokens mid-output

The fix is rarely "ask harder". It's a combination of system-level techniques.