Tool Schemas
Tools are declared, then chosen
A tool's schema decides how often the model calls it and how reliably. Name, description and argument JSON Schema are product decisions: crisp semantics raise call quality, tight validation keeps execution safe.
What you will learn
- Write a precise tool definition
- Design argument schemas the model fills well
- Decide when it's better NOT to expose a tool
What is this?
A tool definition is name + description + JSON-schema arguments. The name should be an unambiguous verb-noun; the description states what it does AND when to use it; the schema keeps argument fields flat, bounded and realistic. These three decide selection accuracy, argument validity, and downstream safety.
Why do you need it?
- Descriptions are the model's only selection signal — write them like docs.
- Tight schemas produce safer, more consistent execution.
- Fewer, focused tools beat exhaustive lists that confuse selection.
- Schema reuse with structured-output validation keeps code honest.
Mental model
A restaurant menu
Tool definitions
The menu must describe each dish (tool) so you order the right one for tonight. Dishes that sound identical or overly similar confuse the choice. A crisp, uncrowded menu with exact ingredients (schema) is ordered correctly every time.
How it works
- Name: verb + noun, verbs of action; consistent casing.
- Description: what it does + one line about when to call.
- Arguments: JSON Schema — required minimal, enums for closed sets.
- Return-shape hints (if supported) scope what the model does with results.
- Ship ≤ a few tools per turn before grouping introduces noise.
Anatomy of a tool.
Examples
A crisp tool
const getWeather = { name: "get_weather", description: "Returns current weather for a city. Use when the user asks about weather or conditions.", parameters: { type: "object", properties: { city: { type: "string", description: "City name as spoken by the user" }, unit: { type: "string", enum: ["celsius", "fahrenheit"] }, }, required: ["city"], additionalProperties: false, },};Name, when-to-use description, minimal required args, one enum.
In production
- Search, DB and math utilities expose one crisp tool each.
- Write-path tools enforce read/write separation in schemas.
- Versioned tools keep evals comparable across deploys.
Best practices
- One responsibility per tool; overlap invites misfires.
- Required = truly required; optional cover the rest.
- Give enums, not free text, for closed sets.
- Run eval cases: does the model pick the right tool for the input?
Common mistakes
- Vague descriptions ('processes data') that invite wrong calls.
- Thirty tools when three would cover the UX.
- Required params the model can't reliably derive.
Common issues
Two tools get confusedOverlapping descriptions
Narrow both; add explicit disambiguation notes.
Schema rejects the model's natural argsToo strict or type-mismatched
Sample actual args; relax bounds or widen enums.
Debugging tips
- Tool misfires → compare descriptions pairwise; disambiguate.
- Args rejected often → log real args; square schema with them.
- Model ignores a great tool → description missing the 'use when' clause.
Interview checkpoint
Hands-on lab
- Express a tool's contract as parameters and required fields
- Validate arguments before dispatching to the function
- Report missing and wrong-typed arguments cleanly
Schema-Driven Dispatcher
30 min · intermediate
Quick quiz
Which field most steers the model to call a tool?
More tools always improve function calling.