Skip to main content
Pydantic AI is the official agent framework by the Pydantic team. It supports typed structured output via output_type and works with any OpenAI-compatible endpoint. For dottxt, output_type is the important integration point: Pydantic AI derives JSON Schema from your output model, sends that schema through the OpenAI-compatible API, and parses the result back into a typed object.

Install

Configure

Create an OpenAIProvider pointed at dottxt, then wrap it in an OpenAIChatModel:

Basic usage

Pass a Pydantic model as output_type to get typed structured output:
Pydantic AI generates the schema from output_type and parses the response back into result.output. Under the hood, this still uses the same dottxt structured generation flow described in API Overview and Pydantic Authoring.

Agent with dependencies and tools

Use deps_type to inject runtime context, and @agent.tool to give the agent callable functions:

Notes

  • Use output_type, not result_type; the latter was removed in Pydantic AI v0.6.0.
  • agent.run() is async, agent.run_sync() is synchronous, agent.run_stream() is async streaming.
  • The result is accessed via result.output, typed according to output_type.
  • ConfigDict(extra="forbid") is useful when you want additionalProperties: false in the generated schema.
  • See the Pydantic authoring guide for how to write effective schemas.