Back to Topics

Structured Output

Getting JSON instead of prose from an LLM — Pydantic schemas, where prompting stops being enough, and streaming structured output to the UI.

By default an LLM answers in prose. Applications need answers in shapes: references in a set format, chapters with timestamps, a verdict your code can branch on. Structured output — schemas, Pydantic models, constrained decoding — is how the material closes that gap, and it has a favorite teaching move: prompt for the format first, watch the format drift, then make the schema enforce it.

From free text to a schema

AI Engineering Buildcamp module 1 introduces structured output the moment the first RAG pipeline works: the documentation assistant gets a Pydantic schema, so answers carry references in a parseable format instead of prose that mostly looks right. The next lesson combines it with streaming — structure arriving incrementally, for UIs that cannot wait for the full response.

Where prompting stops being enough

Module 2 runs the comparison on video summaries. Prompt Engineering for Video Summaries gets chapters and timestamps from a transcript — and then states the two failure modes plainly: timestamps are not always accurate, and the output format is not consistent. Structured Output for Video Summaries fixes both by defining exactly what the response must contain. Same transcript, same model — the schema is the difference. The module repeats the pattern for extracting structured data from PDF books.

Structured agents

Module 3 extends it from responses to agent behavior: an agent that ends its loop by returning parsed JSON instead of free text, using OpenAI's response parsing. Module 4 brings the streaming version into the testing stack — structured streaming with PydanticAI — where the structured output becomes something tests can assert against. That is the quiet theme of the page: structure is what turns model output into a contract, and contracts are what Evaluation and Monitoring tests.

Where to go next

Keep building with a membership

Every topic guide is free to read. Members get structured courses, live workshops, and feedback on real projects.