← Blog

Claude API Tool Use Error Debugging: A Practical Guide

2026-11-12 · 5 min read · SubToAPI Team

When Claude's tool use stops working, the failure usually falls into one of five categories: malformed tool_use blocks, schema validation errors, missing or mismatched tool_result messages, truncated streaming output, or the model simply refusing to call a tool. Each has a distinct signature in the API response, and once you know what to look for, most of these errors take minutes to fix instead of hours.

This guide walks through the actual error patterns you'll see in responses and logs, how to reproduce them reliably, and how to structure your tool-calling code so these failures become rare instead of routine.

The five most common tool use failures

1. Invalid JSON in tool_use.input

Claude occasionally generates arguments that don't parse as valid JSON, especially with complex nested schemas or very long string arguments. This shows up as a JSONDecodeError or similar in your code, not as an API-level error — the request itself succeeds.

const toolUseBlock = response.content.find(b => b.type === "tool_use");
try {
  const args = toolUseBlock.input; // already parsed object, not a string
} catch (e) {
  // this branch rarely fires because Anthropic parses input server-side
}

Note that tool_use.input arrives as a parsed JSON object, not a raw string — if you're seeing parse errors, you're likely trying to JSON.parse() something that's already an object. Check your deserialization logic before blaming the model.

2. Schema validation mismatches

If your tool's input_schema requires a field that Claude omits, or the model sends a string where you defined a number, your downstream function call throws before you ever see the problem at the API layer. Fix this by:

curl https://api.anthropic.com/v1/messages \
  -H "x-api-key: $API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-4-5",
    "max_tokens": 1024,
    "tools": [{
      "name": "get_weather",
      "description": "Get current weather for a location",
      "input_schema": {
        "type": "object",
        "properties": {
          "location": {"type": "string"},
          "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
        },
        "required": ["location"]
      }
    }],
    "messages": [{"role": "user", "content": "Weather in Berlin?"}]
  }'

Run this exact call in isolation when debugging — stripping out your application logic and testing the tool definition directly against the API tells you immediately whether the problem is in the schema or in your handler code.

3. Missing or mismatched tool_result blocks

This is the single most common integration bug. After Claude returns a tool_use block, your next message must include a tool_result block with a matching tool_use_id, sent back in the very next user turn. If you skip this, add extra content before it, or get the ID wrong, you'll get a 400 error describing the conversation as malformed.

const messages = [
  { role: "user", content: "What's the weather in Berlin?" },
  { role: "assistant", content: response.content }, // includes tool_use block
  {
    role: "user",
    content: [
      {
        type: "tool_result",
        tool_use_id: toolUseBlock.id, // must match exactly
        content: JSON.stringify({ temp: 18, condition: "cloudy" })
      }
    ]
  }
];

Common mistakes here: reusing an old tool_use_id from a previous turn, forgetting to echo back the full assistant message (including non-tool text blocks that preceded the tool call), or sending the result as plain text instead of a tool_result content block.

4. Streaming tool calls cut off mid-argument

When streaming, tool input arrives as input_json_delta events that you must concatenate yourself. If your stream handler drops a chunk — due to a network blip or an unhandled event type — you'll end up trying to parse incomplete JSON. Always buffer deltas by index and only attempt to parse once you receive the content_block_stop event for that block. SubToAPI's streaming docs at /docs/streaming cover the event sequence in detail if you're building this from scratch.

5. The model declines to call any tool

Sometimes Claude just answers in text instead of invoking a tool, even when one is clearly applicable. This usually means your tool description is too vague, or your system prompt tells Claude to "answer directly when possible," which conflicts with your intent. Be explicit: describe exactly when the tool should be used, including edge cases, and avoid system prompts that discourage tool use as a side effect of unrelated instructions.

A debugging checklist

If you're running tool-calling workloads through SubToAPI, the dashboard includes per-request usage metadata, which makes it easier to spot which calls triggered tool use and which didn't, without re-instrumenting your own logging. Setting up a key takes a few minutes — see /docs/quickstart — and the /docs/tools page documents the exact request/response shapes for tool blocks if you want a reference while debugging.

questions

Why does my tool_use_id not match on the next turn? You're likely reusing an ID from an earlier conversation turn or regenerating the assistant message instead of echoing back the exact content Claude returned. Always pass the assistant's content array unchanged into the next request.

Why is tool_use.input sometimes incomplete JSON? This typically happens only in streaming responses where you're concatenating input_json_delta chunks manually. Wait for the content_block_stop event before parsing; parsing partial deltas will fail intermittently.

How do I force Claude to use a tool instead of answering in text? Set tool_choice to {"type": "tool", "name": "your_tool"} to require that specific tool, or {"type": "any"} to require some tool call. Leaving tool_choice unset lets the model decide, which is where "no tool called" surprises usually come from.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →