Skip to content

fix: prevent invalid hallucinated tool names from crashing Bedrock conversation replay - #17769

Merged
lgrammel merged 2 commits into
mainfrom
bugfix/10202-1
Jul 22, 2026
Merged

fix: prevent invalid hallucinated tool names from crashing Bedrock conversation replay#17769
lgrammel merged 2 commits into
mainfrom
bugfix/10202-1

Conversation

@lgrammel

Copy link
Copy Markdown
Collaborator

Background

Hallucinated tool names containing unsupported characters caused Amazon Bedrock to reject replayed conversation history with a 400 validation error.

Root Cause

The Bedrock message converter copied part.toolName directly into toolUse.name; focused and live reproductions confirmed $READFILE reached Bedrock unchanged and violated its [a-zA-Z0-9_-]+ constraint.

Summary

Sanitized replayed tool-call names to Bedrock-compatible characters, added a valid fallback for fully invalid names, removed reproduction-only artifacts, and added a patch changeset.

Testing

Added converter regression coverage for $READFILE, names containing <|channel|>, and names containing no valid characters.

End-to-end Validation

  • pnpm -C packages/amazon-bedrock build followed by pnpm -C examples/ai-functions exec tsx -e '<live reproduction>': Claude Sonnet 4.5 completed the request with $READFILE in history without Bedrock's tool-name validation error.

Related Issues

Fixes #10202

Closes #17763

Co-authored-by: MaxAller 2164925+MaxAller@users.noreply.github.com

@lgrammel

Copy link
Copy Markdown
Collaborator Author

Bugfix review

Outcome: approved

Reproduction replay

Status: no-longer-reproduces

The exact original reproduction completed successfully and the original bug signal did not appear.

Fixes issue

Status: fully-addresses

The converter now sanitizes replayed assistant tool-call names at the point that previously forwarded them unchanged, covering both reported invalid-name patterns and fully invalid names.

Side effects

Risk: low

Valid tool names remain unchanged; only replayed names containing characters Bedrock rejects are rewritten before transmission.

Performance

Risk: low

The added work is a linear regular-expression replacement on each replayed tool-call name with negligible allocation and no retained state.

Backwards compatibility

Risk: low

The conversion does not mutate application messages or stored data; sanitization applies only to the Bedrock request representation.

Architecture

Risk: low

The provider-specific constraint is handled by a private helper in the Amazon Bedrock message converter, with no new dependencies, exports, cross-package source access, or boundary violations.

Change scope

Status: minimal

The PR changes only the affected converter, focused regression coverage, and the required patch changeset.

Security

Risk: low

The strict character allowlist and constant nonempty fallback reduce malformed outbound data without changing authentication, URL handling, parsing, or execution behavior.

Testing

Status: appropriate

Regression coverage includes both issue-reported names and an all-invalid fallback, while existing tests verify valid names; all 419 Amazon Bedrock tests passed in both Node and Edge configurations.

Verification

Reviewed every diff hunk and surrounding conversion and tool-repair paths. The full Amazon Bedrock Node and Edge suites, package type checking, focused formatting and lint checks, and diff validation all passed; the authoritative exact replay also succeeded without the original bug signal.

Relevant Documentation

@lgrammel
lgrammel merged commit 8fcb72c into main Jul 22, 2026
59 checks passed
@lgrammel
lgrammel deleted the bugfix/10202-1 branch July 22, 2026 15:32
lgrammel added a commit that referenced this pull request Jul 22, 2026
…rock conversation replay (#17777)

## Background

Hallucinated tool names containing unsupported characters caused Amazon
Bedrock to reject replayed conversation history with a 400 validation
error.

## Root Cause

The Bedrock message converter copied `part.toolName` directly into
`toolUse.name`; focused and live reproductions confirmed `$READFILE`
reached Bedrock unchanged and violated its `[a-zA-Z0-9_-]+` constraint.

## Summary

Sanitized replayed tool-call names to Bedrock-compatible characters,
added a valid fallback for fully invalid names, removed
reproduction-only artifacts, and added a patch changeset.

## Testing

Added converter regression coverage for `$READFILE`, names containing
`<|channel|>`, and names containing no valid characters.

## End-to-end Validation

- `pnpm -C packages/amazon-bedrock build` followed by `pnpm -C
examples/ai-functions exec tsx -e '<live reproduction>'`: Claude Sonnet
4.5 completed the request with `$READFILE` in history without Bedrock's
tool-name validation error.

## Related Issues

Fixes #10202

Closes #17763

Backport of #17769

Co-authored-by: MaxAller <2164925+MaxAller@users.noreply.github.com>
lgrammel added a commit that referenced this pull request Jul 22, 2026
…rock conversation replay (#17781)

## Background

Hallucinated tool names containing unsupported characters caused Amazon
Bedrock to reject replayed conversation history with a 400 validation
error.

## Root Cause

The Bedrock message converter copied `part.toolName` directly into
`toolUse.name`; focused and live reproductions confirmed `$READFILE`
reached Bedrock unchanged and violated its `[a-zA-Z0-9_-]+` constraint.

## Summary

Sanitized replayed tool-call names to Bedrock-compatible characters,
added a valid fallback for fully invalid names, removed
reproduction-only artifacts, and added a patch changeset.

## Testing

Added converter regression coverage for `$READFILE`, names containing
`<|channel|>`, and names containing no valid characters.

## End-to-end Validation

- `pnpm -C packages/amazon-bedrock build` followed by `pnpm -C
examples/ai-functions exec tsx -e '<live reproduction>'`: Claude Sonnet
4.5 completed the request with `$READFILE` in history without Bedrock's
tool-name validation error.

## Related Issues

Fixes #10202

Closes #17763

Backport of #17769

Co-authored-by: MaxAller <2164925+MaxAller@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Published in:

Package Version
ai 7.0.35 github npm
@ai-sdk/amazon-bedrock 5.0.28 github npm
@ai-sdk/angular 3.0.35 github npm
@ai-sdk/azure 4.0.19 github npm
@ai-sdk/devtools 1.0.7 github npm
@ai-sdk/gateway 4.0.27 github npm
@ai-sdk/google 4.0.22 github npm
@ai-sdk/google-vertex 5.0.26 github npm
@ai-sdk/harness 1.0.40 github npm
@ai-sdk/harness-claude-code 1.0.41 github npm
@ai-sdk/harness-codex 1.0.42 github npm
@ai-sdk/harness-deepagents 1.0.39 github npm
@ai-sdk/harness-opencode 1.0.41 github npm
@ai-sdk/harness-pi 1.0.40 github npm
@ai-sdk/langchain 3.0.35 github npm
@ai-sdk/llamaindex 3.0.35 github npm
@ai-sdk/openai 4.0.18 github npm
@ai-sdk/otel 1.0.35 github npm
@ai-sdk/policy-opa 1.0.35 github npm
@ai-sdk/react 4.0.38 github npm
@ai-sdk/rsc 3.0.35 github npm
@ai-sdk/sandbox-just-bash 1.0.40 github npm
@ai-sdk/sandbox-vercel 1.0.40 github npm
@ai-sdk/svelte 5.0.35 github npm
@ai-sdk/tui 1.0.36 github npm
@ai-sdk/vue 4.0.35 github npm
@ai-sdk/workflow 1.0.35 github npm
@ai-sdk/workflow-harness 1.0.40 github npm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bedrock adapter crashes if model hallucinates tool call with $ in the name

1 participant