tool_choice and control
On this page
Control the model’s behavior
By default, the model decides on its own whether to call a tool or respond directly. This is auto mode. But in some cases, you need finer control. The tool_choice parameter gives you that power.
The four tool_choice modes
auto mode (default)
response = client.chat.completions.create(
model="grok-4.5",
messages=messages,
tools=tools,
tool_choice="auto"
)
The model evaluates the request and decides:
- If the request requires external data → it calls a tool
- If it can respond directly → it responds without a tool
This is the most common and natural mode. Use it when you trust the model’s judgment.
required mode
response = client.chat.completions.create(
model="grok-4.5",
messages=messages,
tools=tools,
tool_choice="required"
)
The model must call at least one tool. It cannot respond directly, even if it already knows the answer. Use cases:
- Structured extraction: You want to force the model to extract data into a specific format via a dedicated tool
- Mandatory validation: Every request must pass through a verification tool
- Systematic logging: Everything must be traced via a logging tool
none mode
response = client.chat.completions.create(
model="grok-4.5",
messages=messages,
tools=tools,
tool_choice="none"
)
Completely disables function calling for this request. The model sees the tool definitions (they remain in context) but cannot call them. Use cases:
- Clarification phase: You want the model to ask questions before acting
- Preview mode: Show what the model would do without executing
- Fallback: If tools are temporarily unavailable
Specific mode (force a specific tool)
response = client.chat.completions.create(
model="grok-4.5",
messages=messages,
tools=tools,
tool_choice={
"type": "function",
"function": {"name": "get_weather"}
}
)
The model is forced to call exactly this tool. It cannot choose another one, nor respond directly. This is the most restrictive mode. Use cases:
- Sequential workflow: At this step, this specific tool must be called
- Tests: You want to verify that the model generates the correct arguments for a given tool
- Targeted extraction: You know which tool to use and just want the model to extract the parameters
Mode comparison
| Mode | Behavior | When to use it |
|---|---|---|
| auto | The model decides freely | General case, chatbots |
| required | Must call at least one tool | Extraction, validation |
| none | No tools allowed | Clarification, fallback |
| {"function":...} | Forces a specific tool | Workflow, tests |
Advanced strategies
Alternate modes in a workflow
A smart workflow can change tool_choice depending on the step:
# Step 1: force search
response1 = client.chat.completions.create(
model="grok-4.5",
messages=messages,
tools=tools,
tool_choice={"type": "function", "function": {"name": "search_products"}}
)
# Step 2: let the model decide (analysis or question)
response2 = client.chat.completions.create(
model="grok-4.5",
messages=updated_messages,
tools=tools,
tool_choice="auto"
)
Combine with the system prompt
The system prompt can guide the model in its tool choices even in auto mode:
messages = [
{
"role": "system",
"content": "You are a travel assistant. Always use "
"get_weather before recommending outdoor activities."
},
{"role": "user", "content": "What should I do in Marseille this weekend?"}
]
Key takeaways
auto: The model decides (default, recommended for most cases)required: Forces calling at least one toolnone: Temporarily disables function calling- Specific mode: Forces calling a specific tool by name
- Alternate modes in a workflow for fine control
- Combine
tool_choicewith the system prompt to guide the model