Tool Use & Function Calling
How do you force Claude to use a specific tool?
QUICK ANSWER
Force Claude to use a specific tool by setting the request parameter 'tool_choice' to type 'tool' and providing the name of the target tool.
Tool Choice Configuration
{
"model": "claude-3-5-sonnet-20241022",
"max_tokens": 1024,
"tools": [
{
"name": "fetch_user_records",
"description": "Retrieves user files.",
"input_schema": {
"type": "object",
"properties": {
"user_id": { "type": "string" }
},
"required": ["user_id"]
}
}
],
"tool_choice": {
"type": "tool",
"name": "fetch_user_records"
},
"messages": [
{ "role": "user", "content": "Help me lookup account 987." }
]
}
Verified against: Anthropic API Tool Use v1