Sub topic 12
Designing tools the model uses well
This chapter assumes you can write a tool definition with a JSON Schema and run the tool-calling loop from earlier chapters. Here the question is different. The model can already call your tools, so how do you make it call them correctly?
The model never sees your code. It sees only the tool's name, its description, and its parameter schema. Those three things are the whole interface, so most tool-use failures trace back to them.
Name tools by what they do
Use a verb and an object, such as search_orders or get_invoice. Avoid vague names like process or handle_data. Keep names consistent across tools, so that all lookups use get_ and all changes use update_ or create_.
Write descriptions as instructions
A description should say what the tool does, when to use it, and when not to. The weather example uses this pattern: "Get the current temperature for a city. Use when the user asks about current weather."
If two tools overlap, say how they differ. Without that, the model has to guess.
{
"name": "search_orders",
"description": "Find a customer's orders by email address. Use when the user asks about past or pending orders. Returns at most 10 orders, newest first. Do not use to look up a single order by ID; use get_order for that.",
"parameters": {
"type": "object",
"properties": {
"email": {"type": "string", "description": "Customer email, for example [email protected]"},
"status": {"type": "string", "enum": ["pending", "shipped", "delivered", "cancelled"]}
},
"required": ["email"],
"additionalProperties": false
}
}Make parameters hard to misuse
- Use
enumfor fixed choices, so the model cannot invent a value. - Add an example to each
description, such asOslofor a city. - Mark only truly necessary fields as
required. - Set
additionalPropertiestofalseso stray arguments are rejected. - Prefer a few clear parameters over one free-text field that you must parse.
Keep the tool set small and focused
Each tool you add is more text the model must read and one more choice it can get wrong. Give a tool one clear job. If a single tool takes a mode argument that changes what it does, split it into separate tools. If you have dozens of tools, offer only those relevant to the current task.
Return results the model can use
Return only the fields the model needs, with readable keys. A 500-line raw database row wastes tokens and buries the answer. Cap long lists and say so, for example "showing 10 of 43". When a call fails, return an error that says how to fix it, as covered in the error-handling chapter.
{"orders": [{"id": "A-1042", "status": "shipped", "total": 59.90}], "shown": 1, "total_matches": 1}Common mistakes
| Mistake | Effect | Fix |
|---|---|---|
| Vague name or empty description | Model picks the wrong tool or never uses it | Verb-object name, "use when" sentence |
| Two tools that overlap | Inconsistent choice between them | State the difference in each description |
| Free-text parameter for a fixed set of values | Invented values | Use `enum` |
| Huge, unfiltered results | Cost, latency, lost answer | Trim fields and cap lists |
Exercise
A tool named data has the description "Gets data" and one string parameter called query. List three changes that would help the model use it well.
Show answer
Rename it to say what it does, for example search_orders. Rewrite the description to say what it returns, when to use it, and when not to. Replace the free-text query with specific typed parameters, using an enum for any fixed set of values, and add an example value to each parameter description.