Type-Safe Email Agents with Pydantic AI

Combine Pydantic AI's type safety and dependency injection with MultiMail's email infrastructure for validated, reliable email agents with human oversight.


Pydantic AI is an agent framework built on Pydantic that brings type safety and validation to LLM interactions. It uses dependency injection for tools and provides structured, validated outputs from agents. MultiMail provides the email infrastructure that Pydantic AI agents need to actually send, receive, and manage messages with production reliability.

By integrating MultiMail with Pydantic AI, you get type-safe email operations where tool inputs and outputs are validated by Pydantic models. The dependency injection pattern makes it clean to pass MultiMail API credentials and configuration to your tools without global state. MultiMail's gated_send mode adds human judgment on top of type validation.

Connect Pydantic AI to MultiMail by defining tool functions with type-annotated parameters and using dependency injection to provide API configuration. The framework validates all inputs and outputs automatically.

Built for Pydantic AI developers

Type-Safe Email Operations

Pydantic AI validates tool inputs with Pydantic models. Define typed schemas for email recipients, subjects, and bodies, ensuring your agent always sends well-structured API requests to MultiMail.

Dependency Injection for Configuration

Pass MultiMail API keys, mailbox IDs, and configuration through Pydantic AI's dependency injection system. No global state or environment variable hacks — clean, testable configuration management.

Result Validators Plus Oversight

Pydantic AI's result validators ensure structured output, but cannot prevent a well-structured but inappropriate email. MultiMail's oversight adds human judgment at the delivery layer, catching what validators miss.

Structured Email Responses

Define result types for email operations — classification results, draft summaries, delivery status — all validated by Pydantic models. Your application code gets typed objects, not raw strings.

Testable Email Agents

Pydantic AI's dependency injection makes it easy to test email agents with mock MultiMail responses. Swap the real API client for a test double without changing agent logic.


Try it with your agent

No code, no dashboard. Paste this to your AI agent — it connects MultiMail, creates an inbox, and builds the flow for you.

1. Get MultiMail ready: read https://multimail.dev/llms.txt, connect the MultiMail MCP server in your agent environment, create a free inbox, and set up a verified sending domain so the agent can receive and send email. 2. Wire MultiMail into your Pydantic AI agent using Pydantic AI tools: define typed tool functions with the @agent.tool decorator and use RunContext dependencies for any MultiMail client/session objects your MCP setup exposes to the agent. 3. Give the agent three explicit capabilities: check the MultiMail inbox for recent messages, draft a validated reply for developer review, and send or schedule email through MultiMail only when the requested action is allowed. 4. Send a test email to the new inbox, run the Pydantic AI agent, have it inspect the inbox, produce a reply draft, and confirm the draft includes the intended recipient, subject, and body before sending. 5. Run MultiMail in gated_send oversight mode for development and production launch so every outbound or scheduled email pauses for human review before MultiMail sends it; move to monitored or autonomous only after the behavior is proven safe.

Step by step

1

Create a MultiMail Account and API Key

Sign up at multimail.dev, create a mailbox, and generate an API key. Your key will start with mm_live_.

2

Install Dependencies

Install Pydantic AI and requests for calling the MultiMail API.

3

Define Dependencies and Result Types

Create a dataclass for email dependencies (API key, mailbox ID) and a Pydantic model for structured results.

4

Register Tools

Decorate functions with @agent.tool that accept RunContext[EmailDeps] and call MultiMail API endpoints with the injected configuration.

5

Run and Review

Execute the agent with your dependencies. Review pending emails in the MultiMail dashboard when using gated_send mode.


Common questions

How does dependency injection help with MultiMail integration?
Dependency injection passes your MultiMail API key and mailbox configuration to tool functions through the RunContext, avoiding global state. This makes your agent testable — swap in mock dependencies for testing without changing tool logic — and cleanly separates configuration from behavior.
What's the benefit of typed results for email agents?
Typed results (like EmailResult with summary and actions_taken fields) give your application code structured data instead of raw strings. You can programmatically check what actions the agent took, display summaries in a UI, or feed results into downstream processing — all with type safety and IDE autocomplete.
How do result validators interact with MultiMail's oversight?
Result validators check the agent's output structure and quality, triggering retries if the output is insufficient. MultiMail's oversight checks whether emails should actually be delivered. They operate at different levels: validators ensure the agent reasons well, oversight ensures emails are appropriate to send.
Can I test my email agent without sending real emails?
Yes. Create a mock EmailDeps that returns test responses instead of calling the real API. Pydantic AI's dependency injection makes this straightforward. You can also use MultiMail's staging environment with the gated_send mode to test real API calls without delivering emails.
Does Pydantic AI support async email operations?
Yes. Pydantic AI is async-native with agent.run() being an async function. Use httpx or aiohttp in your tool functions for async HTTP calls to the MultiMail API. The framework handles the async execution lifecycle automatically.

Explore more

The only agent email with a verifiable sender

Email infrastructure built for AI agents. Verifiable identity, graduated oversight, and a hosted MCP server. Formally verified in Lean 4.