Five days of result_type. How does it feel to get typed objects back from an agent instead of strings you have to parse?
Much calmer. Once the model returns a Contact instance or a list[str] directly, you stop writing defensive regex everywhere. The class definition becomes the contract.
That is the shift Week 2 is trying to land — replacing runtime normalization with type-level guarantees. Which pattern felt most powerful?
Literal. One line of typing instead of .strip().lower() plus a fallback. PydanticAI retries invisibly when the model misses — and you get a validated string every call.
That is the whole argument for result_type — the model bends to your schema, not the other way around. Ready for the quiz.
Week 2 kept the same agent call and added four shapes of structured output: a Pydantic Contact model, a Literal enum for closed-set outputs, a list[str] for variable-length lists, and a three-field Ticket model that packs category, urgency, and a summary into one call.
The unifying idea is that result_type replaces runtime parsing. Instead of generating a string and then stripping, splitting, or regex-ing it into shape, you declare the shape first and let PydanticAI validate the model's response against it. If the model misses, PydanticAI retries — invisibly — until the output fits.
Week 3 pushes that further. Two agents in one function, batch processing over a list of inputs, and using min/max with key=len to pick the best response out of several runs. Same Agent, same run_sync, bigger compositions.
Five days of result_type. How does it feel to get typed objects back from an agent instead of strings you have to parse?
Much calmer. Once the model returns a Contact instance or a list[str] directly, you stop writing defensive regex everywhere. The class definition becomes the contract.
That is the shift Week 2 is trying to land — replacing runtime normalization with type-level guarantees. Which pattern felt most powerful?
Literal. One line of typing instead of .strip().lower() plus a fallback. PydanticAI retries invisibly when the model misses — and you get a validated string every call.
That is the whole argument for result_type — the model bends to your schema, not the other way around. Ready for the quiz.
Week 2 kept the same agent call and added four shapes of structured output: a Pydantic Contact model, a Literal enum for closed-set outputs, a list[str] for variable-length lists, and a three-field Ticket model that packs category, urgency, and a summary into one call.
The unifying idea is that result_type replaces runtime parsing. Instead of generating a string and then stripping, splitting, or regex-ing it into shape, you declare the shape first and let PydanticAI validate the model's response against it. If the model misses, PydanticAI retries — invisibly — until the output fits.
Week 3 pushes that further. Two agents in one function, batch processing over a list of inputs, and using min/max with key=len to pick the best response out of several runs. Same Agent, same run_sync, bigger compositions.
Create a free account to get started. Paid plans unlock all tracks.