Sub topic 4
Writing descriptions that say what, when, and when not
The description is the main thing the model reads when it decides whether to call a tool. The name hints at purpose, and the schema constrains the arguments. The description tells the model what the tool does, when to pick it, and when to leave it alone.
This chapter assumes you have made a basic LLM API call, can read JSON and short Python examples, and know the JSON Schema types (string, integer, object, array). It also assumes you know the parts of a tool definition: name, description, and input schema.
Why the description carries so much weight
The model never sees your code. It sees text: the name, the description, and the schema. From that text alone it must answer three questions on every turn:
- Does the user's request need a tool at all?
- If so, which tool?
- What should the arguments be?
A vague description makes all three harder. Compare the two definitions from the spine. The weak one says only "Handles orders." The model cannot tell whether it reads, creates, or cancels orders. It cannot tell whether to call it for a question about an order ID or a search by date.
{
"name": "do_order_thing",
"description": "Handles orders.",
"input_schema": {
"type": "object",
"properties": {
"data": { "type": "string" },
"mode": { "type": "string" }
}
}
}The better definition states purpose, a trigger condition, a boundary, and the shape of the result:
{
"name": "search_orders",
"description": "Search a customer's orders by status and date. Use this when the user does not give an order ID. If the user gives an order ID, use get_order instead. Returns up to `limit` orders, newest first, each with id, status, total, and created_at.",
"input_schema": {
"type": "object",
"properties": {
"customer_id": {
"type": "string",
"description": "Customer ID, for example 'cus_4821'. Ask the user if you do not know it."
},
"status": {
"type": "string",
"enum": ["pending", "shipped", "delivered", "cancelled"],
"description": "Only return orders with this status. Omit to include all statuses."
},
"created_after": {
"type": "string",
"description": "Only return orders created on or after this date, in YYYY-MM-DD format."
},
"limit": {
"type": "integer",
"minimum": 1,
"maximum": 50,
"description": "Maximum number of orders to return. Defaults to 10 if omitted."
}
},
"required": ["customer_id"]
}
}The three parts: what, when, when not
A good description answers three questions in order.
What the tool does
Start with a plain sentence naming the action and the thing acted on: "Search a customer's orders by status and date." Use the same nouns your users and your other tools use. If the system calls them "orders" everywhere, do not write "purchases" here.
State side effects when they exist. A model treats a read differently from a write, and it should know before it calls. Phrases such as "Read-only" or "Sends an email to the customer and cannot be undone" change how carefully the model decides.
When to use it
Give the trigger condition in terms of the user's situation or the data the model has: "Use this when the user does not give an order ID." Triggers based on observable facts are easier to follow than vague ones such as "Use this for order-related questions."
When not to use it
Boundaries stop the most common error, which is picking a neighboring tool. Name the alternative: "If the user gives an order ID, use get_order instead." Naming the other tool is more useful than saying "do not use for single orders," because it gives the model somewhere to go.
Also state when no tool applies, if that mistake is likely. A model with a search tool may try to search for facts it already knows.
What it returns
Add one sentence on the result: how many items, in what order, and which fields. The model plans its next step from this. If it knows results are "newest first" and capped by limit, it knows that "the latest order" means limit: 1.
Checklist for a description
| Element | Example | What goes wrong without it |
|---|---|---|
| Action and object | "Search a customer's orders by status and date." | The model guesses the purpose from the name |
| Trigger | "Use this when the user does not give an order ID." | The model skips the tool or uses it too often |
| Boundary | "If the user gives an order ID, use get_order instead." | The model picks the wrong neighbor |
| Side effects | "Read-only." | The model calls writes casually or avoids safe reads |
| Return shape | "Newest first, each with id, status, total, created_at." | The model cannot plan follow-up steps |
How the boundary shapes selection
The diagram shows the decision the description guides. Each branch corresponds to a sentence you wrote.
The "Ask the user if you do not know it" sentence in the customer_id parameter description produces the branch to the user. Without it, a model may invent an ID to satisfy the required field.
Common errors
- Describing implementation instead of use. "Queries the orders table in Postgres" tells the model nothing about when to call. Describe behavior from the caller's side.
- Repeating the name.
get_order: "Gets an order." This adds no information. Say what identifies the order and what comes back. - Overlapping descriptions. If two tools both say "Look up order information," the model will pick between them at random. Each description must say what separates it from the other.
- Marketing language. Words such as "powerful" or "comprehensive" take space and say nothing. Use concrete limits and fields.
- Burying the boundary. Put "when not to use" in the first few sentences. Long descriptions are not always read with equal weight, and the key distinction should not sit at the end.
- Instructions that belong in the system prompt. Tool-specific rules go in the description. Behavior that applies to the whole conversation, such as tone, goes in the system prompt.
- Stale descriptions. When you change what a tool does, change its description in the same commit. A model follows the text, not the code.
Length and cost
A description needs enough words to cover what, when, when not, and returns. For most tools that is two to five sentences. Longer is fine for tools with real edge cases, but every token is sent with every request. The later chapter on context cost covers this trade-off. For now, cut any sentence that does not change what the model would do.
Verifying a description
You cannot judge a description by reading it. Test it. The spine's evaluation helper runs fixed prompts and reports which tool the model picks, so you can compare two wordings on the same cases.
CASES = [
("Where is order ord_1001?", "get_order"),
("Show me my cancelled orders from last month", "search_orders"),
("What is the capital of France?", None),
]
def run_eval(choose_tool):
"""choose_tool(prompt) -> name of the tool the model called, or None."""
failures = []
for prompt, expected in CASES:
actual = choose_tool(prompt)
if actual != expected:
failures.append((prompt, expected, actual))
passed = len(CASES) - len(failures)
print(f"{passed}/{len(CASES)} correct")
for prompt, expected, actual in failures:
print(f" {prompt!r}: expected {expected}, got {actual}")
return failuresYou supply choose_tool, which sends the prompt and your tool definitions to the model and returns the name of the tool it called. Run it once with the weak description and once with the strong one. The third case, where the expected value is None, checks the "when not" side: the model should answer a general-knowledge question without calling any tool.
When a case fails, read the model's choice as feedback on your text. If it picked search_orders for "Where is order ord_1001?", the boundary sentence is missing or too weak.
Rewriting a weak description
Take "Handles orders." and rewrite it step by step.
- Add the action and object. "Retrieve one order by its ID."
- Add the trigger. "Use this when the user gives an order ID such as 'ord_1001'."
- Add the boundary. "If the user has no ID and wants to find orders by status or date, use search_orders."
- Add the return shape. "Returns id, status, total, and created_at, or an error if the ID is not found."
The result: "Retrieve one order by its ID. Use this when the user gives an order ID such as 'ord1001'. If the user has no ID and wants to find orders by status or date, use searchorders. Returns id, status, total, and created_at, or an error if the ID is not found."
Exercise
A tool named send_refund has the description "Refunds an order." The model sometimes calls it when a user only asks whether an order is eligible for a refund. Rewrite the description so it states what the tool does, when to use it, and when not to. Name a tool to use for eligibility checks (call it check_refund_eligibility) and mention the side effect.
Show answer
Example: "Issue a refund to the customer's original payment method for one order. This moves money and cannot be undone. Use this only after the user has explicitly asked for the refund and the order is confirmed eligible. If the user only asks whether a refund is possible, use checkrefundeligibility instead. Returns refund_id and status." The rewrite states the action, the irreversible side effect, the trigger (explicit request), the boundary with a named alternative, and the return shape.
Exercise
Add two test cases to the CASES list that check the "when not" behavior of send_refund from the previous exercise. What should the expected tool be in each?
Show answer
For example, ("Can I get a refund on ord1001?", "checkrefund_eligibility") and ("What is your refund policy?", None). The first checks that an eligibility question goes to the neighboring tool. The second checks that a general question calls no tool, since no tool provides policy text.