fix(adk/bedrock): coerce nil tool-call args to empty object#2222
Open
go-faustino wants to merge 1 commit into
Open
fix(adk/bedrock): coerce nil tool-call args to empty object#2222go-faustino wants to merge 1 commit into
go-faustino wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes Bedrock Converse tool-call serialization by ensuring no-argument tool calls produce toolUse.input as an empty JSON object ({}) instead of null, which Bedrock rejects on follow-up turns.
Changes:
- Coerces
nilFunctionCall.Argsto an emptymap[string]any{}before creating the BedrockToolUseBlock. - Adds a unit test to cover both
niland empty-map tool arguments, assertingtoolUse.inputis a non-null empty object.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| go/adk/pkg/models/bedrock.go | Coerces nil tool-call args to an empty object before building toolUse.input. |
| go/adk/pkg/models/bedrock_test.go | Adds coverage for no-arg tool calls to ensure toolUse.input is {} not null. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
peterj
approved these changes
Jul 13, 2026
b6ec5e5 to
d4adf70
Compare
A tool call with no arguments reaches the Bedrock converter with a nil
FunctionCall.Args map: genai's FunctionCall.Args is `json:"args,omitempty"`,
so an empty map is dropped when the event is persisted to the session store
and reloaded as nil. document.NewLazyDocument(nil) then serializes
toolUse.input to `null`, and Bedrock Converse rejects the follow-up
(tool-result) turn with:
ValidationException: Malformed input request
(The value at messages.N.content.M.toolUse.input is empty)
Coerce nil args to an empty map[string]any{} so no-argument tool calls
round-trip as `{}`. Adds a unit test covering both nil and empty Args.
Signed-off-by: Gonçalo Faustino <goncalo.santos@wellhub.com>
d4adf70 to
e915fe2
Compare
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.
Summary
The Bedrock converter serializes a no-argument tool call as
toolUse.input: null, which Bedrock Converse rejects on the follow-up (tool-result) turn with:In
convertGenaiContentsToBedrockMessages(go/adk/pkg/models/bedrock.go), a tool call's input is built asdocument.NewLazyDocument(part.FunctionCall.Args). A no-argument call reaches this point with a nilArgsmap, because genai'sFunctionCall.Argsis taggedjson:"args,omitempty": an emptymap[string]any{}is dropped when the event is persisted to the session store and reloaded asnil.document.NewLazyDocument(nil)then serializes to JSONnull, and Bedrock requirestoolUse.inputto be a JSON object ({}).This is reproducible against
us.anthropic.claude-opus-4-8in any multi-turn conversation where the model calls a tool that takes no arguments (e.g.datetime_get_current_time) and the history is reloaded before the next turn.Fix
Coerce a nil
Argsmap to an emptymap[string]any{}before building theToolUseBlock, so no-argument tool calls round-trip as{}instead ofnull.Test
Adds
TestConvertGenaiContentsNoArgToolInputcovering bothniland empty ({})Args, asserting the producedtoolUse.inputis a non-null, empty JSON object. Without the fix, thenilcase serializes tonulland the test fails.