Structured Outputs
Your code cannot read a friendly paragraph. It needs JSON with the right keys and types, every single time. Structured outputs make the model give data that matches a schema. Then the next line of your program can use it directly.
New words
- JSON
- A text format for data, made of keys and values.
- Schema
- A description of the exact shape the data must have.
- Enum
- A field that can take only a few fixed values.
- Token
- A word or a piece of a word that the model writes.
- Constrained decoding
- Blocking every token that would break the schema, at each step.
- Pydantic
- A Python library that checks data against a schema.
- Validation
- Checking that the data follows the shape and the rules.
What you will learn
- The problem: code needs data, models write text
- A ladder of approaches
- How constrained decoding works
- Try it: mask the bad tokens
- Trade-offs and failure modes
- Production practices
- In code
- In a real system
- Interview tip
- Key takeaways
10 quiz questions at the end.
The full lesson, with interactive demos and the quiz, opens after you sign in with Google. It is free.