Lesson 2.39mIntermediate19.6k students
Structured output and JSON
If your code consumes the output, it needs a schema. Constrain the shape, then validate the response before anything downstream touches it.
This lesson sits in Prompting That Holds Up, part of Building AI Apps with LLMs. It assumes what came before it and leads directly into the next lesson in the module.
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.
Resources
Your notes for this lesson will appear here.