Tool Use and Function Calling
What tool use enables
Tool use lets Claude call functions you define — searching a database, checking the weather, running a calculation — rather than just generating text. You describe each tool's name, purpose, and input schema; Claude decides when to invoke it.
The tool-use loop
1. Send a message with tools defined. 2. Claude responds with a tool_use block containing the tool name and arguments. 3. Your code executes the actual function. 4. You send the result back as a tool_result message. 5. Claude uses that result to form its final answer.
Designing reliable tools
Write clear, narrow tool descriptions — vague tools get misused. Validate all arguments Claude sends before executing (never trust them blindly), and return structured error messages the model can reason about if something fails.
Key Takeaways
- Tool use lets Claude call real functions instead of only generating text.
- The loop is: define tools → Claude requests a call → you execute → return result → Claude finalizes.
- Always validate tool arguments server-side before executing.
- Clear, narrow tool descriptions prevent misuse.
Build a weather lookup tool
Define a `get_weather(city)` tool schema, wire it to a mock function returning fixed data, and confirm Claude correctly calls it when asked "What's the weather in Cairo?"