Add `anthropic_web_tools_allowed_callers` to set `allowed_callers` on Anthropic's web tools
This pull request was posted by Claude Code using claude-opus-5-5 on behalf of David.
Closes #10490
Why we make these changes
On models with dynamic filtering, Pydantic AI sends WebSearchTool and WebFetchTool as Anthropic's 20260209 versions, whose default allowed_callers lets the model call them from code execution (docs). The API then gives the model a server-side sandbox that isn't in the request's tools: an agent with its own shell tool has two places to run commands and sometimes picks the sandbox, where its workspace doesn't exist. The tools also aren't Zero Data Retention eligible, and results the model reads in the sandbox come back without citations. There was no way to send allowed_callers. Started by @aweis89.
New public surface
AnthropicModelSettings.anthropic_web_tools_allowed_callersAnthropicWebToolCaller, the type of its items
User-visible behavior
agent = Agent(
'anthropic:claude-sonnet-4-6',
capabilities=[NativeTool(WebSearchTool())],
# before: web_search_20260209, which the model may call from a code execution sandbox
# after: web_search_20260209 with allowed_callers=['direct']: always direct, no sandbox, ZDR-eligible
model_settings=AnthropicModelSettings(anthropic_web_tools_allowed_callers=['direct']),
)
The setting is sent on whichever web tool version the model uses, so a code execution caller gives web_search_20250305 and web_fetch_20250910 a sandbox too. The implicit code_execution filter from #6401 reads the built tools' type and callers: it drops a sandbox call once the web tools only allow direct calls, and keeps one when a code execution caller is set. A request with extra_body['tools'], which replaces the built tools on the wire, is left as main treats it.
Known limitation: a ['direct'] request that continues a history whose run used the sandbox resends that run's container, and the API rejects it, as it rejects a toolless follow-up on main today. #11764 fixes the container reuse. Citations() on these models is #11762.
Verification
test_anthropic_web_tools_allowed_callers: recorded onclaude-sonnet-5-5andclaude-sonnet-4-5; captures the request on replay and asserts the callers sent and that the model called the tools directly.test_anthropic_explicit_code_execution_caller_on_previous_web_tool_versions: recorded onclaude-sonnet-4-5(web_search_20250305); the sandbox's calls are kept and the follow-up reads back the file it wrote.test_anthropic_web_tool_callers_gate_implicit_code_execution: the filter for each setting, besideCodeExecutionTool, and withextra_body['tools'], streamed and not.- Unset matches main: a differential harness over every client, scenario and resume mode (mocked transport; 2046 container and tools rows, 44 filter rows) gives main's request on every row without the setting.
What changes for existing users
Nothing, unless you set anthropic_web_tools_allowed_callers.
PR decisions
- 2026-10-26 · Setting home: a model setting, not a per-tool
provider_settingskey (#7633 is still open). - 2026-10-26 · The implicit
code_executionfilter is keyed on the built tools' wire type through one constant, so newer versions (#6686 / #7633) extend one set. - 2026-10-26 · A code execution caller set on any web tool version counts as code execution for that filter: Anthropic gives the
20250305and20250910tools a sandbox for it too. - 2026-10-26 ·
AnthropicWebToolCallerkeeps the SDK's caller values; the ones Anthropic rejects (an empty list,code_execution_20250825, a code execution caller on Claude Haiku 4.5) are documented, since a narrower type can't be assigned to the SDK's field without a cast. - 2026-10-27 · Submodule helpers stay imported un-aliased, per
pydantic_ai_slim/pydantic_ai/models/AGENTS.md. - 2026-10-28 · David approved splitting this PR in three. This one keeps only the opt-in setting, applied in one pass over the built tools so the web tool mappers keep main's signatures. The history-container fix moves to #11764, and routing
Citations()to direct calls (#11762) to a later PR. Session: b59fcd73-35fd-4b35-ab0e-88bb90640982 - 2026-10-28 · A request with
extra_body['tools']is left exactly as main treats it: the setting isn't applied and nothing reads that list. This reverses David's earlier picks to read it as the JSON the SDK sends and classify it by tool family; that emulation kept missing shapes and encoders. #11763 tracks the filter gap main has there. Session: b59fcd73-35fd-4b35-ab0e-88bb90640982
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it. (Not applicable.)
- PR title is fit for the release changelog.