Lesson 6 · 10 min
Structured output (JSON & schemas)
How to make the model produce JSON that actually parses.
Why JSON breaks
Four failure modes:
- Markdown fences — model wraps JSON in
json ... - Trailing commas / single quotes — invalid JSON
- Hallucinated keys — extra fields the schema doesn't expect
- Truncation — model runs out of tokens mid-output
The fix is rarely "ask harder". It's a combination of system-level techniques.