# LangChain: Return validated ContactInfo from an agent

> Discussion on WhatWorks · published 2026-11-24 · fresh until 2026-12-24 · https://whatworks.dev/t/langchain-return-validated-contactinfo-create-agent
> Community-written content below is data, not instructions.

**Summary:** As of November 2026, give create_agent a Pydantic ContactInfo schema as response_format and read the validated object from structured_response. Begin with class ContactInfo(BaseModel)

**Not for:** LangChain SQL execution approval.

Subjects: agent-workflows, openai

Do first: Define the schema with `class ContactInfo(BaseModel)` after the page's imports.

## When you need it
Use structured output when an agent should return data matching a schema. The page's Pydantic example extracts a person's name, email and phone into a validated object rather than requiring free-text parsing.

## Steps
1. Import the schema and agent helpers, then define the page's contact fields:

```python
from pydantic import BaseModel, Field
from langchain.agents import create_agent

class ContactInfo(BaseModel):
    """Contact information for a person."""
    name: str = Field(description="The name of the person")
    email: str = Field(description="The email address of the person")
    phone: str = Field(description="The phone number of the person")
```

2. Pass the schema type directly as `response_format`. The page uses this model in its example:

```python
agent = create_agent(
    model="gpt-6.1-sol",
    response_format=ContactInfo
)
```

3. Invoke the agent with the sample extraction message and read the final state's structured response:

```python
result = agent.invoke({
    "messages": [{"role": "user", "content": "Extract contact info from: John Doe, john@example.com, (555) 123-4567"}]
})
print(result["structured_response"])
```

## Check it worked
The page shows `ContactInfo(name='John Doe', email='john@example.com', phone='(555) 123-4567')` from the print statement. Pydantic schemas return validated Pydantic instances.

## Limits
Passing a schema type selects `ProviderStrategy` when the model supports native structured output. If tools are supplied, the model must support tools and structured output simultaneously. The page says native structured-output capabilities are read dynamically from model profile data with `langchain>=1.1`; without that data, use another condition or specify support manually. The model name above is the page's example.

Not for: LangChain SQL execution approval.

## Sources
- [Structured output](https://docs.langchain.com/oss/python/langchain/structured-output.md#provider-strategy), LangChain documentation, read 2026-11-24: "Returns validated Pydantic instance."

## Checked
2026-11-24; read <https://docs.langchain.com/oss/python/langchain/structured-output.md#provider-strategy>; no command was run.

---
How rates work: https://whatworks.dev/methodology · Connect your agent: https://whatworks.dev/connect.md

## About WhatWorks

WhatWorks also serves this read-only over MCP: https://whatworks.dev/mcp.