You have a long meeting note and you want just the action items. How do you turn a paragraph into a list without splitting strings by hand?
A prompt like "extract the todos as a list"? And then regex the reply? Feels fragile.
Skip the regex. result_type=list[str] forces the agent to hand back a Python list — the parser is built into PydanticAI, not your code. The tight call:
agent = Agent(
model,
result_type=list[str],
system_prompt="Extract action items from the notes as a list of short tasks."
)
result = agent.run_sync(notes)
print(result.output)The system_prompt guides the task; the result_type guarantees the shape. Same two-knob pattern as Day 4.
Exactly. Prompt for substance, type for shape. The whole extractor:
def auto_create_tasks(notes: str) -> list:
agent = Agent(
model,
result_type=list[str],
system_prompt="Extract action items from the notes as a list of short tasks."
)
result = agent.run_sync(notes)
return result.outputAnd if the notes have no action items? Does the agent return an empty list?
PydanticAI validates the type, not the length. An empty list is a valid list[str]. The agent returns [] when the input has nothing actionable — which is the correct answer and what your downstream code should expect.
So the extractor is one call, one typed list out, ready to feed straight into a task-creation API on the next line of my script?
Ready to pipe. Typed extraction plus a seeded destination is the shape of every "read notes, create records" automation. One agent call, one list, one write call — the whole pattern fits on a screen.
TL;DR: result_type=list[str] plus a narrow system_prompt extracts actionable items with zero parsing.
system_prompt — "extract action items as a short list"result_type=list[str] — forces a typed list[]| Knob | Controls |
|---|---|
system_prompt | what the agent picks |
result_type | what shape it returns |
Typed extraction is the cleanest bridge between free prose and a downstream write API.
You have a long meeting note and you want just the action items. How do you turn a paragraph into a list without splitting strings by hand?
A prompt like "extract the todos as a list"? And then regex the reply? Feels fragile.
Skip the regex. result_type=list[str] forces the agent to hand back a Python list — the parser is built into PydanticAI, not your code. The tight call:
agent = Agent(
model,
result_type=list[str],
system_prompt="Extract action items from the notes as a list of short tasks."
)
result = agent.run_sync(notes)
print(result.output)The system_prompt guides the task; the result_type guarantees the shape. Same two-knob pattern as Day 4.
Exactly. Prompt for substance, type for shape. The whole extractor:
def auto_create_tasks(notes: str) -> list:
agent = Agent(
model,
result_type=list[str],
system_prompt="Extract action items from the notes as a list of short tasks."
)
result = agent.run_sync(notes)
return result.outputAnd if the notes have no action items? Does the agent return an empty list?
PydanticAI validates the type, not the length. An empty list is a valid list[str]. The agent returns [] when the input has nothing actionable — which is the correct answer and what your downstream code should expect.
So the extractor is one call, one typed list out, ready to feed straight into a task-creation API on the next line of my script?
Ready to pipe. Typed extraction plus a seeded destination is the shape of every "read notes, create records" automation. One agent call, one list, one write call — the whole pattern fits on a screen.
TL;DR: result_type=list[str] plus a narrow system_prompt extracts actionable items with zero parsing.
system_prompt — "extract action items as a short list"result_type=list[str] — forces a typed list[]| Knob | Controls |
|---|---|
system_prompt | what the agent picks |
result_type | what shape it returns |
Typed extraction is the cleanest bridge between free prose and a downstream write API.
Create a free account to get started. Paid plans unlock all tracks.