fix(ai): wrap malformed tool call input in JSON object instead of raw string#16280
Open
arinsoni wants to merge 1 commit into
Open
fix(ai): wrap malformed tool call input in JSON object instead of raw string#16280arinsoni wants to merge 1 commit into
arinsoni wants to merge 1 commit into
Conversation
When parseToolCall falls through to the catch block with unparseable JSON,
the input was stored as a raw string. Providers like Amazon Bedrock require
toolUse.input to be a JSON object, so the next API step was rejected before
the model could see the tool-error and retry.
Wrap invalid input as { rawInvalidInput: <string> } so the conversation
history stays well-typed for all providers.
Closes vercel#14442
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Closes #14442
When
parseToolCallfalls through to its catch block because the model returned unparseable JSON as a tool call'sinput, the SDK stored the raw string directly asinputon the resultingtool-callpart:This raw string is then forwarded into the assistant message for the next API step via
to-response-messages.ts. Providers like Amazon Bedrock requiretoolUse.inputto be a JSON object — they reject the request before the model ever sees thetool-errorresult, breaking the retry loop entirely.Fix: when JSON parsing fails, wrap the raw string in
{ rawInvalidInput: toolCall.input }so the conversation history is always a valid JSON object for all providers.Tests: updated two inline snapshots that asserted the old raw-string behavior to match the new wrapped-object shape.
This contribution was made with AI-agent assistance (Claude Code).