Skip to main content

Tool Use

2 min read

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

TypeScript

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

Python

TypeScript Example

TypeScript

Handling Tool Calls

Response Structure

When Claude wants to use a tool, it returns a tool_use content block:

JSON

Processing Tool Calls

TypeScript

Tool Result Format

TypeScript

Complete Example

Multi-Tool Chat Application

TypeScript

Tool Choice

Control how Claude uses tools:

TypeScript

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

TypeScript

Streaming with Tools

TypeScript

Best Practices

1. Write Clear Descriptions

Claude relies on descriptions to understand when and how to use tools:

TypeScript

2. Use Descriptive Parameter Names

TypeScript

3. Handle Errors Gracefully

TypeScript

4. Validate Tool Inputs

TypeScript

5. Keep Tools Focused

Each tool should do one thing well:

TypeScript

Common Patterns

Calculator Tool

TypeScript

Database Query Tool

TypeScript

File Operations Tool

TypeScript

Security Considerations

  1. Validate all inputs - Never trust tool inputs blindly
  2. Sanitize outputs - Don't expose sensitive data in tool results
  3. Limit scope - Tools should have minimal required permissions
  4. Rate limit - Prevent abuse of expensive operations
  5. Audit logging - Log all tool executions for security review

Next Steps

Generated with AI using Claude AI by Anthropic

Model: Claude Opus 4.5 · Generated: 2025-12-20 · Build: v1.21.0-75762dc

Edit this page on GitHub··

Discussion

0/2000

Comments are reviewed before being published