Sub topic 2
The parts of a tool definition: name, description, input schema
A model never sees your code. It sees a short text description of each tool and decides from that text which tool to call and what arguments to send. This chapter covers the three parts of that description.
This chapter assumes you have called an LLM API before, can read JSON, and know the basic JSON Schema types (string, integer, object, array).
The three parts
A tool definition has three fields:
| Part | Role | Who reads it |
|---|---|---|
| `name` | Identifier the model emits when it calls the tool | Model and your dispatch code |
| `description` | Says what the tool does, when to use it, and when not to | Model |
| `input_schema` | JSON Schema describing the arguments | Model, and optionally your validator |
The examples here use the Anthropic-style field name input_schema. OpenAI-style APIs call the same field parameters, and the content is the same kind of JSON Schema.
A well-formed definition
{
"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.",
"input_schema": {
"type": "object",
"properties": {
"customer_id": {
"type": "string",
"description": "Customer ID, for example 'cus_4821'. Ask the user if you do not know it."
},
"status": {
"type": "string",
"enum": ["pending", "shipped", "delivered", "cancelled"],
"description": "Only return orders with this status. Omit to include all statuses."
},
"created_after": {
"type": "string",
"description": "Only return orders created on or after this date, in YYYY-MM-DD format."
},
"limit": {
"type": "integer",
"minimum": 1,
"maximum": 50,
"description": "Maximum number of orders to return. Defaults to 10 if omitted."
}
},
"required": ["customer_id"]
}
}Each part does a separate job.
- Name.
search_ordersis a verb plus a noun. The model copies it into its tool call, so your code can match it exactly. - Description. It states the purpose, when to use the tool, a boundary (use
get_orderwhen an ID is given), and what comes back. - Input schema. The top level is always
"type": "object". Underproperties, each argument has a type. Theenumlimitsstatusto four values.minimumandmaximumboundlimit. Therequiredarray lists onlycustomer_id.
A weak definition for contrast
{
"name": "do_order_thing",
"description": "Handles orders.",
"input_schema": {
"type": "object",
"properties": {
"data": { "type": "string" },
"mode": { "type": "string" }
}
}
}The model has to guess everything here. The name hides the action. The description gives no use or boundary. data and mode are untyped free text with no hint of what to send. Nothing is marked required, so the model may send an empty call.
Common errors
- Leaving out
descriptionbecause the name seems obvious. The model has no other source for the boundary between similar tools. - Describing a parameter only by its name, such as
"date": {"type": "string"}, with no format. - Writing a schema that is valid JSON but not valid JSON Schema, such as a top level that is not an object.
- Assuming the schema is enforced. The model usually follows it, but your server must still check arguments.
Exercise
A tool has the name process, the description "Processes things", and a single parameter input of type string. Name two parts of the definition you would change first, and say what each should contain.
Show answer
First, the name and description. Rename the tool to a verb plus noun that states the action, such as cancel_order. Rewrite the description to say what the tool does, when to use it, when not to (for example, use get_order to only look up an order), and what it returns. The input parameter should also be replaced with typed, described parameters, such as a required order_id string with an example like 'ord_1001'.