Topic 1 of 5 · 4 min read
Writing tool names, descriptions and input schemas
Goal: Write a tool definition whose name, description and input schema let the model pick it at the right time and fill its arguments correctly.
A tool definition is the only documentation the model ever sees for your function, so the name, the description and the schema are the whole interface. The model does not read your code. It reads three things and guesses from them.
Check yourself · 1 of 3
What does the model use to decide which tool to call?
Why it matters
When a tool is picked at the wrong time, or called with a made-up argument, the cause is nearly always the definition. Fixing it costs a few lines. Fixing it in the application code costs much more.
How to write one
- Name it for the action and the object.
get_order_statusbeatsordersorhelper2. Use the same naming style across all tools. - Describe when to use it, and when not to. Say what it returns and what it cannot do. Two tools that sound alike need a sentence each that separates them.
- Give every argument a type and a description. Use
enumfor closed sets,requiredfor what must be present, and a format hint (such as an ISO date) when the shape matters. - Keep the schema small. A tool with twelve optional fields invites wrong guesses. Split it, or drop what the model cannot know.
- Do not ask the model for what you already have. The user id comes from your session, not from the model.
All main providers (Claude, OpenAI, Gemini) take the arguments as JSON Schema, so one schema style works everywhere.
Before and after
Weak:
{
"name": "search",
"description": "Searches things",
"input_schema": {
"type": "object",
"properties": { "q": { "type": "string" }, "t": { "type": "string" } }
}
}
Better:
{
"name": "search_orders",
"description": "Find a customer's past orders by status or date range. Returns up to 20 orders with id, status and total. Does not return refunds; use get_refund for those.",
"input_schema": {
"type": "object",
"properties": {
"status": { "type": "string", "enum": ["pending", "shipped", "delivered", "cancelled"], "description": "Order status to filter by" },
"since": { "type": "string", "description": "Earliest order date, ISO 8601, for example 2026-11-01" }
},
"required": ["status"]
}
}
What goes wrong
- Vague names and descriptions. The model picks by a loose match and calls the wrong tool.
- Free-text arguments for closed sets. The model writes "Shipped!" and your code expects "shipped".
- Overlapping tools. Two tools that both "look up customers" split the calls at random.
- Trusting the schema as validation. The schema guides the model but does not guarantee valid input. Validate on your side too.
Examples
Separating two similar tools
A support bot has get_customer and search_customers. Calls keep landing on the wrong one. The fix is two descriptions: "Fetch one customer by exact id. Use when the user gives an id." and "Find customers by name or email. Returns up to 10 matches. Use when you do not have an id." No code changed, and wrong picks dropped.
Closing an argument with an enum
A set_priority tool took priority as a free string and received "urgent", "High" and "P1" in one week. Declaring "enum": ["low", "normal", "high"] and describing what each means made every call valid.
Key points
- The name, description and input schema are all the model knows about your tool.
- A good description says what the tool does, what it returns and when to use a different tool.
- Use enum, required and format hints so arguments arrive in a shape your code accepts.
- Keep each tool narrow; overlapping or sprawling tools cause wrong picks and wrong arguments.
- The schema guides the model but never replaces validation in your own code.
Common mistakes
- Naming a tool with a short or generic word like
runordataand writing no description. - Leaving out
required, so the model omits a field your code needs. - Asking the model for values the application already knows, such as the signed-in user id.
- Assuming the schema rejects bad input, and skipping server-side validation.
Check yourself · 2 of 3
An argument can only be one of four fixed status values. Which schema choice helps the model most?
Check yourself · 3 of 3
Two tools, get_customer and search_customers, are called at random. What is the best first fix?
Practice items, not counted towards your mastery.
Start here
- Tool use overview (Claude docs) (opens in a new tab)DocsFree
Anthropic's reference for tool definitions, the tool_use and tool_result blocks, tool_choice and parallel calls.
- Function calling guide (OpenAI) (opens in a new tab)DocsFree
OpenAI's guide to function definitions, the call loop, parallel calls and tool_choice.
- Function calling (Gemini API docs) (opens in a new tab)DocsFree
Google's guide to declaring functions and returning function responses to Gemini.
More for this topic
- Understanding JSON Schema (opens in a new tab)DocsFree
The schema language tool inputs are written in: types, enums, required fields and constraints.