Lesson 33.1 · 1 of 6 · 6 min read · Reviewed 24 Nov 2026
Defining tools
By the end, you can
- Write a tool definition with a name, description and input schema.
- Explain why the description matters more than the code behind the tool.
A tool is a function your application offers to Claude. You describe it in the tools array of a Messages APIMessages API: The chat API endpoint that takes a list of messages and returns the next assistant message. request, and Claude can then ask to use it.
{
"name": "get_order_status",
"description": "Look up the shipping status of one order by its id. Use when the customer asks where an order is. Do not use for refunds.",
"input_schema": {
"type": "object",
"properties": {
"order_id": { "type": "string", "description": "Order id, for example A-10234" }
},
"required": ["order_id"]
}
}
The three parts
- name: short, specific and unambiguous.
get_order_statusbeatslookup. - description: the most important part. Claude decides whether and how to call a tool almost entirely from this text. Say what it returns, when to use it, and when another tool fits better.
- input_schema: a JSON Schema object. Use
required, types, enums and per-field descriptions so Claude produces valid input.
What Claude does not see
Claude never sees your code, your database or your API keys. It sees the definition, decides to call, and your application does the work. That separation is the heart of the next lesson.
Key points
- A tool definition is a name, a description and a JSON Schema for its input.
- The description is a prompt: say what the tool does, when to use it and when not to.
- Claude only sees the definition, never your implementation.
Define a tool the model can pick
Write a tool definition clear enough that the model calls it with the right input.
You will have: A get_weather definition with a name, a description and a typed input schema, plus the tool_use it produces.
Steps
- Run the starter and look at the vague tool and the input it gets.
- Rename it get_weather and describe what it returns, when to use it and when not to.
- Replace q with a required city string with a description and an example.
- Run it again and compare the input the model sends.
Done when
- stop_reason is tool_use.
- The tool requested is get_weather.
- The input is {'city': 'Lisbon'}.
Open in the Playground No API key needed.
Starter code (Python)
# Define one tool well, and see which tool and input the model asks for.
import anthropic
client = anthropic.Anthropic()
# TODO: rename this tool get_weather, describe what it returns, when to use it and when not to,
# TODO: and replace the vague "q" with a required "city" string that has a description and an example.
get_weather = {
"name": "weather",
"description": "Weather tool",
"input_schema": {"type": "object", "properties": {"q": {"type": "string"}}},
}
response = client.messages.create(
model="claude-sonnet-5-5",
max_tokens=300,
tools=[get_weather],
messages=[{"role": "user", "content": "Is it sunny in Lisbon right now?"}],
)
print("stop_reason:", response.stop_reason)
for block in response.content:
if block.type == "tool_use":
print("tool requested:", block.name)
print("input:", block.input)
Show a solution
# Define one tool well, and see which tool and input the model asks for.
import anthropic
client = anthropic.Anthropic()
get_weather = {
"name": "get_weather",
"description": "Current weather for one city: temperature in Celsius and conditions. "
"Use when the user asks about the weather now. Not for forecasts.",
"input_schema": {
"type": "object",
"properties": {"city": {"type": "string", "description": "City name, for example Lisbon"}},
"required": ["city"],
},
}
response = client.messages.create(
model="claude-sonnet-5-5",
max_tokens=300,
tools=[get_weather],
messages=[{"role": "user", "content": "Is it sunny in Lisbon right now?"}],
)
print("stop_reason:", response.stop_reason)
for block in response.content:
if block.type == "tool_use":
print("tool requested:", block.name)
print("input:", block.input)
Do it Fix two vague tools in the Tool design lab in the Playground. No API key needed.