Sub topic 4
Writing descriptions that say what, when, and when not
This chapter assumes you have called an LLM API with tools before, can read JSON, and know the basic JSON Schema types. The model sees only your tool's name, description, and schema. The description is the main signal it uses to decide whether to call a tool and when.
What a description must contain
A useful description answers three questions:
- What does the tool do, and what does it return?
- When should the model use it?
- When not, and which tool should it use instead?
A description like "Handles orders." answers none of them. The model has to guess, and it will guess differently on different prompts.
Compare it with the description from the search_orders tool:
{
"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."
}The three parts map onto it like this:
| Question | Text in the description |
|---|---|
| What | "Search a customer's orders by status and date." |
| When | "Use this when the user does not give an order ID." |
| When not | "If the user gives an order ID, use get_order instead." |
| Output | "Returns up to `limit` orders, newest first, each with id, status, total, and created_at." |
The last row matters too. If the model knows what comes back, it can plan the next step before it calls the tool.
Why the "when not" sentence matters
Models pick tools by matching the user's request against descriptions. If two tools both sound like they handle orders, the model may choose either. A "when not" sentence draws the boundary and names the neighbor.
Name the other tool explicitly. "Do not use for single orders" leaves the model without a next step. "If the user gives an order ID, use get_order instead" gives it one.
Writing guidelines
- Open with a verb phrase that states the action: "Search...", "Cancel...", "Return...".
- Use the same words as your users and your other tools. If the tool says "customer" in one place, do not say "account" in another.
- Put the most important boundary early. Long descriptions can bury it.
- Describe behavior, not implementation. The model does not need to know which database you query.
- State side effects. Say so if the tool sends an email, charges a card, or deletes data.
- Keep it to a few sentences. Details about individual arguments belong in the parameter descriptions, which a later chapter covers.
Common errors
- Restating the name. "Gets order" adds nothing to
get_order. - Marketing language. "Powerful, flexible order tool" gives the model no selection criteria.
- No boundary. Two tools with similar descriptions will be confused.
- Hidden preconditions. If the tool needs a customer ID the model may not have, say "Ask the user if you do not know it."
Exercise
A tool cancel_order has the description "Cancels an order." Rewrite it so it says what, when, and when not. Assume that only orders with status "pending" can be cancelled and that get_order returns an order's status.
Show answer
For example: "Cancel a pending order and refund the customer. Use this only after the user has clearly asked to cancel a specific order. Only orders with status 'pending' can be cancelled. If you are not sure of the status, call getorder first. For shipped or delivered orders, do not call this tool. Tell the user it cannot be cancelled." This version states the action and its side effect (what), the trigger (when), and the boundary with a pointer to getorder (when not).