LESSON 2.3
Structured output and JSON
Learn key techniques and workflows in Building AI Apps with LLMs.
9m
intermediate
19,565 students
Overview
If your code consumes the output, it needs a schema. Constrain the shape, then validate the response before anything downstream touches it.
In this lesson you will:
- Constrain responses to a declared schema
- Validate the parsed output at runtime
- Handle the case where the model returns nothing usable
Pro Tip
Validate structured output even when the API guarantees a schema. A retry is cheaper than corrupt data.