Sub topic 3
Defining a Tool: Name, Description, Parameters
This chapter assumes you know how chat messages and roles work, and that you can read basic JSON Schema (type, properties, required). Here you will write the definition the model reads before it decides to call a function.
What a tool definition is
A tool definition is a JSON object you send with your chat request. It tells the model what a function is called, when to use it, and what arguments it takes. The model never sees your code. It sees only this description.
A definition has three parts:
- name: the identifier the model returns when it wants the tool.
- description: plain text that tells the model when to use the tool.
- parameters: a JSON Schema object that describes the arguments.
{
"name": "get_weather",
"description": "Get the current temperature for a city. Use when the user asks about current weather.",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "City name, for example Oslo"},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
},
"required": ["city"],
"additionalProperties": false
}
}Providers wrap this differently. Some nest it under a function key, and some call the schema field input_schema instead of parameters. The three parts are the same everywhere. Check your provider's reference for the exact wrapper.
The name
Use a short verb-and-noun name such as get_weather or search_orders. Many providers limit names to letters, digits, underscores, and hyphens. Pick names that differ clearly from each other. If two tools are called lookup and find, the model has to guess.
The description
The description is the most important field. The model uses it to decide whether to call the tool at all. A good description covers two things:
- What the tool does.
- When to use it, and when not to.
Compare these two:
| Weak | Better |
|---|---|
| "Weather tool." | "Get the current temperature for a city. Use when the user asks about current weather. Does not give forecasts." |
If the model calls a tool at the wrong time, the description is the first thing to fix.
The parameters
The parameters field is a JSON Schema. The top level should be "type": "object", with each argument listed under properties. Several keywords matter most:
requiredlists the arguments the model must supply. Anything not listed is optional.enumlimits a value to a fixed set. This works well for options such asunit.descriptionon each property explains the format and gives an example.additionalProperties: falserejects arguments you did not define.
Some providers support a strict mode that enforces the schema when the model generates arguments. Without it, the schema is guidance, not a guarantee. You still have to validate the arguments in your own code, which a later chapter covers.
Common mistakes
- A vague description that never says when to use the tool.
- Missing
required, so the model leaves out arguments your function needs. - Free-text strings where an
enumwould work. - Many overlapping tools, which make the choice harder.
Exercise
A tool named search has the description "Searches stuff." The model keeps calling it for questions it could answer itself. Which field do you change first, and what should the new text include?
Show answer
Change the description. It should say what the tool searches (for example, the company's product catalog), when to use it (only for facts the model cannot know), and when not to use it. You can also rename the tool to something specific, such as search_product_catalog.