> ## Documentation Index
> Fetch the complete documentation index at: https://docs.definable.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Agent with Structured Output

> Return typed Pydantic models from agent responses.

Return structured data from an agent by passing an `output_schema`.

<Steps>
  <Step title="Create the agent">
    ```python agent_structured.py theme={null}
    import asyncio
    from pydantic import BaseModel, Field
    from definable.agent import Agent

    class MovieReview(BaseModel):
        title: str = Field(description="Movie title")
        rating: float = Field(description="Rating out of 10")
        summary: str = Field(description="Brief summary")
        pros: list[str] = Field(description="Positive aspects")
        cons: list[str] = Field(description="Negative aspects")

    agent = Agent(
        model="gpt-4o",
        instructions="You are a movie critic. Provide structured reviews.",
    )

    async def main():
        output = await agent.arun(
            "Review the movie Inception",
            output_schema=MovieReview,
        )
        review = output.parsed  # MovieReview instance
        print(f"{review.title}: {review.rating}/10")
        print(f"Summary: {review.summary}")
        for pro in review.pros:
            print(f"  + {pro}")
        for con in review.cons:
            print(f"  - {con}")

    asyncio.run(main())
    ```
  </Step>

  <Step title="Install dependencies">
    <Snippet file="install-definable.mdx" />
  </Step>

  <Step title="Export your API key">
    <Snippet file="export-openai-key.mdx" />
  </Step>

  <Step title="Run">
    ```bash theme={null}
    python agent_structured.py
    ```

    The agent returns a validated `MovieReview` Pydantic model.
  </Step>
</Steps>

<Warning>
  Use `output_schema=`, not `response_model=`. The `response_model` parameter does not exist.
</Warning>
