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
@TomerAberbach
Copy link
Collaborator

Sorry for the delay; we were on holiday

Would you be able to copy the fix from #252? I think it's the same issue, but we didn't apply it to the beta accumulator.

@zklapow zklapow force-pushed the fix-empty-tool-input branch from 740f961 to 1893aaa Compare January 7, 2026 20:48
@zklapow
Copy link
Author

zklapow commented Jan 7, 2026

no worries, hope you had a nice break!

Updated to match #252 with if (inputJson.trim() == "") JsonMissing.of()

@TomerAberbach TomerAberbach changed the base branch from main to next January 7, 2026 20:51
@TomerAberbach TomerAberbach changed the title Fix BetaMessageAccumulator crash on empty string tool input fix(client): BetaMessageAccumulator crash on empty tool input Jan 7, 2026
@TomerAberbach
Copy link
Collaborator

Thanks!

@TomerAberbach TomerAberbach merged commit e0fe678 into anthropics:next Jan 7, 2026
4 checks passed
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.

2 participants