Skip to content

fix(amazon-bedrock): preserve reasoning text when signature is present#13972

Merged
dancer merged 4 commits intomainfrom
josh/fix-bedrock-reasoning-signature
Mar 31, 2026
Merged

fix(amazon-bedrock): preserve reasoning text when signature is present#13972
dancer merged 4 commits intomainfrom
josh/fix-bedrock-reasoning-signature

Conversation

@dancer
Copy link
Copy Markdown
Collaborator

@dancer dancer commented Mar 31, 2026

background

trimIfLast() trims trailing whitespace from reasoning block text even when a cryptographic signature is present. the signature is computed over the exact original bytes - trimming even a single trailing newline invalidates the text/signature pair, causing Bedrock to reject with ValidationException: thinking blocks cannot be modified

summary

  • skip trimIfLast for reasoning blocks that have a signature
  • reasoning blocks without a signature still get trimmed as before
  • add test for multi-turn tool use with signed reasoning blocks

checklist

  • tests have been added / updated (for bug fixes / features)
  • documentation has been added / updated (for bug fixes / features)
  • a patch changeset for relevant packages has been added (run pnpm changeset in root)
  • i have reviewed this pull request (self-review)

related issues

fixes #13583

@tigent tigent bot added 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 Mar 31, 2026
@dancer dancer added the backport Admins only: add this label to a pull request in order to backport it to the prior version label Mar 31, 2026
@dancer dancer closed this Mar 31, 2026
@dancer dancer reopened this Mar 31, 2026
@dancer dancer merged commit b0c59e8 into main Mar 31, 2026
37 of 39 checks passed
@dancer dancer deleted the josh/fix-bedrock-reasoning-signature branch March 31, 2026 17:17
vercel-ai-sdk bot pushed a commit that referenced this pull request Mar 31, 2026
#13972)

## background

`trimIfLast()` trims trailing whitespace from reasoning block text even
when a cryptographic `signature` is present. the signature is computed
over the exact original bytes - trimming even a single trailing newline
invalidates the text/signature pair, causing Bedrock to reject with
`ValidationException: thinking blocks cannot be modified`

## summary

- skip `trimIfLast` for reasoning blocks that have a signature
- reasoning blocks without a signature still get trimmed as before
- add test for multi-turn tool use with signed reasoning blocks

## checklist

- [x] tests have been added / updated (for bug fixes / features)
- [ ] documentation has been added / updated (for bug fixes / features)
- [x] a _patch_ changeset for relevant packages has been added (run
`pnpm changeset` in root)
- [x] i have reviewed this pull request (self-review)

## related issues

fixes #13583
@vercel-ai-sdk vercel-ai-sdk bot removed the backport Admins only: add this label to a pull request in order to backport it to the prior version label Mar 31, 2026
@vercel-ai-sdk
Copy link
Copy Markdown
Contributor

vercel-ai-sdk bot commented Mar 31, 2026

✅ Backport PR created: #13979

vercel-ai-sdk bot added a commit that referenced this pull request Mar 31, 2026
… is present (#13979)

This is an automated backport of #13972 to the release-v6.0 branch. FYI
@dancer

Co-authored-by: dancer <144584931+dancer@users.noreply.github.com>
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 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.

fix(amazon-bedrock): trimIfLast must not be applied to reasoning blocks with a signature

3 participants