Day 2, 25 minutes · beginner
Why it matters
Claude decides which tool to call, and with what input, from one thing only: the definition you send. It never sees your function. A vague definition gets you the wrong tool, a missing input or a made-up value. A clear one gets you the right call almost every time.
Today you write the three tools Margriet needs: one for stock, one for prices and one for opening hours. Then you give Claude four customer questions and watch which tool it picks for each. At the end you have a tools.py file that the rest of the course uses, and you know why the description matters more than anything else in it.
The three parts of a tool definition
Every tool you define has three main fields:
- name: what Claude calls the tool. The docs allow letters, digits, underscores and hyphens, from 1 to 128 characters. Use clear names such as
check_stock, nottool1. - description: plain text that says what the tool does, when to use it and what it returns.
- input_schema: a JSON Schema object that lists the inputs.
A small schema looks like this:
{
"type": "object",
"properties": {
"plant": {
"type": "string",
"description": "The common name of one plant in lower case, for example monstera."
}
},
"required": ["plant"],
"additionalProperties": false
}
- type object with properties: the input is a set of named fields. Here there is one,
plant, which must be a string (text). - required: the fields Claude must always fill in. A field that is not listed here is optional.
- enum: a fixed list of allowed values. Today's opening hours tool uses it for the days of the week, so Claude cannot send "Sat" or "weekend".
- additionalProperties false: no other fields are allowed. You need this in lesson 5, when you switch on strict tool use.
The description does most of the work
The docs are clear about this: a detailed description is "by far the most important factor" in how well tools work. They ask for at least three or four sentences per tool, covering:
- what the tool does;
- when it should be used, and when not;
- what each input means;
- what it does not return.
Compare these two descriptions of the same tool:
- Poor: "Gets the stock."
- Better: "Check how many plants of one kind Copperleaf Plants has in its shop today. Use it when a customer asks if a plant is available or how many are left. It returns a count for one plant only, not the price and not care tips. Call it once for each plant the customer asks about."
The second one tells Claude when to pick this tool over the price tool, and that two plants mean two calls. Give each input its own description too, with an example.
Two more tips from the docs:
- Return only what Claude needs. A short, clear result ("4 x monstera in stock today") is easier for Claude to use than a large dump of data.
- Do not trust Claude to fill in what the customer did not say. When a required value is missing, the docs say Claude Opus is much more likely to ask for it, while Claude Sonnet might guess a reasonable value. Your code should still check its inputs, as you do in lesson 5.
Tools cost tokens
Your tool definitions are sent with every request and count as input tokens. On top of that, the API adds a short system prompt that explains tool use to the model: the docs list 286 tokens for Claude Opus 5.5, Sonnet 5.5 and Haiku 5.5 with the default setting. A few clear tools are cheap. Fifty long ones are not.
Optional: examples of good input
For tools with complicated inputs, you can add input_examples: a list of example inputs that match your schema. The docs say each one adds roughly 100 to 200 input tokens. Margriet's tools are simple, so this course leaves them out.
The steps
- Create
tools.pywith the stock and price tools. - Add the opening hours tool and the
TOOLSlist. - Run a short test that sends four questions and prints which tool Claude picked for each.
- Make one description vague on purpose, run the test again and see what changes.
Follow the steps below.
Today's actions
Ticks are not saved without an accountDo it in Claude API
Claude API
- Open a terminal in your copperleaf-tools folder and turn on the virtual environment:
source .venv/bin/activateon macOS or Linux,.venv\Scripts\Activate.ps1on Windows. - Create
tools.pywith this code: the first two tool definitions. Read each description: what it does, when to use it, what it does not return."""The tool definitions Claude sees. The code that runs them is in shop.py.""" PLANT = { "type": "string", "description": "The common name of one plant in lower case, for example monstera or peace lily.", } CHECK_STOCK = { "name": "check_stock", "description": ( "Check how many plants of one kind Copperleaf Plants has in its shop today. " "Use it when a customer asks if a plant is available or how many are left. " "It returns a count for one plant only, not the price and not care tips. " "Call it once for each plant the customer asks about." ), "input_schema": { "type": "object", "properties": {"plant": PLANT}, "required": ["plant"], "additionalProperties": False, }, } GET_PRICE = { "name": "get_price", "description": ( "Look up the shop price in euros of one plant at Copperleaf Plants. " "Use it when a customer asks what a plant costs. " "It returns the price of a single plant, not the stock and not delivery costs." ), "input_schema": { "type": "object", "properties": {"plant": PLANT}, "required": ["plant"], "additionalProperties": False, }, } - Add this to the end of
tools.py: the opening hours tool with a fixed list of days, and theTOOLSlist that the next lessons import.GET_OPENING_HOURS = { "name": "get_opening_hours", "description": ( "Get the opening hours of the Copperleaf Plants shop on one day of the week. " "Use it when a customer asks when the shop is open or wants to pick up a plant. " "It returns the hours for that day or the word closed. It knows no holidays." ), "input_schema": { "type": "object", "properties": { "day": { "type": "string", "enum": ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"], "description": "The day of the week in lower case.", } }, "required": ["day"], "additionalProperties": False, }, } TOOLS = [CHECK_STOCK, GET_PRICE, GET_OPENING_HOURS] - Create
which_tool.pywith this code. It sends four questions, one at a time, and prints the tool Claude chose for each, or that it chose none.from dotenv import load_dotenv import anthropic from tools import TOOLS load_dotenv() client = anthropic.Anthropic() QUESTIONS = [ "Is the peace lily in stock?", "How much is a pothos?", "Can I come by on Thursday evening?", "What does a snake plant need to grow well?", ] for question in QUESTIONS: response = client.messages.create( model="claude-opus-5-5", max_tokens=1024, tools=TOOLS, tool_choice={"type": "auto", "disable_parallel_tool_use": True}, messages=[{"role": "user", "content": question}], ) calls = [b for b in response.content if b.type == "tool_use"] print(question) if calls: print(" ->", calls[0].name, calls[0].input) else: print(" -> no tool, stop_reason:", response.stop_reason) print("Input tokens of the last request:", response.usage.input_tokens) - Run
python which_tool.py. You should seecheck_stock,get_priceandget_opening_hourswith{'day': 'thursday'}, and no tool for the snake plant question. Note the input tokens on the last line. - Test a vague description: in
tools.py, change the description of GET_OPENING_HOURS to"Gets hours."and runpython which_tool.pyagain. Compare, write down what changed (maybe nothing), then put the full description back.
Note: Claude's choice can differ between runs, especially for the last question. If Claude asks for a tool there, look at which one and ask yourself whether your descriptions say when not to use it.
Paid planPay as you go: buy prepaid credits in the Claude Console (minimum 5 US dollars). There is no free tier. Max, Ultra and Team plans include monthly API credits.
Create a free account to save your progress
Free, and no payment details. Your ticks and finished lessons are kept, on every device.
Create a free account I already have an accountCreate a free account to save your progress. Sign in or sign up