Skip to content

[BUG] Bedrock prompt-too-long ValidationException is not mapped to ContextWindowOverflowException #1912

@mikegc-aws

Description

@mikegc-aws

Checks

  • I have updated to the lastest minor and patch version of Strands
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Strands Version

1.25.0

Python Version

3.14.1

Operating System

macOS 26.3.1

Installation Method

other

Steps to Reproduce

  1. Create a Strands agent using the Bedrock model provider (ConverseStream API) — e.g., Claude Opus 4.6
  2. Equip the agent with tools that produce large outputs (e.g., AgentCore browser tool — page navigation, page inspection)
  3. Run an agent session where accumulated tool results push conversation context past the model's token limit (200k for Claude)
  4. Observe the error when the next ConverseStream call is made

Expected Behavior

The Bedrock model provider should detect a ValidationException with a "prompt is too long" message and raise ContextWindowOverflowException. This would allow conversation managers (e.g., SlidingWindowConversationManager) to catch the exception, call reduce_context(), trim conversation history, and retry automatically — which is how other model providers already handle context overflow.

Actual Behavior

The botocore.errorfactory.ValidationException propagates up as-is and gets wrapped as a generic EventLoopException. The SlidingWindowConversationManager overflow handling never fires because it's looking for ContextWindowOverflowException, not ValidationException. The agent fails hard instead of gracefully trimming context and retrying.

Error message:botocore.errorfactory.ValidationException: prompt is too long: 248369 tokens > 200000 maximum

Additional Context

  1. This is a widespread issue — multiple teams and users are hitting the same ValidationException on context overflow with Bedrock across #bedrock-interest, #wasabi-interest, #pippin-interest, #kiro-cli-internal-software-builders, #strands-agents-interest, and #bedrock-agents-interest. Users are forced to manually clear context or start new sessions.
  2. The Kiro CLI team shipped a fix for their version of this issue in CLI v1.26.2, suggesting the pattern is well-understood.
  3. Bedrock Agents (managed) also surfaces this as a validationException through InvokeAgent, so this may affect multiple integration paths.

Possible Solution

In the Bedrock model provider implementation, detect when:

  1. The exception type is a Bedrock ValidationException (via botocore)
  2. The error message contains "prompt is too long" (or similar pattern like "Input is too long")

→ Raise ContextWindowOverflowException instead of letting the ValidationException propagate.

This aligns Bedrock's behavior with other providers where token overflow is already surfaced as ContextWindowOverflowException, enabling existing conversation manager retry logic to work correctly.

Related Issues

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions