
Tool Use and Function Calling: Give Claude Hands to Reach the Real World
Chris Harper
3 min read
Jul 15, 2026 · 20:06 UTC
TL;DR: Tool use is the mechanism that gives Claude the ability to call your functions — define a JSON schema, send it with your message, and Claude returns a structured call your code executes before resuming the conversation.
What you'll be able to do after this:
- Define a custom tool (a JSON Schema function signature) that Claude can invoke during a conversation
- Handle the two-request round trip: receive a
tool_useblock, run your function, send back atool_result - Force Claude to call a specific tool with
tool_choiceand addstrict: truefor schema-guaranteed inputs
How the round trip works
Tool use is a two-turn exchange. Turn 1: you send a message + a tools list. Claude decides to call one and responds with stop_reason: "tool_use" and a tool_use block containing the function name and its arguments. Turn 2: your code executes the function, then you send the result back in a tool_result block. Claude picks up the conversation and answers using the real data.
Python walkthrough
import anthropic
client = anthropic.Anthropic()
tools = [{
"name": "get_weather",
"description": "Return current weather for a city.",
"input_schema": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "City and state, e.g. Austin, TX"}
},
"required": ["location"]
}
}]
messages = [{"role": "user", "content": "What's the weather in Austin, TX?"}]
# Turn 1: Claude decides to call the tool
response = client.messages.create(
model="claude-sonnet-5",
max_tokens=1024,
tools=tools,
messages=messages,
)
tool_block = next(b for b in response.content if b.type == "tool_use")
# tool_block.name == "get_weather", tool_block.input == {"location": "Austin, TX"}
# Run your function
def get_weather(location): return "27°C, partly cloudy"
result = get_weather(**tool_block.input)
# Turn 2: send the result back
messages += [
{"role": "assistant", "content": response.content},
{"role": "user", "content": [{
"type": "tool_result",
"tool_use_id": tool_block.id,
"content": result
}]},
]
final = client.messages.create(
model="claude-sonnet-5",
max_tokens=1024,
tools=tools,
messages=messages,
)
print(next(b.text for b in final.content if b.type == "text"))
# "The weather in Austin, TX is currently 27°C and partly cloudy."
Things worth knowing
- When does Claude use the tool? By default (
tool_choice: {type: "auto"}), Claude decides. Settool_choice: {type: "any"}to force at least one tool call, or{type: "tool", name: "get_weather"}to force a specific one. - Strict mode: Add
"strict": trueto your tool definition. Claude'sinputwill exactly match your schema — no extra fields, no missing required fields. Always pair with"additionalProperties": false. - Skip the boilerplate: The Tool Runner in the Python and JS SDKs handles the two-turn loop automatically — register your function and the SDK calls it and sends the result.
- Server tools: Anthropic also provides hosted tools (web search, code execution, web fetch) that run on Anthropic's infrastructure — no handler code in your app.
Sources: Tool use overview — Claude Platform Docs · Build a tool-using agent — Claude Platform Docs · Strict tool use — Claude Platform Docs · Claude Function Calling Made Dead Simple — YouTube