A client sends a long email with five action items buried in the text. You read it twice to catch them all. What if the agent could return a list you could loop over?
I'd need the agent to return a Python list. But last week it returned strings. Can you actually get a list back?
result_type=list[str] tells the agent to return a JSON array of strings. PydanticAI deserialises it into a real Python list:
def extract_action_items(text: str) -> list:
return Agent(model, result_type=list[str]).run_sync(text).outputSo result.output is literally a Python list? I can do for item in result.output?
Exactly. Compare this to what you would have to do without result_type:
# Without result_type — parse a multi-line string manually
raw = Agent(model, system_prompt="List action items, one per line.").run_sync(text).output
items = [line.strip('- ') for line in raw.strip().splitlines() if line.strip()]
# With result_type — Python list, no parsing needed
items = Agent(model, result_type=list[str]).run_sync(text).outputFive action items, five list entries, one call. I can email each one, add them to a task list, count them — all standard Python list operations.
And if the client email has zero action items, the model returns an empty list — not an error. Your downstream code handles it identically either way.
This is the scope-change extraction I was imagining in Week 1. Client sends a messy email, I get back a clean list of what changed.
That is Day 14 exactly — a multi-field Pydantic model that includes category, urgency, and summary. First build the list pattern; then add structure to each item.
result_type=list[str] for List Outputresult = Agent(model, result_type=list[str]).run_sync(text)
items = result.output # ['Send the revised logo by Friday', 'Confirm print specs', ...]PydanticAI deserialises the model's JSON array into a Python list[str]. All standard list operations apply: len(), indexing, iteration, filtering, list comprehensions.
Without result_type, you would call .split('\n') on free text — fragile when the model changes its formatting. result_type=list[str] produces a guaranteed list regardless of how the model chose to structure its response internally.
An empty list is valid — no special handling needed. If the email has no action items, result.output is [].
A client sends a long email with five action items buried in the text. You read it twice to catch them all. What if the agent could return a list you could loop over?
I'd need the agent to return a Python list. But last week it returned strings. Can you actually get a list back?
result_type=list[str] tells the agent to return a JSON array of strings. PydanticAI deserialises it into a real Python list:
def extract_action_items(text: str) -> list:
return Agent(model, result_type=list[str]).run_sync(text).outputSo result.output is literally a Python list? I can do for item in result.output?
Exactly. Compare this to what you would have to do without result_type:
# Without result_type — parse a multi-line string manually
raw = Agent(model, system_prompt="List action items, one per line.").run_sync(text).output
items = [line.strip('- ') for line in raw.strip().splitlines() if line.strip()]
# With result_type — Python list, no parsing needed
items = Agent(model, result_type=list[str]).run_sync(text).outputFive action items, five list entries, one call. I can email each one, add them to a task list, count them — all standard Python list operations.
And if the client email has zero action items, the model returns an empty list — not an error. Your downstream code handles it identically either way.
This is the scope-change extraction I was imagining in Week 1. Client sends a messy email, I get back a clean list of what changed.
That is Day 14 exactly — a multi-field Pydantic model that includes category, urgency, and summary. First build the list pattern; then add structure to each item.
result_type=list[str] for List Outputresult = Agent(model, result_type=list[str]).run_sync(text)
items = result.output # ['Send the revised logo by Friday', 'Confirm print specs', ...]PydanticAI deserialises the model's JSON array into a Python list[str]. All standard list operations apply: len(), indexing, iteration, filtering, list comprehensions.
Without result_type, you would call .split('\n') on free text — fragile when the model changes its formatting. result_type=list[str] produces a guaranteed list regardless of how the model chose to structure its response internally.
An empty list is valid — no special handling needed. If the email has no action items, result.output is [].
Create a free account to get started. Paid plans unlock all tracks.