Skip to content

fix(converter): parse tool_use.input JSON string into object#13

Open
digachoy wants to merge 1 commit intonielspeter:mainfrom
digachoy:fix/tool-use-input-object
Open

fix(converter): parse tool_use.input JSON string into object#13
digachoy wants to merge 1 commit intonielspeter:mainfrom
digachoy:fix/tool-use-input-object

Conversation

@digachoy
Copy link
Copy Markdown

Anthropic's Messages API spec requires content blocks of type 'tool_use' to carry 'input' as a JSON object. OpenAI-compat upstreams return function arguments as a JSON-encoded string, and we were forwarding that string verbatim, which breaks downstream Anthropic SDKs (including Claude Code CLI) that expect an object.

Parse the arguments string into interface{} so the final JSON-encoding emits a proper object; fall back to an empty object when arguments are missing, and leave the raw string only when it is not valid JSON.

Extend TestConvertResponse to assert Input is a map[string]interface{} and add coverage for the empty-arguments case.

Anthropic's Messages API spec requires content blocks of type
'tool_use' to carry 'input' as a JSON object. OpenAI-compat upstreams
return function arguments as a JSON-encoded string, and we were
forwarding that string verbatim, which breaks downstream Anthropic
SDKs (including Claude Code CLI) that expect an object.

Parse the arguments string into interface{} so the final JSON-encoding
emits a proper object; fall back to an empty object when arguments are
missing, and leave the raw string only when it is not valid JSON.

Extend TestConvertResponse to assert Input is a map[string]interface{}
and add coverage for the empty-arguments case.
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