Skip to content

fix: wrap invalid tool call input in JSON object#14470

Open
SAY-5 wants to merge 2 commits intovercel:mainfrom
SAY-5:fix/tool-call-invalid-input-object
Open

fix: wrap invalid tool call input in JSON object#14470
SAY-5 wants to merge 2 commits intovercel:mainfrom
SAY-5:fix/tool-call-invalid-input-object

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented Apr 15, 2026

When parseToolCall fails to parse the tool input JSON, the raw string was stored directly as the input property. Providers like Amazon Bedrock require toolUse.input to be a JSON object, so the raw string caused API rejections on the next step before the model could see the tool-error and retry.

Now wraps the unparsable input as { rawInvalidInput: toolCall.input } so the conversation history remains valid JSON for all providers.

2221/2221 tests pass across 106 test files.

Fixes #14442

…ring

When parseToolCall fails to parse tool input JSON, the raw string was
stored as input. Providers like Bedrock require input to be a JSON
object, so the raw string caused API rejections before the model
could see the tool-error and retry.

Now wraps the raw input as { rawInvalidInput: toolCall.input } so the
conversation history stays valid for the next API call.

2221/2221 tests pass.

Fixes vercel#14442
@tigent tigent bot added ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/amazon-bedrock Issues related to the @ai-sdk/amazon-bedrock provider labels Apr 15, 2026
Copy link
Copy Markdown
Contributor

@vercel vercel bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Suggestion:

Two test inline snapshots in parse-tool-call.test.ts were not updated after changing the fallback for unparseable tool call input from the raw string to { rawInvalidInput: toolCall.input }, causing 2 snapshot test failures.

Fix on Vercel

…pping

Address feedback on vercel#14470 — two inline snapshots in parse-tool-call.test.ts
weren't updated after the parse-tool-call.ts change that wraps the
fallback input as { rawInvalidInput: ... } instead of leaving it as a
raw string.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/amazon-bedrock Issues related to the @ai-sdk/amazon-bedrock provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid tool call input stored as raw string causes API rejection on next step

1 participant