Skip to content

WebSearchTool max_uses parameter ignored in Anthropic model integration #2555

@eballesteros

Description

@eballesteros

Initial Checks

Description

max_uses appears both as a parameter in WebSearchTool and in the anthropic docs as a mechanism to limits the number of searches performed, but at the moment has no effect.

When a WebSearchTool with max_uses specified is passed to an Anthropic model, the parameter is not forwarded to the underlying BetaWebSearchTool20250305Param, causing the limitation to have no effect.

In .../models/anthropic.py at lines 355-375, the _get_builtin_tools method processes WebSearchTool instances but only forwards allowed_domains, blocked_domains, and user_location to the Anthropic API parameter object. The max_uses field is omitted.

If I'm not mistaken, it should be a 1 line change. I'd be happy to open a PR.

Example Code

import asyncio

from pydantic_ai import Agent
from pydantic_ai.models.anthropic import AnthropicModel
from pydantic_ai.builtin_tools import WebSearchTool


async def main():
    agent = Agent(
        model=AnthropicModel('claude-sonnet-4-20250514'),
        builtin_tools=[WebSearchTool(max_uses=1)],
        instructions="You are a helpful assistant. Use web search to answer questions."
    )

    result = await agent.run("What is the birthdate of the CEO of the most valuable company in the S&P 500 as of July 2025?")

    print(result.output)

asyncio.run(main())

Python, Pydantic AI & LLM client version

Python 3.12.8
pydantic-ai-slim 0.7.1
anthropic 0.64.0

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions