Skip to content

fix: bedrock chat tool arguments - #3564

Merged
akshaydeo merged 1 commit into
devfrom
05-18-fix_bedrock_chat_tool_arguments
May 18, 2026
Merged

fix: bedrock chat tool arguments#3564
akshaydeo merged 1 commit into
devfrom
05-18-fix_bedrock_chat_tool_arguments

Conversation

@TejasGhatte

@TejasGhatte TejasGhatte commented May 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

When a tool call contains invalid JSON arguments, the Bedrock provider now falls back to an empty JSON object {} instead of forwarding the malformed payload. This prevents downstream errors caused by passing invalid JSON to the Bedrock API.

Changes

  • When json.Compact fails on tool call arguments, the input is now set to {} rather than preserving the raw (invalid) string. Forwarding invalid JSON to Bedrock would cause API errors, so discarding it in favor of a safe empty object is the correct behavior.

Type of change

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (React)
  • Docs

How to test

Construct a tool call with malformed JSON arguments and send it through the Bedrock provider. Verify that the request succeeds and the tool input is treated as an empty object rather than causing a serialization or API error.

go test ./core/providers/bedrock/...

Breaking changes

  • Yes
  • No

Related issues

Security considerations

No security implications. Invalid input is sanitized to an empty object rather than being forwarded.

Checklist

  • I read docs/contributing/README.md and followed the guidelines
  • I added/updated tests where appropriate
  • I updated documentation where needed
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


tejas ghatte seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Copy Markdown
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@TejasGhatte
TejasGhatte marked this pull request as ready for review May 18, 2026 10:50
@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

A single-file change to the Bedrock provider's tool-call conversion function: when tool-call arguments fail JSON compacting, the Bedrock tool input now defaults to an empty JSON object ({}) instead of using the original (malformed) argument string.

Changes

Bedrock tool-call conversion

Layer / File(s) Summary
Tool-call argument JSON parsing fallback
core/providers/bedrock/utils.go
When JSON compact parsing fails for tool-call arguments, Bedrock tool input is set to {} instead of the original invalid argument bytes, improving error handling for malformed payloads.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • akshaydeo

Poem

🐰 When JSON fails to parse just right,
An empty object saves the flight,
No more malformed bytes to send,
The Bedrock tooling's safer friend!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is a template with all sections present but no actual content filled in by the author. Fill in all required sections with actual content: provide a clear summary of the bug fix, explain what was changed and why, check the appropriate type of change and affected areas, describe how to test the changes, address the security considerations section, and complete the checklist items.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: fixing how the Bedrock provider handles tool call arguments, which is the primary focus of the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 05-18-fix_bedrock_chat_tool_arguments

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps

greptile-apps Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5

Safe to merge — the change eliminates a code path that would have caused Bedrock API failures and introduces no new functional risk.

The fix is correct and targeted: the previous behavior of forwarding a raw invalid JSON string to Bedrock was worse than discarding it. The only concern is that the silent discard produces no log output, which could make it hard to notice in production when tool arguments are unexpectedly lost.

core/providers/bedrock/utils.go — worth considering whether a warn log should be added when arguments are silently dropped.

Important Files Changed

Filename Overview
core/providers/bedrock/utils.go Single-line fix in convertToolCallToContentBlock: invalid JSON tool arguments now fall back to {} instead of forwarding the raw malformed string to Bedrock. The change prevents API errors but silently discards arguments with no log warning.

Reviews (1): Last reviewed commit: "fix: bedrock chat tool arguments" | Re-trigger Greptile

@coderabbitai
coderabbitai Bot requested a review from akshaydeo May 18, 2026 10:52
Comment thread core/providers/bedrock/utils.go

akshaydeo commented May 18, 2026

Copy link
Copy Markdown
Contributor

Merge activity

  • May 18, 1:42 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • May 18, 1:42 PM UTC: @akshaydeo merged this pull request with Graphite.

@akshaydeo
akshaydeo merged commit fd904ac into dev May 18, 2026
15 of 16 checks passed
@akshaydeo
akshaydeo deleted the 05-18-fix_bedrock_chat_tool_arguments branch May 18, 2026 13:42
akshaydeo pushed a commit that referenced this pull request May 20, 2026
## Summary

When a tool call contains invalid JSON arguments, the Bedrock provider now falls back to an empty JSON object `{}` instead of forwarding the malformed payload. This prevents downstream errors caused by passing invalid JSON to the Bedrock API.

## Changes

- When `json.Compact` fails on tool call arguments, the input is now set to `{}` rather than preserving the raw (invalid) string. Forwarding invalid JSON to Bedrock would cause API errors, so discarding it in favor of a safe empty object is the correct behavior.

## Type of change

- [x] Bug fix
- [ ] Feature
- [ ] Refactor
- [ ] Documentation
- [ ] Chore/CI

## Affected areas

- [ ] Core (Go)
- [ ] Transports (HTTP)
- [x] Providers/Integrations
- [ ] Plugins
- [ ] UI (React)
- [ ] Docs

## How to test

Construct a tool call with malformed JSON arguments and send it through the Bedrock provider. Verify that the request succeeds and the tool input is treated as an empty object rather than causing a serialization or API error.

```sh
go test ./core/providers/bedrock/...
```

## Breaking changes

- [ ] Yes
- [x] No

## Related issues

## Security considerations

No security implications. Invalid input is sanitized to an empty object rather than being forwarded.

## Checklist

- [ ] I read `docs/contributing/README.md` and followed the guidelines
- [ ] I added/updated tests where appropriate
- [ ] I updated documentation where needed
- [ ] I verified builds succeed (Go and UI)
- [ ] I verified the CI pipeline passes locally if applicable
@akshaydeo akshaydeo mentioned this pull request May 20, 2026
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.

3 participants