B3Beginner 90 minutes reading and codeLocked

Structured Outputs: JSON, Schema Validation, Constrained Decoding

Your LLM returns a string. Your application needs JSON. That gap has crashed more production systems than any model hallucination. Structured output is the bridge between natural language and typed data. Get it right and your LLM becomes a reliable API. Get it wrong and you're parsing free-text with regex at 3am.

In this lesson

  1. 01Learning Objectives
  2. 02The Problem
  3. 03The Concept
  4. 04Build it
  5. 05Use it
  6. 06Exercises
  7. 07Key Terms
  8. 08Further Reading

About 3300 words of reading, with code, 5 quiz questions and the tutor.

The full lesson opens with an access code

You can see what this lesson covers and the milestone it sets. The full text, code, quizzes, the tutor and the AI reviews come with the K850 practice, along with weekly build sessions and code review.

Codes come with the K850 practice. Book a place

Milestone forThe ZRA Tax Desk

Every answer passes a schema

Define the response schema (answer, citations with doc and page, confidence, needs_human, follow_up) and enforce it: provider JSON mode, validation, one repair retry with the validation error, then a safe fallback.

Done when

  • A Pydantic model with typed citations (doc, page) and a confidence enum
  • Validation plus one repair retry, then a fixed safe fallback
  • Over 50 calls: under 2% of responses end in the fallback

Stretch: Compare provider JSON mode with constrained decoding or a validation library

Reviews open with an access code.

Interview practice

Questions on this topic that AI engineering interviews ask, with the companies reported to ask them. Answer the way you would out loud; Jev scores it and DeepSeek tells you what to add.

Scoring opens with an access code. You can still read the questions and prepare.

Adapted from open-source work: AI Engineering from Scratch by Rohit Ghumare (MIT, lesson text, code and quizzes); Awesome LLM Apps by Shubham Saboo (Apache-2.0, starter code); AI Engineering Interview Questions by Outcome School (Apache-2.0, interview questions). Capstones, milestones, data packs and Zambian context by Zambrite.

Chat on WhatsApp