Sub topic 10
Keeping similar tools distinguishable
This chapter assumes you have read the earlier chapters on tool names, descriptions, and granularity. It also assumes you can read short Python examples and JSON Schema. A model chooses between tools by comparing their names, descriptions, and schemas. When two tools look alike in those fields, the model guesses, and the guess changes from run to run.
Why overlap causes failures
Suppose a support assistant has get_order and search_orders. A person can tell them apart from experience. The model has only the text you wrote. If both descriptions say "Finds order information," nothing in that text separates them.
Overlap produces three kinds of failure:
- Wrong tool. The model calls
search_orderswith a guessed customer ID when the user already gave an order ID. - Unstable choice. The same prompt picks different tools on different runs, so a test passes once and fails the next time.
- Wasted calls. The model calls one tool, finds it was the wrong one, then calls the other. This costs latency and tokens.
Overlap comes from three places: descriptions that share generic verbs, tools whose inputs and outputs are nearly the same, and tools that each cover part of the same job. Fix the cause that applies. Do not rewrite everything.
First decide whether the tools should stay separate
Rewording cannot fix tools that should not exist in their current form. Before you edit descriptions, check three things.
- Do the tools differ in input?
get_order(order_id)andsearch_orders(customer_id, ...)take different inputs and answer different questions. That is a real difference, and a description can state it. - Do they differ only in a mode flag? If you have
get_order_summaryandget_order_detailsand both take an order ID, the split is cosmetic. Merge them and add an enum parameter such asdetail: "summary" | "full". - Does one tool secretly do two jobs? The weak
do_order_thingwith a free-textmodeparameter hides several actions behind one name. Split it into tools whose names state the action.
Merge when the tools share the same inputs and differ in output size. Split when the inputs, side effects, or permissions differ. Reading a record and cancelling a record should never share a tool, because the model can mistake one for the other.
Write descriptions as a pair
Once the tools are properly separate, write their descriptions together and treat them as one unit. Each description should contain four parts:
- What the tool does, in one sentence.
- The input condition that selects it, such as "Use this when the user gives an order ID."
- The sibling to use instead when that condition is false, named exactly.
- What it returns, so the model knows whether the result will answer the question.
Here is a pair written this way:
[
{
"name": "get_order",
"description": "Fetch one order by its order ID. Use this when the user gives an ID like 'ord_1001'. If you only have a customer ID or a date range, use search_orders instead. Returns id, status, total, created_at, and line items.",
"input_schema": {
"type": "object",
"properties": {
"order_id": {
"type": "string",
"description": "Order ID, for example 'ord_1001'."
}
},
"required": ["order_id"]
}
},
{
"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, but no line items.",
"input_schema": {
"type": "object",
"properties": {
"customer_id": {
"type": "string",
"description": "Customer ID, for example 'cus_4821'."
}
},
"required": ["customer_id"]
}
}
]Each description names the other tool and states a different trigger. The return notes also differ: only get_order returns line items, so a question about what was in an order points to get_order.
Prefer observable conditions
Write the selection rule in terms the model can check in the user's message. "Use this when the user gives an order ID" is checkable. "Use this for specific orders" is not, because "specific" is a judgment. The first rule gives the model something to look for. The second leaves it to decide.
Keep the cross-references accurate
The "use X instead" lines are text you maintain by hand. If you rename get_order to get_order_by_id, every description that mentions it is now wrong, and the model may try to call a tool that does not exist. Search your definitions for old names whenever you rename a tool.
How the model decides
The decision looks roughly like this:
If you cannot draw a tree like this for your tools, the descriptions cannot express one either. Drawing it is a good way to find missing branches. In this tree, the branch where no ID is known is handled by the parameter description ("Ask the user if you do not know it"), not by a third tool.
Use names and parameters to help
Descriptions carry most of the weight, but names and schemas add signal.
- Names that differ in the part that matters.
get_orderandsearch_ordersdiffer in the verb, which tells the model one fetches by key and the other filters. Names such asorder_lookupandorder_finderdiffer in nothing a reader could use. - Parameter names that expose the input. A required
order_idon one tool and a requiredcustomer_idon the other makes the choice almost mechanical. If both tools take a genericquerystring, the schema gives no help. - Enums that narrow scope. If two tools differ by data source, an enum on a single tool (
source: "orders" | "returns") is often clearer than two near-identical tools.
Measure confusion, not only accuracy
A single accuracy number tells you something is wrong but not which tools are being mixed up. Count how often each expected tool is mistaken for each other tool. This code extends the evaluation loop from the earlier chapter:
from collections import Counter
CASES = [
("Where is order ord_1001?", "get_order"),
("What did I buy in order ord_1001?", "get_order"),
("Show me my cancelled orders from last month", "search_orders"),
("List everything customer cus_4821 ordered", "search_orders"),
("What is the capital of France?", None),
]
def confusion(choose_tool):
"""Count (expected, actual) pairs for every test case."""
counts = Counter()
for prompt, expected in CASES:
counts[(expected, choose_tool(prompt))] += 1
return counts
def report(counts):
for (expected, actual), n in sorted(counts.items(), key=str):
mark = "ok " if expected == actual else "BAD"
print(f"{mark} expected={expected} actual={actual} x{n}")
def fake_choose_tool(prompt):
# Stand-in for a real model call: always picks a tool.
return "get_order" if "ord_" in prompt else "search_orders"
report(confusion(fake_choose_tool))The fake chooser always picks a tool, so it fails the last case. That mirrors a real failure: models often call a tool when none is needed, and the off-diagonal row expected=None actual=search_orders shows it. Replace fake_choose_tool with a function that calls your model and returns the name of the first tool it requested, or None.
Write test prompts that sit on the boundary. "What did I buy in order ord_1001?" mentions an order ID but also sounds like a search. Easy prompts will pass whatever the descriptions say.
Iterate on one change at a time
Change one description, rerun the same cases, and compare the confusion counts. If you change both descriptions and a schema together, you cannot tell which edit helped. Run each case several times, because tool choice varies between runs at nonzero temperature. A case that passes three times in five is a real defect, not noise.
Common mistakes
| Mistake | Effect | Fix |
|---|---|---|
| Same opening sentence in both descriptions | Model sees no difference | Lead with what each tool takes as input |
| Cross-reference to a renamed tool | Model calls a missing tool | Search all definitions after a rename |
| Two tools differing only by output size | Choice is arbitrary | Merge and add a `detail` enum |
| Vague rule such as "for specific orders" | Model must judge | Use a condition visible in the message |
| Testing only easy prompts | Confusion stays hidden | Add boundary prompts to the test set |
Exercise
A toolset has get_customer_profile(customer_id) and get_customer_summary(customer_id). Both descriptions say "Gets information about a customer." The model picks between them at random. What two changes would you consider, and how would you decide between them?
Show answer
First check whether the split is real. Both tools take the same input and differ only in how much they return, so the better fix is usually to merge them into one get_customer tool with a detail enum (summary or full) and describe what each value returns. If the tools differ in cost, permissions, or data source and must stay separate, rewrite the descriptions as a pair. Each should state what it returns (for example, "name and email only" versus "name, email, address, and payment methods"), when to use it, and which sibling to use otherwise. Then add boundary prompts to the test set and compare confusion counts before and after.