Structured Email Extraction with Instructor

Use Instructor's Pydantic-powered structured outputs to extract email data from natural language, then send through MultiMail with configurable human oversight.


Instructor is a library for getting structured outputs from LLMs using Pydantic models. It patches LLM client libraries to return validated, typed objects instead of raw text, with automatic retry on validation failure. MultiMail provides the email delivery infrastructure that turns Instructor's structured email data into actual sent messages.

The combination is powerful: Instructor extracts structured email fields (recipients, subject, body, urgency) from natural language requests, validates them with Pydantic, and MultiMail handles the delivery with human oversight. This ensures emails are both well-structured and appropriately reviewed before sending.

Integrate Instructor with MultiMail by defining Pydantic models for email data, extracting structured content with Instructor, and calling the MultiMail REST API to send. No special SDK required — just Pydantic models and HTTP requests.

Built for Instructor developers

Validated Email Structure

Instructor ensures the LLM produces valid email data — proper email addresses, non-empty subjects, appropriate body length — through Pydantic validation with automatic retries on failure.

Natural Language to Email

Users describe what they want to send in natural language. Instructor extracts the structured email fields, validates them, and MultiMail delivers the result. The entire pipeline is type-safe and validated.

Automatic Retry on Validation Failure

If the LLM produces an invalid email structure (missing fields, bad format), Instructor automatically retries with the validation error as feedback. This self-healing loop produces reliable email data without manual intervention.

Human Oversight After Extraction

Instructor ensures emails are well-structured, but cannot judge appropriateness. MultiMail's gated_send mode adds human review after extraction, catching issues that structural validation misses.

Multi-Provider Support

Instructor patches multiple LLM providers (OpenAI, Anthropic, Cohere, Mistral). Use any supported provider for email extraction while MultiMail handles delivery consistently across all of them.


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 before coding: read https://multimail.dev/llms.txt, connect the MultiMail MCP server to this agent, create a free inbox for testing, and set up a verified sending domain. Use only the capabilities exposed by the connected MCP server for inbox creation, composing, sending, scheduling, and oversight modes. 2. Wire MultiMail into my Instructor flow using Instructor’s Pydantic structured-output mechanism. Define Pydantic models for EmailIntent, InboxCheck, DraftReply, and SendRequest, then use an Instructor client with response_model and validation retries to extract recipients, subject, body, reply context, urgency, and whether the action should be inbox_check, draft_reply, send, or schedule from natural language. 3. Give the agent three capabilities backed by MultiMail MCP tools: inbox-check reads recent messages from the test inbox, draft-reply turns a selected message plus user instruction into a Pydantic-validated reply draft, and send uses the verified sender to compose or schedule the validated email through MultiMail. Do not call any email capability unless the structured Instructor output validates. 4. Send a test email through the verified sender to the free test inbox. Then run inbox-check, extract the received message into the Pydantic email model, generate a draft reply, and prepare the reply for sending. 5. Run everything in MultiMail gated_send oversight mode for this quickstart. Before any send or schedule action, show me the validated recipient, subject, body, and reason for sending, then wait for my explicit approval. Do not switch to monitored or autonomous mode until I ask.

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 Instructor, an LLM client library, and requests for calling the MultiMail API.

3

Define Email Models

Create Pydantic models for email data with field validators for content quality checks.

4

Extract and Send

Use Instructor to extract structured email data from natural language, then send through MultiMail's REST API.

5

Review Pending Emails

If using gated_send mode (the default), approve or reject pending emails in the MultiMail dashboard before delivery.


Common questions

How does Instructor's validation help with email quality?
Instructor validates the LLM's output against your Pydantic model, ensuring fields like email addresses, subject lines, and body content meet your criteria. If validation fails, Instructor automatically retries with the error as feedback, so the LLM corrects its output. This ensures every email sent to MultiMail is well-structured.
Can I use Instructor with models other than OpenAI?
Yes. Instructor supports multiple LLM providers including Anthropic, Cohere, Mistral, and others. The email extraction pattern works the same regardless of provider — define your Pydantic models, patch the client with Instructor, and extract structured data. MultiMail's REST API is provider-agnostic.
What's the difference between Instructor validation and MultiMail oversight?
Instructor validation ensures emails are structurally correct — valid addresses, non-empty fields, appropriate length. MultiMail's oversight ensures emails are contextually appropriate — right recipients, suitable tone, correct timing. Validation is automatic and instant; oversight involves human judgment.
Can I extract and send multiple emails in one request?
Yes. Use Instructor's Iterable response type to extract multiple EmailDraft objects from a single natural language request. Then iterate and send each through MultiMail's API. In gated_send mode, each email queues separately for individual approval.
How do I handle extraction failures?
Set max_retries on Instructor's create call. When the LLM produces output that fails Pydantic validation, Instructor sends the validation error back to the LLM and retries. After exhausting retries, it raises a ValidationError. Your application can catch this and inform the user that the request couldn't be parsed into a valid email.

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.