Claude API Custom Tool Definition Examples That Work
If you're searching for Claude API custom tool definition examples, you're probably past the "hello world" stage and need real schemas for real tools — database lookups, API calls, calculators, file operations. This article walks through working tool definitions you can adapt directly, plus the schema rules that trip people up.
A tool definition in the Claude API is a JSON object with a name, a description, and an input_schema that follows JSON Schema conventions. Claude reads these definitions to decide when and how to call your tool, then returns a structured tool_use block you parse and execute yourself. Get the schema wrong and Claude either ignores the tool, calls it with malformed arguments, or hallucinates fields that don't exist. The examples below show the patterns that actually work in production.
A minimal but correct tool definition
Here's the simplest tool that still follows best practices — a weather lookup:
{
"name": "get_weather",
"description": "Get the current weather for a specific city. Returns temperature in Celsius and a short condition summary.",
"input_schema": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "The city name, e.g. 'Berlin' or 'San Francisco'"
},
"units": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "Temperature unit, defaults to celsius if omitted"
}
},
"required": ["city"]
}
}
Three things matter here. First, the description on the tool itself should explain what it does and when to use it, not just repeat the name. Second, every property needs its own description — Claude uses these to decide what value to extract from the user's message. Third, required should list only the fields that genuinely need a value; optional fields with sane defaults reduce unnecessary clarifying questions.
Example: a database query tool with nested structure
Real tools often need structured input, not just flat strings:
{
"name": "query_orders",
"description": "Query customer orders by date range and status. Use this when the user asks about order history or order status.",
"input_schema": {
"type": "object",
"properties": {
"customer_id": {
"type": "string",
"description": "The customer's unique ID"
},
"date_range": {
"type": "object",
"properties": {
"start": { "type": "string", "description": "ISO 8601 date, e.g. 2024-01-01" },
"end": { "type": "string", "description": "ISO 8601 date, e.g. 2024-12-31" }
},
"required": ["start", "end"]
},
"status": {
"type": "string",
"enum": ["pending", "shipped", "delivered", "cancelled"]
}
},
"required": ["customer_id", "date_range"]
}
}
Nested objects work fine, but keep nesting to two levels max — deeper structures increase the chance Claude fills them in inconsistently.
Example: a calculator tool with strict typing
For anything mathematical, lock down types tightly so you don't have to sanity-check strings-that-look-like-numbers:
{
"name": "calculate",
"description": "Perform a basic arithmetic calculation. Use this for any math the user asks about instead of computing it yourself.",
"input_schema": {
"type": "object",
"properties": {
"operation": {
"type": "string",
"enum": ["add", "subtract", "multiply", "divide"]
},
"a": { "type": "number" },
"b": { "type": "number" }
},
"required": ["operation", "a", "b"]
}
}
Adding "Use this instead of computing it yourself" to the description noticeably reduces cases where Claude does mental math and skips the tool call entirely.
Defining multiple tools together
When you give Claude several tools, each name must be unique and descriptions must clearly differentiate purpose — overlapping descriptions cause Claude to pick the wrong tool:
curl https://api.subtoapi.app/v1/messages \
-H "Authorization: Bearer $SUBTOAPI_KEY" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-4",
"max_tokens": 1024,
"tools": [
{"name": "get_weather", "description": "...", "input_schema": {...}},
{"name": "query_orders", "description": "...", "input_schema": {...}},
{"name": "calculate", "description": "...", "input_schema": {...}}
],
"messages": [
{"role": "user", "content": "What is the weather in Lisbon and what is 42 * 17?"}
]
}'
This example routes through SubToAPI's /v1/messages endpoint, which wraps standard Claude message and tool semantics behind a sub_live_... API key — so if you're already building with Claude's tool-use format, switching the base URL and key is the only change needed. Full schema details are in /docs/tools and a runnable end-to-end example is in /docs/quickstart.
Handling the tool_use response
Claude's response contains a tool_use content block, not the final answer:
{
"type": "tool_use",
"id": "toolu_01A2B3",
"name": "get_weather",
"input": { "city": "Lisbon" }
}
You execute the tool yourself and send the result back as a tool_result block referencing that same id, in a follow-up message. Claude then produces the final natural-language answer. This round trip is the part most tutorials gloss over — budget for it in your latency expectations, especially with multiple sequential tool calls.
Common mistakes in custom tool schemas
- Vague descriptions. "Get data" tells Claude nothing about when to call it. Be specific about triggering conditions.
- Missing
enumconstraints. If a field only accepts five values, declare them — don't rely on the description text alone. - Over-nesting objects. Flatten where possible; deeply nested schemas increase malformed-argument rates.
- No
requiredarray. Without it, Claude may omit fields it should have filled. - Reusing generic names like
searchacross unrelated tools, which makes routing ambiguous when multiple tools are active at once.
If you're prototyping and want to skip infrastructure setup, /signup gives you a free trial key, and /pricing covers the Solo, Team, and Scale tiers if you move past experimentation into production tool-calling workloads.
questions
Do tool input schemas support all JSON Schema features? Claude supports a practical subset: type, properties, required, enum, and nested object/array types. Advanced JSON Schema features like oneOf or $ref are not reliably honored, so stick to flat, explicit definitions.
Can I define more than one tool in a single request? Yes — pass an array under tools. Claude picks which one (if any) to call based on the user's message and each tool's description, so keep descriptions distinct to avoid ambiguous routing.
What happens if Claude calls a tool with invalid arguments? It can happen, especially with loosely typed schemas. Validate tool_use.input against your schema before executing, and return a tool_result with an error message if validation fails — Claude will usually retry with corrected input.