Sub topic 13
Steering when the model uses a tool
This chapter assumes you can already declare a built-in tool in a request and read the tool-call items in a response. Here you control when the model uses a tool. The model decides by default, and you can influence or override that decision.
Two levers
You have two ways to steer tool use:
- Instructions are text in the system or developer message. They influence the model, but it can still ignore them.
- Tool choice is a request parameter. It constrains what the model may do.
Use instructions to describe a policy, such as "search only for events after 2024". Use tool choice when a request must or must not use a tool.
Tool choice values
The names below follow the OpenAI Responses API. Anthropic uses similar modes with different spellings.
| Goal | OpenAI `tool_choice` | Anthropic `tool_choice` |
|---|---|---|
| Let the model decide | `"auto"` (default) | `{"type": "auto"}` |
| Require some tool call | `"required"` | `{"type": "any"}` |
| Require one specific tool | `{"type": "file_search"}` | `{"type": "tool", "name": "web_search"}` |
| Forbid tool calls | `"none"` | `{"type": "none"}` |
Forcing a tool
The next example forces the code interpreter, so the model computes the answer instead of estimating it.
from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model="gpt-4.1",
tools=[{"type": "code_interpreter", "container": {"type": "auto"}}],
tool_choice="required",
input="What is 17 raised to the power of 23?",
)
print(response.output_text)Always check the output items afterward. A forced call shows up as a tool-call item, such as code_interpreter_call. If it is missing, your parameter was not applied.
Steering with instructions
Instructions suit softer rules. This request offers file search but tells the model when to use it.
response = client.responses.create(
model="gpt-4.1",
tools=[{"type": "file_search", "vector_store_ids": ["vs_123"]}],
instructions=(
"Answer company policy questions only from the handbook. "
"Call file_search before answering. If the handbook has no answer, say so."
),
input="How many vacation days do new employees get?",
)Here vs_123 is a placeholder. Use the ID of your own vector store.
Common errors
- Forcing a tool on every turn. In a multi-turn conversation,
requiredmakes the model call a tool even for "thanks". Set it only on the turns that need it. - Forcing and then trusting. A forced search still returns whatever the web contains. Forcing guarantees the call, not the quality of the result.
- Relying on instructions alone for compliance. If a missing call would be a real failure, such as an uncited policy answer, use tool choice and check the output items.
- Mismatched tool names. The type in
tool_choicemust match a tool you declared. Some providers version these names, for exampleweb_search_20250305.
Exercise
A support bot must always consult the handbook before answering, but it also chats casually. Which setting would you use, and what do you check afterward?
Show answer
Set toolchoice to the specific filesearch tool on turns that ask policy questions, and leave it on auto for small talk. Instructions alone can be ignored. Afterward, check that the response output contains a filesearchcall item, and use the citations to confirm the answer came from the handbook.