Skip to content

Bedrock provider throws on unknown assistant/user content types (other providers skip) #4223

@sesame437

Description

@sesame437

Issue: Bedrock provider throws on unknown assistant/user content types (other providers skip)

Summary

amazon-bedrock.js in convertMessages() throws Error("Unknown assistant content type") / Error("Unknown user content type") when encountering any content block type outside the recognized set (text/image for user, text/toolCall/thinking for assistant).

This causes entire agent runs to crash when context history contains blocks from newer API features (e.g., redacted thinking replay, structured output blocks, provider-specific extensions) that the Bedrock provider doesn't yet handle.

Other providers in the same codebase handle this gracefully:

  • anthropic.js: uses if/else if and simply doesn't push unrecognized blocks (silently skips)
  • openai-*.js / google.js: similar forgiving behavior

Reproduction

  1. Use Bedrock provider with Claude Opus/Sonnet via amazon-bedrock API
  2. Have conversation history that includes a non-standard content block (e.g., a redacted thinking block, an image block in assistant role, or any future block type)
  3. On the next turn, convertMessages() hits the default: branch and throws

Impact

  • Agent runs crash with no recovery (the error is unhandled)
  • Users on Bedrock have worse reliability than users on the direct Anthropic API for the same models
  • As new block types are added upstream, Bedrock users will hit this more often

Suggested fix

Minimum: Replace throw with skip behavior, matching the anthropic provider:

// User branch (inside .map callback):
default:
    return null; // skip unknown
// ... then .filter(Boolean) on the map result
// + guard: if (content.length === 0) continue;

// Assistant branch (inside for...of loop):
default:
    continue; // skip unknown

Better: Add a console.warn or debug log when skipping, so users know context was dropped:

default:
    console.warn(`[bedrock] skipping unknown ${m.role} content type: ${c.type}`);
    return null; // or continue

Best: Handle all known pi-ai content types (text, image, thinking, toolCall, redacted, etc.) explicitly, and only skip truly unknown ones.

Additional context

  • Affected versions: at least 0.66 through 0.73 (latest at time of writing)
  • File: packages/ai/src/providers/amazon-bedrock.tsconvertMessages() function
  • The anthropic provider in the same repo already demonstrates the correct pattern
  • We're currently running a local patch on our deployment; happy to submit a PR if maintainers agree with the approach

Environment

  • pi-ai 0.71.1 (bundled with OpenClaw 2026.5.2)
  • amazon-bedrock provider, models: claude-opus-4-7, claude-sonnet-4-6
  • Node.js v24.13.0

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions