🧬Pydantic AI
Also known as PydanticAI, pydantic-ai
A Python kit for agents. It gives back answers as checked, typed data.
Think of it like
It is like a form with boxes. The answer must fit each box, or it goes back.
Example
Emma needs each invoice's date, total and seller as fields. She sets the output type to an Invoice model, so bad data fails at once instead of later.
Why it matters
Apps need data they can trust, not loose text. Typed output catches a wrong shape at the edge of your code.
Definition
Example code
python
from pydantic_ai import Agent
agent = Agent("openai:gpt-6.1-sol")
result = agent.run_sync("Say hello.")
print(result.output)Common mistake
Key takeaways
- 1Typed output. Answers fit a Pydantic model.
- 2Model as a name. Provider and model in one string.
- 3A test model. Runs without a real AI.