anthropic-sdk-python icon indicating copy to clipboard operation
anthropic-sdk-python copied to clipboard

Malformed XML-like `TextBlock` response instead of `ToolUseBlock` with Batch API

Open gordonhart opened this issue 9 months ago • 3 comments

Seeing an issue with tool use in the Batch API this afternoon. When forcing tool use with tool_choice=dict(type="auto") or tool_choice=dict(type="tool", name="my_tool_name"), the API is returning a TextBlock with content like this (tool name and parameter names replaced with placeholders):

="my_tool_name">
<parameter name="example_parameter">lorem ipsum</parameter>
<parameter name="example_parameter_2">lorem ipsum</parameter>
<parameter name="example_parameter_3">[]</parameter>
</invoke>
</function_calls>

The tool name is correct, the parameter names are correct, and the parameter values are correct for the requested tool. However, rather than having this shaped nicely into a ToolUseBlock with name and input set accordingly, it's yielded as a broken XML string. The rest of the MessageBatchIndividualResponse looks correct.

Only seeing this with the Batch API, and only started seeing this in the past hour or so.

gordonhart avatar Apr 10 '25 18:04 gordonhart

Seeing this from the synchronous API occasionally now as well.

gordonhart avatar Apr 14 '25 15:04 gordonhart

I am seeing this in the async API also. Any thing that can be done here?

mattzcarey avatar Jun 23 '25 15:06 mattzcarey

I'm seeing this as well -- Anthropic API seems to be subtly broken and responds with a malformed XML instead of the expected JSON.

This is sonnet 4.5 routed through the official anthropic endpoint (not proxied, but the same thing happens via openrouter)

@RobertCraigie can someone look at this?

Image

1st1 avatar Nov 07 '25 18:11 1st1