# Structured Output Strict Tools (/examples/models/anthropic/structured-output-strict-tools)



The local `get_weather` function returns fixed demonstration data. It does not retrieve actual weather. Agno normalizes the strict tool schema at initialization, making both `location` and `unit` required in the outgoing request even though the original schema below lists only `location`. This is Agno's schema transformation; Anthropic also supports optional tool properties.

```python title="structured_output_strict_tools.py"
"""Example demonstrating strict tool use with Anthropic structured outputs.

Strict tool use ensures that tool parameters strictly follow the input_schema.
"""

from agno.agent import Agent
from agno.models.anthropic import Claude
from agno.tools import Function
from pydantic import BaseModel

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------


class WeatherInfo(BaseModel):
    """Structured output schema for weather information."""

    location: str
    temperature: float
    unit: str
    condition: str


def get_weather(location: str, unit: str = "celsius") -> str:
    temp = 72 if unit == "fahrenheit" else 22
    return f"Weather in {location}: {temp}°{unit}, Sunny"


# Create function with strict mode enabled
weather_tool = Function(
    name="get_weather",
    description="Get current weather information for a location",
    parameters={
        "type": "object",
        "properties": {
            "location": {
                "type": "string",
                "description": "The city and state, e.g. San Francisco, CA",
            },
            "unit": {
                "type": "string",
                "enum": ["celsius", "fahrenheit"],
                "description": "Temperature unit",
            },
        },
        "required": ["location"],
        "additionalProperties": False,
    },
    strict=True,  # Enable strict mode for validated tool parameters
    entrypoint=get_weather,
)

# Agent with both structured outputs and strict tool
agent = Agent(
    model=Claude(id="claude-sonnet-4-5-20250929"),
    tools=[weather_tool],
    output_schema=WeatherInfo,
    description="You help users get weather information.",
)

# The agent will use strict tool validation and return structured output
agent.print_response("What's the weather like in San Francisco?")

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    pass
```

<Note>
  `output_schema` describes the expected type. If parsing or validation fails, `result.content` can remain a string. Before accessing schema fields in a run result, use `isinstance(result.content, YourSchema)`, replacing `YourSchema` with the class you passed as `output_schema`.
</Note>

## Run the Example [#run-the-example]

<Steps>
    <Step title="Set up your virtual environment">
      <CodeBlockTabs defaultValue="Mac">
        <CodeBlockTabsList>
          <CodeBlockTabsTrigger value="Mac">
            Mac
          </CodeBlockTabsTrigger>

          <CodeBlockTabsTrigger value="Windows">
            Windows
          </CodeBlockTabsTrigger>
        </CodeBlockTabsList>

        <CodeBlockTab value="Mac">
          ```bash
          uv venv --python 3.12
          source .venv/bin/activate
          ```
        </CodeBlockTab>

        <CodeBlockTab value="Windows">
          ```bash
          uv venv --python 3.12
          .venv\Scripts\activate
          ```
        </CodeBlockTab>
      </CodeBlockTabs>
    </Step>

  <Step title="Install dependencies">
    ```bash
    uv pip install -U agno anthropic
    ```
  </Step>

  <Step title="Export your Anthropic API key">
    <CodeBlockTabs defaultValue="Mac/Linux">
      <CodeBlockTabsList>
        <CodeBlockTabsTrigger value="Mac/Linux">
          Mac/Linux
        </CodeBlockTabsTrigger>

        <CodeBlockTabsTrigger value="Windows">
          Windows
        </CodeBlockTabsTrigger>
      </CodeBlockTabsList>

      <CodeBlockTab value="Mac/Linux">
        ```bash
        export ANTHROPIC_API_KEY="your_anthropic_api_key_here"
        ```
      </CodeBlockTab>

      <CodeBlockTab value="Windows">
        ```powershell
        $Env:ANTHROPIC_API_KEY="your_anthropic_api_key_here"
        ```
      </CodeBlockTab>
    </CodeBlockTabs>
  </Step>

  <Step title="Run the example">
    Save the code above as `structured_output_strict_tools.py`, then run:

    ```bash
    python structured_output_strict_tools.py
    ```
  </Step>
</Steps>

Full source: [cookbook/90\_models/anthropic/structured\_output\_strict\_tools.py](https://github.com/agno-agi/agno/blob/8f36eaf2d18e91afa7b327eec66a3cd3685dcb87/cookbook/90_models/anthropic/structured_output_strict_tools.py)
