Tool Definition Generator
Generate clean function/tool schemas for an LLM agent from existing code or a spec — accurate JSON Schema, model-facing descriptions, honest required fields, and enums that make invalid calls impossible. Use when wiring functions into an agent's tool-calling loop.
Most bad tool calls come from bad tool definitions, not a weak model. This skill turns a function or API operation into a tool schema written for the model: precise types, honest required fields, enums and bounds, and a description that says when to call it and when not to, plus test requests that check the model picks it correctly.
Install to ~/.claude/skills/tool-definition-generator/SKILL.md
npx agentscamp add skills/tool-definition-generatorWhen an agent calls the wrong tool or passes garbage arguments, the instinct is to blame the model. Far more often, the tool definition is the problem: a vague description, an enum left as a free string, a required field marked optional. This skill generates tool/function schemas that are written for the model, so correct calls are easy and invalid ones are impossible.
It defines the arguments a model passes into a function. For the shape of data a model returns as its final answer, use llm-output-schema-generator.
When to use this skill
- Wiring existing functions or API endpoints into an agent's tool-calling loop.
- An agent picks the wrong tool, omits required arguments, or passes malformed values.
- Standardizing tool schemas across an agent codebase.
Instructions
-
Read the source of truth. Derive the schema from the actual function signature, types, and docstring (or an OpenAPI operation). Then
Grepfor call sites to learn which arguments real callers pass, which defaults they rely on, and which combinations never occur. Never invent an argument name. -
Decide what the model should not control. Remove from the schema anything the runtime must supply: user or tenant IDs, auth tokens, idempotency keys, internal flags. Inject those in the tool executor. An argument the model can set is an argument a prompt injection can set.
-
Name and describe for the model, not the compiler. Use a
verb_nounname that is unambiguous next to the other tools. Write a description of three or four sentences that covers: what the tool does, when to use it, when not to use it and which tool to use instead, and what it returns, including what an empty result or an error looks like. -
Type every argument precisely. Use JSON Schema types and give each argument a description with units, format, and one example ("ISO 8601 date, e.g. 2026-11-28", "amount in USD cents"). Mark fields
requiredhonestly: required when the function cannot run without it, optional only when a real default exists, and say what the default is. -
Constrain with enums and bounds. Replace free strings with
enumwhere the set is known, addminimum,maximum, andpatternwhere they apply, and setadditionalProperties: falseso invented arguments are rejected. A constrained schema makes an invalid call structurally impossible instead of merely discouraged. -
Keep the surface tight. Fewer, well-scoped tools beat many overlapping ones. If two tools are easily confused, name the other tool in each description or merge them. If one tool has a
modeargument that switches between unrelated behaviors, split it. -
Emit in the target format. The schema body is the same everywhere; the envelope differs. Anthropic's Messages API takes
name,description, andinput_schema. OpenAI's Responses API takestype: "function",name,description, andparameters. Agent SDKs usually derive both from a decorated function or a Zod or Pydantic model, in which case edit the source types and docstrings and let the SDK generate. Both providers acceptstrict: trueon a tool to guarantee arguments match the schema, and strict modes support a subset of JSON Schema, so check the provider's current limitations before relying on bounds or patterns there. -
Verify. Validate the schema with a JSON Schema validator. Then write three or four realistic user requests per tool, including one that should not trigger it, and check that the arguments the model produces validate and match what a careful human would pass.
TIP
The description is doing prompt engineering. "Refund a charge. Use only after confirming the charge exists and the amount; do not use for subscription cancellations." prevents more misfires than any amount of system-prompt nagging.
NOTE
This generates the interface the model calls. The runtime still needs error handling and (for consequential actions) a human-in-the-loop-gate. A good schema reduces bad calls but doesn't replace guardrails.
Worked example
Source function (fictional):
def refund_charge(charge_id: str, amount_cents: int | None = None, reason: str = "requested_by_customer") -> Refund:
"""Refund a charge fully or partially. Raises ChargeNotFound, AlreadyRefunded."""A weak definition that mirrors the signature and nothing else:
{
"name": "refund",
"description": "Refunds a charge.",
"input_schema": {
"type": "object",
"properties": {
"charge_id": { "type": "string" },
"amount_cents": { "type": "number" },
"reason": { "type": "string" }
}
}
}Nothing is required, reason accepts any string, the amount can be negative or fractional, and the model cannot tell this tool from a subscription-cancel tool.
The generated definition, in Anthropic's tool format:
{
"name": "refund_charge",
"description": "Refund a single card charge, fully or partially, back to the original payment method. Use only after you have looked up the charge with get_charge and the user has confirmed the amount. Do not use to cancel a subscription (use cancel_subscription) or to refund a charge that get_charge reports as already refunded. Returns the refund ID and status; returns an error with code charge_not_found or already_refunded if the refund cannot be made.",
"input_schema": {
"type": "object",
"properties": {
"charge_id": {
"type": "string",
"pattern": "^ch_[A-Za-z0-9]+$",
"description": "ID of the charge to refund, exactly as returned by get_charge, e.g. ch_3Abc123"
},
"amount_cents": {
"type": "integer",
"minimum": 1,
"description": "Amount to refund in the charge's currency, in minor units (USD $12.50 -> 1250). Omit to refund the full remaining amount."
},
"reason": {
"type": "string",
"enum": ["requested_by_customer", "duplicate", "fraudulent"],
"description": "Why the refund is being issued. Defaults to requested_by_customer when omitted."
}
},
"required": ["charge_id"],
"additionalProperties": false
}
}For OpenAI's Responses API the same definition becomes {"type": "function", "name": "refund_charge", "description": "...", "parameters": { ...the same schema... }}.
Test requests for the verification step: "refund order 1042's charge in full" (expect a get_charge call first, then refund_charge with no amount_cents); "give them $5 back on ch_3Abc123" (expect amount_cents: 500); "cancel my plan and refund me" (expect cancel_subscription, not this tool, as the first call).
Output
For each tool, return:
- The definition in the target format, with a description on the tool and on every argument.
- A short change list against the previous definition or the raw signature: what became required, which strings became enums, which arguments were removed from the model's control.
- The test requests with expected tool and arguments, and the result of running them if a model was available.
- Open questions where the source did not settle a type, a default, or an allowed value.
Filed under
Related
- AgentAgent Tool Integration EngineerUse this agent to wire tools and function-calling into an agent loop reliably — clean tool schemas, errors fed back as observations, retries with limits, idempotency, and parallel calls. Examples — "connect our APIs as agent tools", "our agent calls tools wrong / ignores tool errors", "add function-calling with proper error recovery to our agent".
- GuideProduction Tool & Function Calling: Feed Errors Back as ObservationsHow agents use tools: the call, observe, retry loop, a weak vs strict tool schema, error results the model can act on, idempotency keys, and default caps.
- SkillLLM Output Schema GeneratorTurn an example of the data you want from an LLM into a precise, validated output schema (Pydantic / Zod / JSON Schema) and wire it into structured-output calls. Use when adding typed LLM output, replacing brittle JSON parsing, or designing an extraction shape.
- GuideWhich Agent Framework in 2026? LangGraph vs CrewAI vs AutoGen vs OpenAI Agents SDK vs Claude Agent SDK vs Pydantic AIA decision guide to the major AI agent frameworks — control vs. abstraction, multi-agent models, state and durability, and which fits your project.
- SkillOpenAPI Doc WriterProduce and maintain OpenAPI documentation for an HTTP API. Use when documenting endpoints, request/response schemas, or generating API reference docs.
- TermFunction Calling (Tool Calling)Function calling lets an LLM request structured invocations of your code: describe tools with schemas, the model emits typed calls, your app executes them.
- Guide7 Best Claude Skills for MCP Server DevelopmentClaude skills, commands, and agents for building MCP servers: scaffolding, tool schemas, Inspector testing, safe registration, config audits, code review, and plugins.
- Guide9 Best Claude Skills for Prompt EngineeringCompare Claude skills for prompt rewrites, regression harnesses, output schemas, tool definitions, prompt caching, PII redaction, and CLAUDE.md memory.