Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/strands/models/bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@

BEDROCK_CONTEXT_WINDOW_OVERFLOW_MESSAGES = [
"Input is too long for requested model",
"input length and `max_tokens` exceed context limit",

Check warning on line 43 in src/strands/models/bedrock.py

View workflow job for this annotation

GitHub Actions / check-api

BEDROCK_CONTEXT_WINDOW_OVERFLOW_MESSAGES

Attribute value was changed: `['Input is too long for requested model', 'input length and `max_tokens` exceed context limit', 'too many total text bytes']` -> `['Input is too long for requested model', 'input length and `max_tokens` exceed context limit', 'too many total text bytes', 'prompt is too long']`
"too many total text bytes",
"prompt is too long",
]

# Models that should include tool result status (include_tool_result_status = True)
Expand Down
27 changes: 26 additions & 1 deletion tests/strands/models/test_bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
DEFAULT_BEDROCK_REGION,
DEFAULT_READ_TIMEOUT,
)
from strands.types.exceptions import ModelThrottledException
from strands.types.exceptions import ContextWindowOverflowException, ModelThrottledException
from strands.types.tools import ToolSpec

FORMATTED_DEFAULT_MODEL_ID = DEFAULT_BEDROCK_MODEL_ID.format("us")
Expand Down Expand Up @@ -1516,6 +1516,31 @@ async def test_add_note_on_validation_exception_throughput(bedrock_client, model
]


@pytest.mark.parametrize(
"overflow_message",
[
"Input is too long for requested model",
"input length and `max_tokens` exceed context limit",
"too many total text bytes",
"prompt is too long: 903884 tokens > 200000 maximum",
],
)
@pytest.mark.asyncio
async def test_stream_context_window_overflow(overflow_message, bedrock_client, model, alist, messages):
"""Test that ClientError with overflow messages raises ContextWindowOverflowException."""
error_response = {
"Error": {
"Code": "ValidationException",
"Message": f"An error occurred (ValidationException) when calling the ConverseStream operation: "
f"The model returned the following errors: {overflow_message}",
}
}
bedrock_client.converse_stream.side_effect = ClientError(error_response, "ConverseStream")

with pytest.raises(ContextWindowOverflowException):
await alist(model.stream(messages))


@pytest.mark.asyncio
async def test_stream_logging(bedrock_client, model, messages, caplog, alist):
"""Test that stream method logs debug messages at the expected stages."""
Expand Down
Loading