# Structured output

```python
from pydantic import BaseModel
from langchain.agents import create_agent
from langchain.agents.structured_output import ToolStrategy, ProviderStrategy

class Weather(BaseModel):
    temperature: float
    condition: str

agent = create_agent(
    "gpt-5.4-mini",
    tools=[weather_tool],
    response_format=ToolStrategy(Weather),
)

result = agent.invoke({"messages": [{"role": "user", "content": "Weather in SF?"}]})
print(repr(result["structured_response"]))  # Weather(temperature=70.0, condition='sunny')
```

## Rules

- ToolStrategy: the model calls a synthetic tool to produce the structure. ProviderStrategy: uses the provider's native structured output. Prefer provider-native when the provider supports it well.
- Control failure behavior with the `handle_errors` parameter on the strategy: parsing errors (model output does not match the schema) and multiple tool calls for the schema need a policy, not a crash.
- The old prompted tuple form `response_format=("please generate ...", Schema)` is removed in v1. Migrate it.
- This replaces output parsers for the agent case. Parsers still exist for plain LCEL chains.