Skip to content

fix(bedrock): extract tool arguments from Bedrock's input field#4764

Open
giulio-leone wants to merge 1 commit intocrewAIInc:mainfrom
giulio-leone:fix/bedrock-tool-args-extraction
Open

fix(bedrock): extract tool arguments from Bedrock's input field#4764
giulio-leone wants to merge 1 commit intocrewAIInc:mainfrom
giulio-leone:fix/bedrock-tool-args-extraction

Conversation

@giulio-leone
Copy link
Contributor

@giulio-leone giulio-leone commented Mar 8, 2026

Problem

AWS Bedrock tool calls always receive empty arguments {} regardless of what the LLM provides. This affects all Bedrock models (Nova Pro, Nova Lite, Claude via Bedrock, etc.).

Bedrock tool call format:

{"toolUseId": "tooluse_abc", "name": "search_tool", "input": {"query": "AWS Bedrock features"}}

OpenAI tool call format:

{"id": "call_xyz", "function": {"name": "search_tool", "arguments": '{"query": "test"}'}}

Root Cause

In _parse_native_tool_call (line 850):

func_args = func_info.get("arguments", "{}") or tool_call.get("input", {})

When func_info (from tool_call.get("function", {})) is an empty dict (Bedrock has no function key), .get("arguments", "{}") returns the default string "{}". Since "{}" is truthy, the or operator never evaluates tool_call.get("input").

Result: Bedrock's actual arguments in input are silently dropped.

Fix

Use None as the sentinel so or falls through correctly:

func_args = (
    func_info.get("arguments")
    or tool_call.get("input")
    or "{}"
)

Verified Locally

=== Bedrock tool call ===
OLD CODE: '{}'       <-- BUG: returns empty string instead of args
NEW CODE: {'query': 'AWS Bedrock features'}  <-- FIXED: returns actual args

=== OpenAI tool call (regression) ===
OLD CODE: '{"query": "test"}'
NEW CODE: '{"query": "test"}'
MATCH: True          <-- No regression

Tests

Added 7 unit tests covering:

  • Bedrock dict with input field (the reported bug)
  • OpenAI dict with function.arguments (regression)
  • Bedrock dict without function key
  • Empty input dict
  • Neither function nor input (fallback)
  • OpenAI-style object with .function attribute
  • Bedrock-style object with .name and .input attributes

All pass.

Fixes #4748


Note

Low Risk
Low risk bugfix limited to native tool-call argument extraction; main risk is subtle behavior changes for dict-style tool calls when function.arguments is missing/empty, but new tests cover expected formats.

Overview
Fixes _parse_native_tool_call to correctly extract tool arguments from AWS Bedrock-style tool calls by falling back to the dict’s input field when function.arguments is absent.

Adds focused unit tests covering Bedrock dict/object tool calls, OpenAI regression cases, and fallback behavior when no arguments are provided.

Written by Cursor Bugbot for commit 310f000. This will update automatically on new commits. Configure here.

The `_parse_native_tool_call` method's dict branch used:
```python
func_args = func_info.get("arguments", "{}") or tool_call.get("input", {})
```

Since `.get("arguments", "{}")` returns the default string `"{}"`
(which is truthy), the `or` operator never evaluates
`tool_call.get("input")`. Bedrock tool calls — which use `input`
instead of `function.arguments` — always received empty `"{}"` args.

Fix: use `None` as the sentinel so `or` falls through correctly:
```python
func_args = func_info.get("arguments") or tool_call.get("input") or "{}"
```

Fixes crewAIInc#4748

Signed-off-by: Giulio Leone <[email protected]>
@giulio-leone giulio-leone force-pushed the fix/bedrock-tool-args-extraction branch from 5af77a8 to 310f000 Compare March 9, 2026 14:10
@giulio-leone
Copy link
Contributor Author

Friendly ping — CI is green, tests pass, ready for review whenever convenient. Happy to address any feedback. Thanks! 🙏

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.

[BUG] AWS Bedrock tool calls extract empty arguments - uses wrong field name

1 participant