# Tool use primer

Web page: https://academy.memberpress.ai/courses/prompt-engineering-101/l18/

Lesson 18 of 19 in [Prompt Engineering 101](https://academy.memberpress.ai/courses/prompt-engineering-101/), 8 min.

Video: https://www.youtube.com/watch?v=Orzpw984A_0

Claude's training data has a cutoff. It cannot browse the web in real time. It cannot query a database. It cannot run code. It can, however, call external functions — if you define those functions and give it a way to invoke them.

This is tool use. It is the technique that powers most production Claude integrations that do something beyond text generation.

**The concept**

You define a set of tools — a calculator, a search function, a database query function. You give Claude the name and description of each tool. When Claude needs to use one, it produces a structured tool call — a function name and arguments — instead of answering directly. Your code intercepts the tool call, executes the actual function, and returns the result to Claude. Claude then uses the result to produce the final answer.

Claude does not execute the tool. Claude writes the instruction to execute the tool. Your code executes it.

**A worked example**

You want Claude to answer: "What is the total Q3 revenue for the North American segment?"

Without tool use, Claude either retrieves this from training data (unreliable for your specific company) or tells you it does not have access to that information.

With tool use:

1. You define a tool: `database_query(sql: string) -> string`
2. Claude produces: `database_query("SELECT SUM(revenue) FROM sales WHERE quarter='Q3' AND region='North America'")`
3. Your code runs the query and returns: `"12,450,000"`
4. Claude formats the final answer: "Q3 revenue for the North American segment was $12.45 million."

The answer is accurate because it came from the actual database. Claude's role was to write the right query and format the result — two things it does well.

**Defining tools in a prompt**

When you are prototyping tool use without building the infrastructure, define the tools in the prompt and ask Claude to simulate the call:

"You have access to the following tools:
- `calculator(expression: string) -> number`: evaluates a mathematical expression and returns the result
- `search(query: string) -> string`: searches the web and returns a summary of the top result

When you need to use a tool, write the tool call on its own line. I will provide the result. Then continue your answer."

This lets you test whether Claude produces the right tool calls before you build the execution layer.

**If you get stuck**

If Claude is trying to answer without using the tool, add: "You must use the tool to answer this question. Do not estimate or guess."

If Claude is producing tool calls with the wrong arguments, the tool description is not specific enough. Add a description of what valid arguments look like: "Expression must be a standard arithmetic expression using +, -, *, /. No functions."

**Cross-reference**

L19 (Search and retrieval) covers the specific case of search tools and how to use retrieved text as context. L17 (Chaining prompts) covers how to chain tool calls when one tool's output feeds into the next.

**Deliverable**

Define two tools in a prompt using the simulation technique from this lesson. Write a question that requires using both tools to answer. Run the prompt. For each tool call Claude produces, write the result it would receive, then continue the conversation until Claude produces the final answer.

## Try these prompts

- What is the total revenue for Q3? Use calculator(expression) if exact math is needed.
- Look up the current weather in [city] using search(query) and summarize it in one sentence.

Next: [Search & retrieval](https://academy.memberpress.ai/courses/prompt-engineering-101/l19/)
