Skip to content

Conversation

@zklapow
Copy link

@zklapow zklapow commented Dec 17, 2025

Problem

BetaMessageAccumulator throws AnthropicInvalidDataException when streaming tool calls where the tool has no required parameters (empty input {}).

Reproduction: https://github.com/zklapow/cuddly-tribble

Request

Tool schema with no required parameters:

{
  "model": "claude-haiku-4-5-20251001",
  "tools": [{
    "input_schema": {
      "type": "object",
      "properties": {},
      "required": []
    },
    "name": "getCurrentTime",
    "description": "Returns the current time. This tool takes NO arguments."
  }]
}

Streaming Response

The API returns:

event: content_block_start
data: {"type":"content_block_start","index":1,"content_block":{"type":"tool_use","id":"toolu_01FbXcfAkW7TGhzDtCCcxfAh","name":"getCurrentTime","input":{}}}

event: content_block_delta
data: {"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":""}}

event: content_block_stop
data: {"type":"content_block_stop","index":1}

Note that:

  • content_block_start already contains "input":{} (complete)
  • content_block_delta sends "partial_json":"" (empty string)

The accumulator stores "" and then JSON_MAPPER.readValue("") fails with MismatchedInputException.

Fix

This PR adds a check to default empty accumulated JSON strings to "{}" before parsing.

Note: I am not sure this is a great fix, its kind of a workaround to remap the content in this way. Is this the expected output from this API? Should the partial JSON delta just get skipped in this case somehow?

Test

Added accumulateToolUseContentBlockWithEmptyInputDelta test case.

@zklapow zklapow requested a review from a team as a code owner December 17, 2025 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant