← Blog

Claude API Function Calling Error Debugging Guide

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

When Claude's function calling (tool use) breaks, it usually fails in one of three places: the request you sent, the response you parsed, or the tool_result you sent back on the next turn. This guide walks through the most common error patterns, how to read the error messages Claude returns, and a checklist you can run through before opening a support ticket.

If you're seeing a 400 error, a malformed tool_use block, or Claude ignoring your tools entirely, start by isolating which of those three stages is failing. Most "function calling doesn't work" bugs are actually conversation-state bugs — the model behaved correctly, but the follow-up request wasn't built the way the API expects.

Step 1: Validate the request you're sending

The most frequent cause of function calling errors is an invalid tools array. Before debugging anything downstream, confirm:

A malformed schema typically returns a 400 with a message pointing at the tools field. Test a minimal tool definition in isolation to confirm the schema itself is the problem:

curl https://api.anthropic.com/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-opus-4-20250514",
    "max_tokens": 256,
    "tools": [{
      "name": "get_weather",
      "description": "Get current weather for a city",
      "input_schema": {
        "type": "object",
        "properties": { "city": { "type": "string" } },
        "required": ["city"]
      }
    }],
    "messages": [{ "role": "user", "content": "What is the weather in Lisbon?" }]
  }'

If this minimal call works but your production request doesn't, bisect your actual schema by removing tools one at a time until the error disappears.

Step 2: Check how you parse the tool_use block

Claude returns tool calls as content blocks with type: "tool_use", not as a separate field. A common bug is code that assumes the response is only a tool call and ignores the possibility of mixed content — Claude can return text and a tool_use block in the same response.

const toolUseBlock = response.content.find(block => block.type === "tool_use");
if (toolUseBlock) {
  const { id, name, input } = toolUseBlock;
  // input is already parsed JSON — don't JSON.parse() it again
}

Two mistakes show up repeatedly here:

  1. Double-parsing input. It's already a JS object/dict, not a string. Calling JSON.parse() on it throws.
  2. Ignoring stop_reason. If stop_reason is tool_use, you must respond with a tool_result before Claude will continue. If you send a new user message instead, the conversation state becomes inconsistent and Claude may silently repeat the same tool call.

Step 3: Fix the tool_result round-trip

This is where most "intermittent" errors live. The follow-up message must include a tool_result content block that references the exact tool_use_id from Claude's previous turn, inside a user message:

{
  "role": "user",
  "content": [
    {
      "type": "tool_result",
      "tool_use_id": "toolu_01A09q90qw90lq917835lq9",
      "content": "Lisbon: 18°C, partly cloudy"
    }
  ]
}

Common failures:

Step 4: Handle parallel tool calls correctly

When Claude requests multiple tools in one turn, your response message needs a tool_result block for every tool_use_id it emitted — in the same user message, as separate content blocks. Sending them as separate messages, or omitting one because your code only handled the first tool call, is a very common source of hangs where Claude keeps re-requesting the same tools.

Step 5: Debugging streamed tool use

If you're streaming responses, tool call errors often come from reassembling partial JSON incorrectly. The input_json_delta events arrive as string fragments that you must concatenate and parse only once the block is complete — attempting to JSON.parse() each fragment individually will throw on every chunk except the last. See the streaming event sequence in detail if you're building your own parser.

A faster debugging loop

Reproducing tool-use bugs against the raw API means rebuilding request/response logging yourself. If you're running Claude through SubToAPI, every call made with your sub_live_ key is logged with full request/response payloads and usage metadata in the dashboard, so you can inspect the exact tool_use and tool_result blocks that were exchanged without adding your own logging layer. The tool use docs cover the supported schema and response shape, and streaming docs cover how partial JSON deltas are emitted for tool calls specifically.

Debugging checklist

FAQ

Why does Claude keep repeating the same tool call? Almost always a missing or mismatched tool_result. Claude re-requests the tool because it never received confirmation that the previous call was handled — check that your tool_use_id matches exactly and that the result is in a user message.

What does is_error: true actually do? It tells Claude the tool execution failed so it can reason about the failure (retry, ask the user, pick a different tool) instead of treating the returned content as valid data. Omitting it when a call failed is a common cause of hallucinated answers.

Why do I get a 400 error only on some tool schemas? Check for non-standard JSON Schema keywords (like example without quotes, or missing type on nested properties) and root-level types other than object. Validate the schema independently with a JSON Schema validator before sending it to the API.

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 →