What this thread does
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:
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:
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:
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, 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.
Started from a post by @LangChain, packaged by the editor. Original post