Week 1 every agent handed back a plain string. Imagine you asked it to pull the key commitment from a strategy memo — owner, task, due date. What do you actually get back?
A paragraph, probably. The names and dates buried somewhere in prose. I'd have to parse it every time — split on punctuation, pray the format holds.
And the moment the model rephrases a commitment — "will own this" versus "falls to" — your parser breaks. This week you skip the parser entirely. You hand PydanticAI a Pydantic model as result_type, and result.output is no longer a string. It is a typed Python object with exactly the fields you declared.
So the Pydantic model is a form the AI must fill out completely. That's the difference between a tool I can use in a pipeline and a chatbot I have to babysit.
Exactly that contract. Week 2 covers Pydantic models for multi-field extraction, Literal for constrained single values so the AI picks from your options instead of writing an essay, list[str] for variable-length bullet lists, and chaining a summariser into a Literal-typed classifier. Strings are messy. Structure is reliable.
result_type=Contact with a Pydantic model: extract name and email from any textresult_type=Literal["high","medium","low"] for urgency classificationresult_type=list[str] to pull action items as a proper Python listGoal: agents return the shape you asked for, not the shape the model felt like.
Create a free account to get started. Paid plans unlock all tracks.
Week 1 every agent handed back a plain string. Imagine you asked it to pull the key commitment from a strategy memo — owner, task, due date. What do you actually get back?
A paragraph, probably. The names and dates buried somewhere in prose. I'd have to parse it every time — split on punctuation, pray the format holds.
And the moment the model rephrases a commitment — "will own this" versus "falls to" — your parser breaks. This week you skip the parser entirely. You hand PydanticAI a Pydantic model as result_type, and result.output is no longer a string. It is a typed Python object with exactly the fields you declared.
So the Pydantic model is a form the AI must fill out completely. That's the difference between a tool I can use in a pipeline and a chatbot I have to babysit.
Exactly that contract. Week 2 covers Pydantic models for multi-field extraction, Literal for constrained single values so the AI picks from your options instead of writing an essay, list[str] for variable-length bullet lists, and chaining a summariser into a Literal-typed classifier. Strings are messy. Structure is reliable.
result_type=Contact with a Pydantic model: extract name and email from any textresult_type=Literal["high","medium","low"] for urgency classificationresult_type=list[str] to pull action items as a proper Python listGoal: agents return the shape you asked for, not the shape the model felt like.