Send {} for empty Anthropic tool_use input instead of null#544
Merged
qmuntal merged 3 commits intoJul 18, 2026
Conversation
When a FunctionCallContent has empty Arguments, buildMessageParams left
the parsed args map nil and passed it to NewToolUseBlock. A nil map
serializes to "input": null, but Anthropic requires a tool_use block's
input to be an object and rejects null — so replaying history that
contains a no-argument tool call produced a 400.
Default the args map to an empty object when Arguments is empty or absent
(and when it decodes to null), so the tool_use input is always {}. Adds a
request-capturing test asserting the serialized tool_use input is an
object.
There was a problem hiding this comment.
Pull request overview
This PR fixes Anthropic tool_use serialization so that no-argument tool calls send an empty object ({}) for input instead of null, which Anthropic rejects with a 400 when replaying conversation history.
Changes:
- Default
argstomap[string]any{}when tool arguments are empty/absent (or decode to JSONnull) sotool_use.inputis always an object. - Add a black-box regression test that captures the outbound request body and asserts
tool_use.inputis a JSON object for emptyFunctionCallContent.Arguments. - Minor gofmt/formatting adjustments in existing test helper/setup code.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| provider/anthropicprovider/agent.go | Ensure nil tool argument maps serialize as {} to satisfy Anthropic’s tool_use.input object requirement. |
| provider/anthropicprovider/agent_test.go | Add regression coverage verifying empty tool arguments serialize to an object, plus small formatting changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address review feedback: replace unchecked assertions on the decoded request body with guarded ones so a schema mismatch reports a readable failure instead of panicking.
qmuntal
approved these changes
Jul 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In
buildMessageParams(provider/anthropicprovider/agent.go), aFunctionCallContentis converted to an Anthropictool_useblock:When
c.Argumentsis empty,argsstaysnil, and a nil map serializes to"input": null. Anthropic requires a tool_use block'sinputto be an object and rejectsnullwith a 400. So replaying a conversation history that contains a no-argument tool call (e.g. a tool with no parameters, or a call carried over from another provider that emits empty arguments) breaks the request.Fix
Default
argsto an empty object (map[string]any{}) when it is nil — i.e. whenArgumentsis empty/absent, or decodes to JSONnull— so the serializedinputis always{}.Test
TestToolUseEmptyArgumentsSerializeAsObject(black-box, inagent_test.go) runs the agent over a history containing an assistantFunctionCallContent{Arguments: ""}, captures the request body sent to the server, and asserts thetool_useblock'sinputis a JSON object. Fails onmain(input = null), passes with the fix.