Validate server-side
Never trust tool arguments because the model 'should' follow the schema. Validate types, enums, ranges and permissions in your application before executing any action.
Describe when not to use a tool
Good tool descriptions reduce misfires. Include boundaries, required preconditions and examples of cases where a different tool is the right choice.
| Tool contract | The name, description, input schema and output shape exposed to the agent. |
| Idempotency key | A stable identifier that makes repeated calls safe to retry. |
| Tool result | Structured output returned to the model, including errors. |
- An agent must call business systems.
- Tool calls are unreliable or duplicated.
- Permissions differ across operations.
- 01Define one narrow tool per intent, with a typed input schema.
- 02Write descriptions that say when not to use the tool.
- 03Return structured errors the model can reason about.
- 04Add idempotency and server-side validation before execution.
Order lookup with a narrow schema
- Context
- An agent needs to fetch an order by ID.
- Problem
- It guesses IDs and calls the tool with malformed arguments.
- Approach
- Constrain the ID with a pattern, describe when not to use the tool and return actionable errors.
- Outcome
- Fewer invalid calls and clearer recovery when an order is missing.
Retry-safe refund tool
- Context
- A refund call may be retried after a network timeout.
- Problem
- A retry could issue the same refund twice.
- Approach
- Require an idempotency key and return an explicit success state.
- Outcome
- Safe retries without duplicate payouts.
Typed tool contract
json
{
"name": "lookup_order",
"description": "Fetch an order by ID. Use only when the user provides an order ID. Do not guess IDs.",
"input_schema": {
"type": "object",
"properties": {
"order_id": { "type": "string", "pattern": "^ORD-[0-9]{6}$" }
},
"required": ["order_id"],
"additionalProperties": false
}
}Narrow schemas, enums/patterns and `additionalProperties: false` make validation failures actionable.
Return actionable errors
json
{
"ok": false,
"error": {
"code": "ORDER_NOT_FOUND",
"message": "No order matches ORD-104200.",
"retryable": false,
"next_step": "Ask the user to confirm the order ID."
}
}Many small tools
Up: Clear choices, easy permissions
Down: More context to describe them
Few broad tools
Up: Compact context
Down: Ambiguous arguments and wide permissions
Free-form arguments
Up: Flexible
Down: Frequent validation failures
| Option | Upside | Cost |
|---|---|---|
| Many small tools | Clear choices, easy permissions | More context to describe them |
| Few broad tools | Compact context | Ambiguous arguments and wide permissions |
| Free-form arguments | Flexible | Frequent validation failures |
- Use descriptive tool names with verbs.
- Include units, formats and examples in the schema.
- Make errors actionable: what went wrong and what to try instead.
- Deny unknown fields in validation.
| Key | Typical value | Note |
|---|---|---|
| tool_scope | read/write split | Grant per role. |
| timeout | short | Fail fast and retry safely. |
| idempotency | required for writes | Prevents duplicate actions. |
| Symptom | Cause | Fix |
|---|---|---|
| Agent calls a tool repeatedly | Ambiguous result or no idempotency | Return explicit success state and require idempotency keys. |
| Invalid arguments | Weak schema description | Add types, enums and examples. |
How many tools should an agent see?
Only those needed for the current step. Too many choices degrade tool selection.
Should errors be hidden from the model?
No. Structured, actionable errors help the agent recover or ask for help.
More in Context & protocols