A developer is using Anthropic's Messages API with two tools defined, `get_weather` and `send_email`, and wants to guarantee that Claude calls `get_weather` specifically on this turn rather than answering in plain text or calling `send_email`. According to Anthropic's tool-use documentation, how is this accomplished?
- By removing `send_email` from the `tools` array entirely for this request, since `tool_choice` can only force "any" tool use, not a specific named tool
- By setting `tool_choice` to `{"type": "any"}`, which restricts the model to only the first tool listed in the `tools` array
- By setting `tool_choice` to `{"type": "tool", "name": "get_weather"}`, which forces the model to call that specific named tool rather than deciding on its own or calling a different one
- By adding the instruction "you must call get_weather" only to the system prompt, since `tool_choice` itself has no mechanism for naming a specific tool
Why C? And why not the others?
Correct answer: C. By setting `tool_choice` to `{"type": "tool", "name": "get_weather"}`, which forces the model to call that specific named tool rather than deciding on its own or calling a different one
Anthropic's Messages API exposes a `tool_choice` parameter with four possible values: `auto` (the default, letting the model decide whether and which tool to call), `any` (forcing some tool call but not a particular one), `none` (preventing tool use), and `tool` -- and setting `tool_choice` to `{"type": "tool", "name": "get_weather"}` specifically forces that named tool to be called on this turn, which is exactly the guarantee the developer wants. Removing the other tool from the array would only prevent it from being offered at all, and does not actually force a call, since the model could still decline to call the only remaining tool under the default `auto` behavior. The `any` value forces some tool call, but not a specific one -- it does not default to "the first tool listed"; the model still chooses among whichever tools are available to it. Relying only on a system-prompt instruction is a weaker, unenforced nudge that Anthropic's own documentation contrasts with the `tool_choice` mechanism, which structurally guarantees the behavior rather than merely encouraging it through prompting.
Source: Anthropic, 'Define tools' -- Forcing tool use, https://platform.claude.com/docs/en/agents-and-tools/tool-use/define-tools