-
Notifications
You must be signed in to change notification settings - Fork 676
Bedrock Runtime Converse Force Tool Use Not Working w/ Anthropic API #3048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Adding some further details to this issue after some testing. Ironically, had an LLM help me generate this.. 😂 Problem SummaryWhen using the Debugging Steps PerformedI've systematically simplified the request to isolate the cause of the empty
ConclusionThe extensive testing, culminating in the failure even with no input data and a minimal generation task (Step 6), strongly suggests this is not an issue with:
The evidence points towards an issue with Bedrock's handling of tool use when an While the SDK appears to be constructing the request as documented, the Bedrock service itself seems unable to fulfill the tool input generation part of the workflow correctly in this scenario. example code test (Step 6):
|
the specific functionality I'm trying to replicate in AWS Bedrock is "use tools to get Claude produce JSON output that follows a schema" as outlined in the Anthropic API docs. |
I choose the latest code that you posted on
however, I'm actually able to see a non-empty input on the request and the response from the server. My code (modified your signature a bit to pass the struct members as parameters)
I can see both on the raw HTTP response
And on the Go content that input is not nil
|
thanks for your response! Using your type casting code I was also able to see non-empty input on the response from the server. I was able to store the content.Value.Input into a |
This issue is now closed. Comments on closed issues are hard for our team to see. |
Acknowledgements
go get -u github.com/aws/aws-sdk-go-v2/...
)Describe the bug
I very recently integrated our backend with Anthropic's API for some structured data analysis/basic chat functionality and I was hoping the switch to AWS Bedrock would be as simple as replacing a couple function calls.. since Bedrock is essentially a wrapper on top of the thing I already integrated with.. but I've run into some problems.
model:
us.anthropic.claude-3-7-sonnet-20250219-v1:0
According to the docs:
If you are using an Anthropic Claude 3 model,
(which I am)
you can force the use of a tool by specifying the toolChoice (ToolChoice) field in the toolConfig request parameter.There seem to be two issues:
tool_use
StopReason rather than using the tool provided - this is annoying but not as critical.The Input field within the returned ToolUse block is consistently empty ({}). I am using the tool schema primarily as a mechanism to obtain reliable, structured JSON output from the model.
This could be because I am forming my JSON schema incorrectly but I've triple checked and ran several tests - its doesn't seem the case.
Expected Behavior
work like Anthropic's API where the LLM uses the tool within a single request rather than needing to make a second request acknowledging the tool use when you have correctly passed in the SpecificToolChoice within the tool config.
Current Behavior
the LLM returns with the
stop_reason
response with an empty input{}Reproduction Steps
my imports :
inside my function call:
the helper func with simplified descriptions:
Possible Solution
is the
tool
part of the request body is being omitted or not correctly marshaled into the call to the bedrock runtime? is there something wrong with the NewLazyDocument() wrapper?from the example docs:
{"tool" : {"name" : "top_song"}}
Additional Information/Context
the exact same request with the same document & user prompt works with my claude's API implementation:
AWS Go SDK V2 Module Versions Used
Compiler and Version used
go version go1.23.3 linux/amd64
Operating System and version
Pop!_OS 22.04 LTS x86_64
The text was updated successfully, but these errors were encountered: