Week 1 planning returned a list[str]. Production agents need richer output — priority, estimated actions, maybe a risk flag. How do you pack all that into one agent call?
A Pydantic model with those fields? But one of them is a list and the others are scalars — does the same result_type pattern still work?
It does. Pydantic models handle mixed types — a list[str], an int, a Literal[...] label — all in one class. The model definition:
from pydantic import BaseModel
from typing import Literal
class Plan(BaseModel):
steps: list[str]
priority: Literal["low", "medium", "high"]
estimated_actions: intEach field is its own type — list, Literal enum, int — and PydanticAI validates every one before returning?
Every field validated. The agent returns a Plan instance with every attribute present and typed. The full planner:
def build_agent_plan(goal: str) -> dict:
agent = Agent(
model,
result_type=Plan,
system_prompt="Plan the goal with steps, priority, and an action count estimate."
)
result = agent.run_sync(goal)
return result.output.model_dump()And model_dump() flattens the nested types — the Literal becomes a plain string, the list stays a list?
Exactly. .model_dump() serializes every field to its JSON-friendly form. Literals become strings, lists stay lists, ints stay ints. The caller gets a plain dict that any logger, dashboard, or downstream agent can read without importing your model class.
So one agent call returns a fully structured plan — steps plus priority plus estimate — ready for a dashboard or an execution loop?
One call, rich typed output. Every production planner builds on this shape. Add a field to the class when you need one more signal — nothing else in the pipeline has to change.
TL;DR: one Plan class with list, Literal, and int fields packs a full plan into one agent call.
steps: list[str] — ordered action listpriority: Literal[...] — closed-set urgency labelestimated_actions: int — numeric budget.model_dump() — JSON-friendly dict for the caller| Field | Type |
|---|---|
| steps | list[str] |
| priority | Literal |
| estimated_actions | int |
Mixed types in one model is the Pydantic superpower — ask once, get everything typed.
Week 1 planning returned a list[str]. Production agents need richer output — priority, estimated actions, maybe a risk flag. How do you pack all that into one agent call?
A Pydantic model with those fields? But one of them is a list and the others are scalars — does the same result_type pattern still work?
It does. Pydantic models handle mixed types — a list[str], an int, a Literal[...] label — all in one class. The model definition:
from pydantic import BaseModel
from typing import Literal
class Plan(BaseModel):
steps: list[str]
priority: Literal["low", "medium", "high"]
estimated_actions: intEach field is its own type — list, Literal enum, int — and PydanticAI validates every one before returning?
Every field validated. The agent returns a Plan instance with every attribute present and typed. The full planner:
def build_agent_plan(goal: str) -> dict:
agent = Agent(
model,
result_type=Plan,
system_prompt="Plan the goal with steps, priority, and an action count estimate."
)
result = agent.run_sync(goal)
return result.output.model_dump()And model_dump() flattens the nested types — the Literal becomes a plain string, the list stays a list?
Exactly. .model_dump() serializes every field to its JSON-friendly form. Literals become strings, lists stay lists, ints stay ints. The caller gets a plain dict that any logger, dashboard, or downstream agent can read without importing your model class.
So one agent call returns a fully structured plan — steps plus priority plus estimate — ready for a dashboard or an execution loop?
One call, rich typed output. Every production planner builds on this shape. Add a field to the class when you need one more signal — nothing else in the pipeline has to change.
TL;DR: one Plan class with list, Literal, and int fields packs a full plan into one agent call.
steps: list[str] — ordered action listpriority: Literal[...] — closed-set urgency labelestimated_actions: int — numeric budget.model_dump() — JSON-friendly dict for the caller| Field | Type |
|---|---|
| steps | list[str] |
| priority | Literal |
| estimated_actions | int |
Mixed types in one model is the Pydantic superpower — ask once, get everything typed.
Create a free account to get started. Paid plans unlock all tracks.