← AI GitHub

AI GitHub

Pydantic AI for typed agent applications

Build Python agents with typed dependencies, tools and model outputs.

Language ModelsPublished 2 min read

Key Takeaways

  • The agent binds a model to functions it may call and to an output contract.
  • Define the model and tool interface separately from the dependencies supplied at run time.
  • Write a read-only lookup tool and test the agent with a fake or test model before connecting a real provider.
  • Types constrain the shape of data crossing a boundary.

How it works

The agent binds a model to functions it may call and to an output contract. Typed dependencies let application code pass resources into tools while keeping those details out of the model prompt.

What you need

Define the model and tool interface separately from the dependencies supplied at run time. A read-only test dependency helps exercise the same application code without calling a production service.

What to try first

Write a read-only lookup tool and test the agent with a fake or test model before connecting a real provider. Include a malformed tool request and an unavailable record.

Return an error from the fixture lookup and confirm which details reach the model. Use that test to keep internal exceptions and credentials outside prompts.

Where to look for failures

Types constrain the shape of data crossing a boundary. Application code still owns authorization, resource limits and the consequences of letting a model choose which tool to call.

Related Franklin pages

Test both a valid structured response and one that requires recovery. A good application contract specifies what happens after the allowed attempts are exhausted.

For the distinction between requesting structured output and enforcing its format, see Franklin’s glossary. Structured output

Project documentation

Try it for your workflow

Explore the project’s documentation for setup and usage, or save this page to a collection for later.

Read the project documentation ↗