-
Notifications
You must be signed in to change notification settings - Fork 1
Add example: agent with structured output validation (Pydantic) #10
Copy link
Copy link
Open
Labels
good first issueGood for newcomersGood for newcomers
Description
Summary
Create an example that demonstrates using Pydantic models to validate and enforce structured output from an OpenSymbolicAI agent. Shows how to guarantee the agent returns data in a specific schema.
What needs to happen
- Create
structured_output/directory - Define a Pydantic model for the expected output (e.g.,
ExtractedContactwith name, email, phone) - Create an agent that extracts structured data from unstructured text
- Validate the agent's output against the Pydantic model
- Handle validation errors gracefully (retry or report)
- Add README explaining the pattern
Example
from pydantic import BaseModel
from opensymbolicai import Agent
class Contact(BaseModel):
name: str
email: str
phone: str | None
agent = Agent(
goal="Extract contact info from this text",
output_schema=Contact
)
result = agent.run(input="Call John at john@example.com or 555-1234")
print(result) # Contact(name='John', email='john@example.com', phone='555-1234')Acceptance criteria
- Output is validated against a Pydantic model
- Invalid outputs are caught and handled
- README explains when and why to use structured output
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
good first issueGood for newcomersGood for newcomers