Tool Use
Enable Claude to interact with external systems and execute functions
title: Tool Use description: Enable Claude to interact with external systems and execute functions
Tool use (function calling) allows Claude to interact with external systems, APIs, and services. This guide covers how to define tools, handle tool calls, and implement common patterns.
Overview
Tools extend Claude's capabilities by letting it:
- Fetch real-time data (weather, stock prices, search results)
- Perform calculations
- Interact with databases
- Call external APIs
- Execute code
Defining Tools
Basic Tool Definition
Tool Schema Properties
| Property | Type | Required | Description |
|----------|------|----------|-------------|
| name | string | Yes | Unique identifier for the tool |
| description | string | Yes | Clear description of what the tool does |
| input_schema | object | Yes | JSON Schema for input validation |
Making Requests with Tools
Python Example
TypeScript Example
Handling Tool Calls
Response Structure
When Claude wants to use a tool, it returns a tool_use content block:
Processing Tool Calls
Tool Result Format
Complete Example
Multi-Tool Chat Application
Tool Choice
Control how Claude uses tools:
Tool Choice Options
| Type | Description |
|------|-------------|
| auto | Claude decides whether to use tools (default) |
| any | Claude must use at least one tool |
| tool | Claude must use a specific tool |
| none | Claude cannot use any tools |
Forcing a Specific Tool
Streaming with Tools
Best Practices
1. Write Clear Descriptions
Claude relies on descriptions to understand when and how to use tools:
2. Use Descriptive Parameter Names
3. Handle Errors Gracefully
4. Validate Tool Inputs
5. Keep Tools Focused
Each tool should do one thing well:
Common Patterns
Calculator Tool
Database Query Tool
File Operations Tool
Security Considerations
- Validate all inputs - Never trust tool inputs blindly
- Sanitize outputs - Don't expose sensitive data in tool results
- Limit scope - Tools should have minimal required permissions
- Rate limit - Prevent abuse of expensive operations
- Audit logging - Log all tool executions for security review