Writing Tool Descriptions
Part of the Tools and Agents section of Coddy's AI Engineering journey. Lesson 11 of 22.
A model never sees your Python functions. It decides whether to call a tool, and which one, from the tool's name and description alone. A description like Useful helper. gives it nothing to go on, so it answers without the tool.
vague = {"name": "helper", "description": "Useful helper.", "input_schema": schema}
clear = {
"name": "get_tides",
"description": "Get today's high and low tide times for a harbour. Use it for any question about tides.",
"input_schema": schema,
}Asked When is high tide in Dover?, the model answers alone with vague (stop reason end_turn) and calls clear (stop reason tool_use).
A good description says three things: what the tool does or returns, when to use it, and anything the model must know about the arguments (units, formats, limits). Give each argument its own description too. The stand-in matches words between the request and the description; a real model reads the meaning, but it fails in the same way when the description says nothing.
Challenge
MediumThe library's assistant never uses its lookup tool, because the description says nothing. Fix the description; keep the name, the schema and the loop.
- Replace
Looks things up.with a description in one or two sentences. - Say that the tool gets the opening hours of a library branch.
- Say to use it when someone asks when a branch opens or closes.
The loop prints each tool call and the answer. For example, for the input When does the Riverside branch open? the program prints:
Tool: lookup {'branch_name': 'Riverside'}
Answer: Here is what I found: Riverside: 9 am to 6 pmTry it yourself
import coddy_ai as anthropic # in production: import anthropic
client = anthropic.Anthropic()
HOURS = {"Riverside": "9 am to 6 pm", "Hill": "10 am to 4 pm", "Oak": "8 am to 8 pm"}
# Rewrite the description so the model knows when to use this tool
TOOLS = [
{
"name": "lookup",
"description": "Looks things up.",
"input_schema": {
"type": "object",
"properties": {"branch_name": {"type": "string", "description": "The branch name, such as Riverside"}},
"required": ["branch_name"],
},
}
]
def lookup(branch_name):
return f"{branch_name}: {HOURS.get(branch_name, 'no such branch')}"
request = input()
messages = [{"role": "user", "content": request}]
response = client.messages.create(model="claude-opus-5-5", max_tokens=300, tools=TOOLS, messages=messages)
while response.stop_reason == "tool_use":
messages.append({"role": "assistant", "content": response.content})
results = []
for block in response.content:
if block.type == "tool_use":
print(f"Tool: {block.name} {block.input}")
results.append({"type": "tool_result", "tool_use_id": block.id, "content": lookup(**block.input)})
messages.append({"role": "user", "content": results})
response = client.messages.create(model="claude-opus-5-5", max_tokens=300, tools=TOOLS, messages=messages)
for block in response.content:
if block.type == "text":
print("Answer: " + block.text)
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Tools and Agents
3Designing Agents
Writing Tool DescriptionsValidating Tool InputHuman ApprovalChaining Tool ResultsRecap: Expense AgentPractice on your own: Online Python compiler