Fix the Tool Schema: Read the Trace, Fix the Card, Re-Run (Four Real Schema Bugs)
Four broken tool cards from a refund app: amount left out of required, an enum the backend doesn't accept, a phone typed as a number one level down, and two tools with the same description. Read the trace, fix the card, run it again.
What you will learn
- Map a failing tool call trace to the part of the tool card that caused it
- Fix a missing required field, a wrong enum and a wrong nested type
- Separate two tools whose descriptions overlap
- Explain why patching the handler leaves the bug in place
Before you start
- Tool input schemas and error responses
- Tool descriptions: how Claude picks a tool
A customer writes: refund order A-102, the full 120. The agent calls the refund tool, and the backend answers with an error: amount is required.
Claude never saw the backend's rules. It only read the tool card. So the card is where the fix goes. In this article we repair four broken cards from a refund app with one routine: read the trace, fix the schema, re-run.
A paper form at a shop counter
A customer fills in a paper form exactly as it is printed. If the form is wrong, the customer gets it wrong too:
- The form marks the amount as optional, so the customer leaves it out. No amount, no refund.
- The tick boxes offer low, normal and high. The desk only takes routine or urgent.
- The phone box says "number", so the leading zero disappears. The desk wants text.
- Two counters have the same sign: money back. Nobody knows which one to visit.
Those are the four bugs in this lesson. Fix the form, not the customer.
The routine: the trace names the part
The Claude docs name the description and the input schema as what Claude reads, so those are the two places a tool-call bug can live on the card.
tools_broken.py: four cards, four bugs
ISSUE_REFUND = tool(
"issue_refund",
"Refund or cancel an order. Gives the money back.",
{"order_id": {"type": "string"},
"amount": {"type": "number"}},
["order_id"])
HAND_TO_HUMAN = tool(
"hand_to_human",
"Send the case to a person.",
{"order_id": {"type": "string"},
"priority": {"type": "string",
"enum": ["low", "normal", "high"]}},
["order_id", "priority"])
BOOK_CALLBACK = tool(
"book_callback",
"Book a call back to the customer.",
{"callback": {"type": "object",
"properties": {
"phone": {"type": "number"}},
"required": ["phone"]}},
["callback"])
CANCEL_ORDER = tool(
"cancel_order",
"Cancel or refund an order. Gives the money back.",
{"order_id": {"type": "string"}},
["order_id"])
- Bug 1:
issue_refundlistsamountas a property but leaves it out ofrequired, so it may be skipped. - Bug 2: the
priorityenum offers low, normal and high. The backend only knows routine and urgent. - Bug 3: inside the nested
callbackobject,phoneis a number, so the leading zero is lost. Becausephoneis required, it is always sent, and always wrong. The mistake hides one level down. - Bug 4:
issue_refundandcancel_orderhave the same words in a different order. Nothing tells Claude which one to choose.
tools_fixed.py: each change answers one trace
ISSUE_REFUND = tool(
"issue_refund",
"Refunds a delivered order and returns a refund id. "
"Not for orders not shipped yet: use cancel_order.",
{"order_id": {"type": "string"},
"amount": {"type": "number"}},
["order_id", "amount"])
HAND_TO_HUMAN = tool(
"hand_to_human",
"Send the case to a person.",
{"order_id": {"type": "string"},
"priority": {"type": "string",
"enum": ["routine", "urgent"]}},
["order_id", "priority"])
BOOK_CALLBACK = tool(
"book_callback",
"Book a call back to the customer.",
{"callback": {"type": "object",
"properties": {
"phone": {"type": "string"}},
"required": ["phone"]}},
["callback"])
CANCEL_ORDER = tool(
"cancel_order",
"Cancels an order that has not shipped yet and "
"returns the money. "
"Not for delivered orders: use issue_refund.",
{"order_id": {"type": "string"}},
["order_id"])
Fix 1 adds amount to required. Fix 2 sets the enum to the values the backend accepts. Fix 3 types the phone as a string. Fix 4 gives each refund tool its own job, delivered orders against orders not shipped yet, and a "Not for" line that names the other tool.
Run it: broken cards, then fixed ones
fix_run.py sends the same requests against both files. The model is a stand-in reader that follows each card exactly as written: it fills only the required fields, maps a word onto the enum, converts a "number" field to an integer, and picks a tool by shared words (a tie goes to the first tool). That is not how the real model works, but it makes every failure trace back to the schema, and it needs no API key.
1 broken issue_refund {"order_id": "A-102"}
ERROR amount is required
1 fixed issue_refund {"order_id": "A-102", "amount": 120}
OK refund sent: 120
2 broken hand_to_human {"order_id": "A-103", "priority": "high"}
ERROR priority high is not routine or urgent
2 fixed hand_to_human {"order_id": "A-103", "priority": "urgent"}
OK queued urgent
3 broken book_callback {"callback": {"phone": 7700900123}}
ERROR callback.phone must be a string, got int
3 fixed book_callback {"callback": {"phone": "07700900123"}}
OK call booked for 07700900123
4 broken tie: issue_refund 4, cancel_order 4 -> issue_refund
issue_refund {"order_id": "A-105"}
ERROR A-105 has not been delivered
4 fixed issue_refund ruled out, cancel_order picked
cancel_order {"order_id": "A-105"}
OK A-105 cancelled
Each broken line carries the clue. amount is required points at the required list. high is not routine or urgent points at the enum. must be a string, got int points at the nested type, and you can see the zero missing from 7700900123. And case 4 is a tie, 4 against 4, so the first tool listed won, which was the wrong one for an order still processing.
Break it: patch the handler instead
The tempting shortcut is to leave the card alone and map high to urgent in the handler. The run shows what happens:
patched handler: high is mapped to urgent
urgent request card sends high -> OK queued urgent
routine request card sends normal -> ERROR priority normal is not routine or urgent
fixed card, no patch
routine request card sends routine -> OK queued routine
The urgent request works, but a routine request sends normal, and the backend refuses it. The card still offers low, normal and high, and Claude keeps choosing from that list. Fix the card, and the routine request goes through with no patch at all.
Common mistakes
| Symptom in the trace | Wrong fix | Right fix |
|---|---|---|
| A field is missing | Default it in the handler | Add it to required |
| A value isn't allowed | Map values in the handler | Make the enum match the backend |
| Wrong type in a nested field | Look only at top-level properties | Check the nested object's types |
| The wrong tool is called | Add more code around the call | Say when to use each tool, and when not |
Quick recap
| Step | What you do |
|---|---|
| Read | The trace names the part of the card that failed |
| Fix | Change the required list, the enum, the type or the description |
| Re-run | Send the same request again and check the trace is clean |
The card is what Claude reads. A patch elsewhere leaves it wrong for the next request. For the parts of a good card in the first place, see tool input schemas and error responses.
Try it yourself
hand_to_human still has a one-line description, Send the case to a person. Write a fuller one with a purpose, an input example and a boundary, so it can't be confused with book_callback.
Related course on Udemy
Claude Certified Developer - Foundations (CCDV-F) Exam Prep
Build and ship Claude apps: the API, agents, tools and MCP, prompts, evals, security and model choice.View on Udemy ↗: Claude Certified Developer - Foundations (CCDV-F) Exam Prep (paid course, opens in a new tab)Related posts
The Claude Messages API: Your First Call, Field by Field
One request in, one Message out. The four fields of a Messages API call (model, max_tokens, system, messages), how to read content blocks, stop_reason and usage, and why every turn resends the history.
Claude Tool Use: How tool_use and tool_result Work in the Messages API
Follow one order question through Claude's tool round trip: define a tool, read the tool_use block, run your own function and send a matching tool_result back, including parallel calls and is_error.
Claude Client SDKs Wrap One REST API: Raw HTTP, Python, TypeScript and Async Calls Compared
Every Claude client SDK wraps the same REST request: a POST to /v1/messages with a JSON body. See it built by hand, through the Python and TypeScript SDKs, as typed errors, and as async calls that wait together.
Anthropic SDK Timeouts, Retries and Error Classes: Configure the Client Once, Then Give 429, 529, 400 and Timeouts Their Own Move
Configure the Anthropic SDK client (timeout, max_retries, with_options, async, pagination), see which errors it retries by itself, then repair a retry wrapper so a 429, a 529, a 400 and a timeout each get the move the docs support.