Use Pydantic models to validate and parse LLM outputs into predictable structures.

Single Agent

from pydantic import BaseModel

class CalendarEvent(BaseModel):
  name: str
  date: str
  participants: list[str]

event = agent.generate(
  "Alice and Bob are going to a science fair on Friday.",
  response_model=CalendarEvent,
)
print(event)

Workflow Final Step

from pydantic import BaseModel
class KeyDifferences(BaseModel):
  title: str
  points: list[str]
  summary: str

final = wf.run("Explain fission vs fusion", response_model=KeyDifferences)