Skip to content
Open
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
3 changes: 3 additions & 0 deletions src/strands/models/bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ def _format_bedrock_messages(self, messages: Messages) -> Messages:
cleaned_messages = []

for message in messages:
if not message["content"]:
Copy link
Member

@dbschmigelski dbschmigelski Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when can content come back as None? Should this not always be getting set to an empty list when we receive the response from Bedrock earlier on?

content: List[ContentBlock]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems to be from other places where session manager stores empty content, and then was sent to bedrock.

Copy link
Member

@dbschmigelski dbschmigelski Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should try to fix it in the session manager where we ensure we never write malformed messages and/or never restore the agent with these malformed messages. Because it seems like Bedrock is functioning correctly it was just passed something that didn't actually adhere to the class which is just possible because we are using python. Otherwise this feels like a patch over a session manager bug

continue

cleaned_content: list[ContentBlock] = []

for content_block in message["content"]:
Expand Down
19 changes: 19 additions & 0 deletions tests/strands/models/test_bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,25 @@ def test_format_request_tool_specs(model, messages, model_id, tool_spec):
assert tru_request == exp_request


def test_format_request_skip_empty_content(model, model_id, inference_config):
messages = [{"role": "user", "content": []}]
model.update_config(**inference_config)
tru_request = model.format_request(messages)
exp_request = {
"inferenceConfig": {
"maxTokens": inference_config["max_tokens"],
"stopSequences": inference_config["stop_sequences"],
"temperature": inference_config["temperature"],
"topP": inference_config["top_p"],
},
"modelId": model_id,
"messages": [],
"system": [],
}

assert tru_request == exp_request


def test_format_request_cache(model, messages, model_id, tool_spec, cache_type):
model.update_config(cache_prompt=cache_type, cache_tools=cache_type)
tru_request = model.format_request(messages, [tool_spec])
Expand Down
Loading