Sub topic 1
How a Model Sees and Calls Your Tools
Prerequisites
Assume you can call an LLM API, read and write JSON, and recognize basic JSON Schema types such as string, integer, and object. This chapter focuses on how tool definitions guide model behavior.
How a Model Sees and Calls Your Tools
A tool is a structured operation that your application makes available to the model. The model does not inspect your implementation. It sees the tool's name, description, input schema, and often the results returned after a call.
During a tool-calling loop, the model:
- Reads the user's request and the available tool definitions.
- Chooses a tool, or decides that no tool is needed.
- Produces arguments that match the input schema.
- Your server validates and runs the tool.
- Your application sends the result back to the model.
- The model answers the user or makes another tool call.
The Parts of a Tool Definition
A useful definition has three connected parts:
- Name: A stable identifier the model can distinguish from other tools.
- Description: The tool's purpose, its appropriate use, and important boundaries.
- Input schema: A JSON Schema object describing accepted arguments.
{
"name": "get_order",
"description": "Get one order by ID. Use this when the user provides an order ID. Do not use it for searches by status or date; use search_orders instead.",
"input_schema": {
"type": "object",
"properties": {
"order_id": {
"type": "string",
"description": "Order ID such as 'ord_1001'."
}
},
"required": ["order_id"],
"additionalProperties": false
}
}Choosing Names and Writing Descriptions
Use consistent, specific names with an action and an object, such as get_order or search_orders. Avoid vague names such as handle_order.
Descriptions should answer three questions:
- What does the tool do?
- When should the model use it?
- When should the model use another tool instead?
This explicit contrast helps when tools overlap. Include format hints where the schema cannot express the full rule, such as date format or an example identifier.
Defining Parameters with JSON Schema
Give every parameter a precise type. Use enum for a fixed set of values, minimum and maximum for numeric bounds, and required for values the tool cannot operate without. Mark filters and optional controls as optional, and explain their defaults in their descriptions.
Exercise
A model uses get_order for “Show my cancelled orders.” What definition change would help?
Show answer
State that get_order requires one order ID and must not be used for status searches; direct that request to search_orders.