Certopolis

Claude Certified Architect – Foundations

Programmatic tool calling and allowed_callers

Programmatic tool calling lets Claude write Python that calls your tools inside the code execution container, instead of one model round trip per call. Add "allowed_callers": ["code_execution_20260120"] to a tool and include code execution version code_execution_20260120 or later.

How it works

Claude writes code that calls your tool as an async Python function. When the code reaches a call, it pauses and the API returns stop_reason: "tool_use" with a tool_use block whose caller field names the code execution run. You run the tool and send back a tool_result. The code resumes and may pause again. When it finishes, Claude gets the final output and continues.

On each continuation, send the container id from the paused response, or the API rejects the request. Send the same tools array. The user message must contain only tool_result blocks, with no text, and each result's content must be a string or text blocks.

Why use it

Results from programmatic calls go to the running code, not into Claude's context, and they do not count toward input or output token usage. Only the final code output and Claude's response do. Checking 20 employees' budgets becomes one script that runs 20 lookups and returns only the employees over their limit. It fits fan-out work and large results that can be filtered. It fits poorly when each call depends on Claude reasoning over the previous result.

Limits

A pending call times out after about 4 minutes and raises TimeoutError inside the code, which Claude usually retries. Split long operations into smaller pieces that return well inside that window. Idle containers are reclaimed after about 5 minutes.

Tools with strict: true are not supported. You cannot force a programmatic call through tool_choice, disable_parallel_tool_use: true is not supported, and MCP connector tools cannot be called from code. A schema with a recursive $ref fails with Circular $ref detected; keep that tool direct-only. allowed_callers guides Claude but is not a security boundary.

Where the exam catches people

  • Believing strict: true can be added to a programmatically called tool: the two are incompatible.
  • Believing a continuation can be rebuilt from message history alone: the container id is required while a call is pending.
  • Believing allowed_callers blocks direct calls: it only guides Claude, so your client should still handle a direct tool_use.
  • Believing programmatic tool results are billed as input tokens: only the final code output and Claude's response count.

Written from Anthropic's documentation

Try 3 questions on this

Pick an answer to see why each option is right or wrong.

  1. You have programmatic tool calling working on Claude Sonnet 5 (claude-sonnet-5) and now want the same custom tool to also carry a hard schema-conformance guarantee, so a compliance reviewer asks whether strict: true can simply be added to that tool definition. How should you evaluate this proposal?

    Right. In the game that’s Renown for your Tool Design, MCP and Server Tools building.

    Not that one: D is right. In the game your Tool Design, MCP and Server Tools building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    When the sandbox is orchestrating calls, schema conformance has to be enforced by validating in the tool implementation and returning tool_result with is_error: true on a violation.

    Written from platform.claude.com/docs/en/agents-and-tools/tool-use/programmatic-tool-calling

  2. Your service uses programmatic tool calling on Claude Opus 5 (claude-opus-5). Claude's code calls query_database, and the API returns a tool_use block whose caller names the code execution run. Your client answers with a tool_result in a request rebuilt from the stored message history alone, and the API rejects it. What is the most likely cause?

    Right. In the game that’s Renown for your Tool Design, MCP and Server Tools building.

    Not that one: C is right. In the game your Tool Design, MCP and Server Tools building would lose a little Renown, and this question would come back later.

  3. Your Claude Opus 5 (claude-opus-5) service enables programmatic tool calling over a warehouse query tool. Some queries take six to eight minutes. Those runs come back with TimeoutError: Calling tool ['run_query'] timed out in stderr, a return_code of 0, and Claude retrying the same call. What change would most effectively resolve the issue?

    Right. In the game that’s Renown for your Tool Design, MCP and Server Tools building.

    Not that one: C is right. In the game your Tool Design, MCP and Server Tools building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    The documented remedy is to break long operations into smaller chunks that return well before that limit.

    Written from platform.claude.com/docs/en/agents-and-tools/tool-use/programmatic-tool-calling