> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Agent with Structured Outputs

> Return a validated Pydantic object from a Claude agent.

Set `output_schema` to return a validated Pydantic object instead of free-form text.

## Code

```python structured_output.py theme={null}
from agno.agent import Agent, RunOutput
from agno.models.anthropic import Claude
from pydantic import BaseModel, Field


class MovieScript(BaseModel):
    name: str = Field(description="Movie title")
    genre: str
    characters: list[str]
    storyline: str = Field(description="Three-sentence storyline")


movie_agent = Agent(
    model=Claude(id="claude-sonnet-4-6"),
    description="You help people write movie scripts.",
    output_schema=MovieScript,
)

if __name__ == "__main__":
    run: RunOutput = movie_agent.run("Write a thriller set in New York.")
    movie = run.content

    assert isinstance(movie, MovieScript)
    print(movie.model_dump_json(indent=2))
```

`run.content` is a `MovieScript` instance after Claude returns valid JSON and Agno validates it against the schema.

> [!NOTE]
>
> Agno 2.7.2 translates `output_schema` to Anthropic's legacy-compatible `output_format` request and adds the `structured-outputs-2025-11-13` beta automatically. Anthropic's current direct API uses `output_config.format`; the legacy request remains available during Anthropic's migration period. Let Agno populate the request field when you use `output_schema`.

Anthropic lists Claude Sonnet 4.6 as supporting structured outputs. Refusals and responses stopped at `max_tokens` can end without a schema-valid result. Anthropic JSON outputs are also incompatible with citations and message prefilling; Agno disables document citations for these requests.

## Usage

<Snippet file="create-venv-step.mdx" />

**1. Install dependencies**

```bash theme={null}
uv pip install -U "agno[anthropic]"
```

**2. Export your Anthropic API key**

```bash Mac/Linux theme={null}
export ANTHROPIC_API_KEY="your_anthropic_api_key_here"
```

```powershell Windows theme={null}
$Env:ANTHROPIC_API_KEY="your_anthropic_api_key_here"
```

**3. Run the agent**

Save the code above as `structured_output.py`, then run:

```bash theme={null}
python structured_output.py
```

## Developer Resources

* [Streaming structured outputs](https://agno-v2.mintlify.site/models/providers/native/anthropic/usage/structured-output-stream.md)
* [Structured outputs with strict tools](https://agno-v2.mintlify.site/models/providers/native/anthropic/usage/structured-output-strict-tools.md)
* [Anthropic structured outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.