Skip to content

fix(providers/amazon-bedrock): strip empty text content to avoid API errors#7559

Merged
lgrammel merged 3 commits intovercel:mainfrom
MaxAller:fix/bedrock-empty-text-blocks
Aug 9, 2025
Merged

fix(providers/amazon-bedrock): strip empty text content to avoid API errors#7559
lgrammel merged 3 commits intovercel:mainfrom
MaxAller:fix/bedrock-empty-text-blocks

Conversation

@MaxAller
Copy link
Copy Markdown
Contributor

Note: this replaces the closed PR which I nuked by accident.

Without this, with maxSteps set, we sometimes see messages sent to the API like this:

{
  role: 'assistant',
  content: [ { text: '\n\n' }, { toolUse: [Object] } ]
},

This leads to API errors like this:

The text field in the ContentBlock object at messages.$n.content.0 is blank. Add text to the text field, and try again.

This change simply filters out this useless but apparently harmful message.

Background

Summary

Verification

Tasks

  • Tests have been added / updated (for bug fixes / features)
  • [n/a] Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • Formatting issues have been fixed (run pnpm prettier-fix in the project root)

Future Work

Related Issues

Fixes #6254.

Supersedes #6255

…errors.

Without this, with maxSteps set, we sometimes see messages sent to the API like this:

```
{
  role: 'assistant',
  content: [ { text: '\n\n' }, { toolUse: [Object] } ]
},
```

This leads to API errors like this:

```
The text field in the ContentBlock object at messages.$n.content.0 is blank. Add text to the text field, and try again.
```

This change simply filters out this useless but apparently harmful message.
@lgrammel
Copy link
Copy Markdown
Collaborator

pls fix ts errors

@MaxAller
Copy link
Copy Markdown
Contributor Author

MaxAller commented Aug 8, 2025

Thanks @dancer, that change looks correct to me.

@lgrammel lgrammel merged commit 9aa06a7 into vercel:main Aug 9, 2025
8 of 9 checks passed
@MaxAller MaxAller deleted the fix/bedrock-empty-text-blocks branch August 12, 2025 16:35
@gr2m gr2m added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label provider/amazon-bedrock Issues related to the @ai-sdk/amazon-bedrock provider labels Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label 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.

Amazon Bedrock + streamText + maxSteps often leads to APICallError

4 participants