Module 4 · Structured outputs & tools
Function calling and tool descriptions
7 min read
When a model has tools, it chooses by itself which one to call, and with which arguments. It sees only three things about each tool: its name, its description and its parameter schema. A tool's description is therefore a prompt, often the most neglected one in the application. This lesson measures the effect of vague or precise descriptions on tool choice, then shows the tool format with the Claude API.
The experiment
A back-office assistant has six tools: order status, refund, supplier invoice, contract search, support ticket and stock. Names and parameters are identical in both versions; only the descriptions change.
VAGUE = {
"get_order_status": "Commande.",
"refund_order": "Remboursement.",
"get_invoice": "Facture.",
"search_contracts": "Recherche.",
"create_ticket": "Ticket.",
"get_stock": "Produits.",
}
Precise descriptions say what the tool does, when to use it, when not to use it, and the format of identifiers:
PRECISE = {
"get_order_status": "Donne l'état d'expédition d'une commande client (préparée, expédiée, livrée) à partir de "
"son numéro au format CMD-12345. À utiliser pour « où en est ma commande ». Ne rembourse rien.",
"refund_order": "Déclenche le remboursement d'une commande client, total ou partiel. N'utiliser que si "
"l'utilisateur demande explicitement un remboursement et donne le numéro CMD-xxxxx.",
"get_invoice": "Renvoie une facture FOURNISSEUR (achats) à partir de son numéro au format F-12345. "
"Pas pour les commandes clients.",
"search_contracts": "Recherche en texte libre dans les contrats fournisseurs signés (clauses, durées, "
"pénalités, conditions de paiement). À utiliser pour toute question sur ce que prévoit un contrat.",
"create_ticket": "Crée un ticket pour l'équipe support quand aucun autre outil ne permet de répondre ou "
"qu'une intervention humaine est nécessaire. priority « haute » si le client est bloqué.",
"get_stock": "Donne la quantité disponible en entrepôt pour un produit du catalogue (nom ou référence), "
"pour savoir si on peut livrer.",
}
24 realistic requests, four per tool, are submitted to Qwen2.5-1.5B with each set of descriptions. Tools use the "function" format that open models' chat templates understand:
def tool_specs(descriptions: dict[str, str]) -> list[dict]:
"""Format « function » accepté par les chat templates (Qwen, Llama…) et, à la clé près, par l'API Claude."""
return [{"type": "function", "function": {
"name": name, "description": descriptions[name],
"parameters": {"type": "object", "properties": params, "required": list(params)}}}
for name, params in SHAPES.items()]
| Descriptions and system prompt | Right tool | Wrong tool | No tool called |
|---|---|---|---|
| Vague | 0.54 | 0 | 11 / 24 |
| Precise | 0.58 | 0 | 10 / 24 |
| Precise + calling instruction in the system prompt | 0.75 | 0 | 6 / 24 |
The result defeats the starting hypothesis. The model never picked the wrong tool, even with one-word descriptions: when it calls a tool, it is the right one. The names (get_order_status, refund_order…) and the request numbers (CMD-, F-) are enough here. Its real flaw lies elsewhere: in nearly one request out of two, it calls no tool at all and answers like a human promising to act:
D'accord, je vais vérifier l'état de votre commande CMD-31277. Veuillez patienter quelques instants.
For an agent, this is the most serious failure: the user believes an action is under way, and nothing happens. Precise descriptions barely change it (10 instead of 11). What changes the result is one sentence in the system prompt saying when to call a tool:
SYSTEM_CALL = (SYSTEM + " Chaque demande correspond à exactement un outil : appelle-le toujours, même si un "
"paramètre te semble incomplet, plutôt que de répondre ou de poser une question.")
With it, the right-tool rate rises from 0.58 to 0.75. Two lessons:
- measure the right failure: "right tool" mixes two very different errors, the wrong tool and the missing call. Separating them showed that the second was the only one here;
- the usage instruction matters as much as the descriptions: when to call, when to answer directly, when to ask for clarification. It belongs in the agent's system prompt (lesson 4.3).
Writing a good tool description
| Element | Example |
|---|---|
| What the tool does, concretely | "Gives the shipping status of a customer order" |
| When to use it | "Use for 'where is my order'" |
| When not to use it | "Not for customer orders"; "Does not refund anything" |
| Parameter format | "Number in the CMD-12345 format" |
| Side effects | "Triggers the refund": the tool acts, it does not just read |
| Boundaries with neighboring tools | supplier invoice versus customer order |
In our experiment, the model confused no tools; with a model more inclined to act, or more numerous tools, confusions almost always come from neighboring tools: get_invoice and get_order_status both talk about money and numbers. The description must draw the boundary explicitly. Names matter too: get_invoice is ambiguous, get_supplier_invoice is not.
The tool format with Claude
The Claude API uses input_schema instead of parameters. The conversion is mechanical:
def to_claude_tools(specs: list[dict]) -> list[dict]:
"""Convertit le format « function » (chat templates, autres API) vers le format Claude."""
out = []
for s in specs:
f = s["function"]
schema = {**f["parameters"], "additionalProperties": False}
out.append({"name": f["name"], "description": f["description"], "input_schema": schema})
return out
With strict: true, arguments are guaranteed to match the schema, as with structured outputs (lesson 4.1). Strict mode requires "additionalProperties": false, hence its addition during conversion.
def call_tools(request: str, tools: list[dict], system: str) -> list[tuple[str, dict]]:
"""Outils au format Claude : `input_schema`, et `strict` pour garantir des arguments conformes."""
response = client().messages.create(
model=config.CLAUDE_MODEL,
max_tokens=2000,
system=system,
tools=[{**t, "strict": True} for t in tools],
messages=[{"role": "user", "content": request}],
)
return [(b.name, b.input) for b in response.content if b.type == "tool_use"]
Two differences from older practices:
- Forcing a tool (
tool_choiceset to "any" or to a tool name) returns a 400 error on Opus 5.5 and Sonnet 5.5. You guide the choice through the system prompt and the descriptions, which makes them even more important; - The model can call several tools at once when the calls are independent (the status of two orders, for instance): the code must handle a list of calls, as
call_toolsdoes.
How many tools?
Each tool adds its description to every request, and each neighboring tool adds an opportunity for confusion. A few rules:
- merge redundant tools (one
searchwith ascopeparameter rather than five search tools); - beyond a few dozen tools, provide only those useful for the current task, or use a tool-search mechanism;
- test tool choice like any prompt: a set of requests, the expected tool, a score (lesson 5.2).
Key takeaways
- A tool's description is a prompt: the model sees only the name, the description and the schema.
- Here, the main failure was not the wrong tool but the missing call: a calling instruction takes the score from 0.58 to 0.75.
- Say what the tool does, when to use it, when not to, the parameter format and the side effects.
- Draw explicit boundaries between neighboring tools; choose unambiguous names.
- With Claude:
input_schema,strict: truefor guaranteed arguments; no forced tool choice on current models.- Measure tool choice on a set of requests, like any prompt.
Practice
- Run
examples/06_outputs_tools_injection.pyand list the requests where vague descriptions pick the wrong tool. - Add a seventh neighboring tool (
get_customer_invoice, customer invoice) and measure the new confusions, then fix them through the descriptions. - Check the arguments as well as the tool: is the CMD-xxxxx number copied correctly?