📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Generative AI Engineering Tool Use and Function Calling

Tool Use and Function Calling

6 min read Quiz at the end
Enable LLMs to call external tools: define tools with schemas, detect tool_use blocks, execute and return results.

LLM Tool Use / Function Calling

LLMs can select and call external tools — search, calculate, fetch data, run code.

# Claude tool use
import anthropic

tools = [
    {
        'name': 'get_weather',
        'description': 'Get current weather for a city',
        'input_schema': {
            'type': 'object',
            'properties': {
                'city': {'type':'string','description':'City name'}
            },
            'required': ['city']
        }
    },
    {
        'name': 'search_docs',
        'description': 'Search internal documentation',
        'input_schema': {
            'type': 'object',
            'properties': {
                'query': {'type':'string'}
            },
            'required': ['query']
        }
    }
]

client = anthropic.Anthropic()
response = client.messages.create(
    model='claude-opus-4-5', max_tokens=1024,
    tools=tools,
    messages=[{'role':'user','content':'Weather in London?'}]
)

for block in response.content:
    if block.type == 'tool_use':
        print('Tool:', block.name, 'Input:', block.input)
        # Execute tool, feed result back to model
Topic Quiz · 1 questions

Test your understanding before moving on

1. What must you provide for an LLM tool so it can decide when to use it?
💡 Tools need a name, human-readable description, and structured input schema so the LLM knows what the tool does.