With-Structured-Output
LangBot Day 5: Structured Output — Typed Responses with Pydantic
reading time: 16 minutes
Recap: Yesterday we wired LangBot’s prompt and model into one pipeline with LCEL’s pipe operator — chain = prompt | llm. One invoke() call now handles everything from formatting to generation. But we still get back a raw AIMessage and have to reach into .content for the text. Today LangBot returns real typed objects.
The problem: unstructured mush
Every LLM response so far has been an AIMessage — a blob of text with no shape. To extract anything useful, you either parse it yourself or pray the model followed your formatting instructions. Both are fragile.