-
Notifications
You must be signed in to change notification settings - Fork 976
Description
Type of issue
issue / bug
Language
Python
Description
Problem
The documentation gives two mutually exclusive statements about how to request structured output from an agent in LangChain ≥1.0.
Page: provider_strategy
As of langchain 1.0, simply passing a schema (e.g., response_format=ContactInfo) is no longer supported. You must explicitly use ToolStrategy or ProviderStrategy.
Page: response-format
Response Format
Controls how the agent returns structured data:
- ToolStrategy[StructuredResponseT]: Uses tool calling for structured output
- ProviderStrategy[StructuredResponseT]: Uses provider-native structured output
- type[StructuredResponseT]: Schema type - automatically selects best strategy based on model capabilities
- None: No structured output
When a schema type is provided directly, LangChain automatically chooses:
- ProviderStrategy for models supporting native structured output (e.g. OpenAI, Grok)
- ToolStrategy for all other models
The structured response is returned in the structured_response key of the agent’s final state.
Evidence (repro)
Running the following snippet today (2025-11-21) with langchain==1.0.8 (latest):
class Mood(BaseModel):
mood: str = Field(..., description="LLM simulates mood from user message")
agent = create_agent(model, [], response_format=Mood)
resp = agent.invoke({"messages": "Hello!"})
print(resp["messages"][-1])
Output contains a valid tool call and returns the expected structure:
content="Returning structured response: mood='friendly'" name='Mood' id=... tool_call_id='call_...'
No exception is raised, confirming that passing response_format=Mood (a schema type) is still accepted.
Suggested fix
Update the first page (provider_strategy) to align with the second page:
- Remove the claim that “passing a schema directly is no longer supported.”
- Clarify that supplying only a schema type is shorthand for “auto-select best strategy,” not deprecated.
Environment
langchain==1.0.8
Python 3.11.9