fix(bedrock): replace whitespace-only ' ' placeholder with '(empty message)' in Converse adapter - #39850
Open
HeLLGURD wants to merge 1 commit into
Open
Conversation
…ssage)' in Converse adapter Bedrock's Converse/ConverseStream API rejects text content blocks that contain only whitespace (ValidationException: 'text content blocks must contain non-whitespace text'). The previous fix for NousResearch#9486 replaced empty strings with a single space ' ', which passes the non-empty check but fails the non-whitespace check. Replace all seven ' ' placeholder occurrences in _convert_content_to_converse() and convert_messages_to_converse() with '(empty message)', mirroring the already-correct handling in anthropic_adapter.py. Also tighten the truthiness gate on text parts to use text.strip() instead of bare text truthiness so that genuinely whitespace-only text blocks are also caught. Closes NousResearch#39829
teknium1
reviewed
Jul 14, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for isolating the six literal placeholder sites; the reported assistant-first and empty-content failure is still present on current main at agent/bedrock_adapter.py:505-507, :629, and :655-659.
Problems
- The change does not yet enforce the stated non-whitespace contract for all Converse text blocks. Current paths still pass raw string list items unchanged at
agent/bedrock_adapter.py:512, system list text at:578-580, and tool-result content at:586-590. These paths are outside this diff. - The PR changes no tests. Current
TestEmptyTextBlockFixinstead asserts the obsolete space placeholder attests/agent/test_bedrock_adapter.py:1307-1323.
Suggested changes
- Add conversion-level regressions asserting no emitted text block (including nested
toolResult.contentand system blocks) is whitespace-only. - Extend the same sanitizer/policy to the remaining paths while preserving tool-result pairing.
Automated hermes-sweeper review.
| @@ -464,7 +465,7 @@ def _convert_content_to_converse(content) -> List[Dict]: | |||
| part_type = part.get("type", "") | |||
Contributor
There was a problem hiding this comment.
This handles dict-shaped text parts, but _convert_content_to_converse() still appends raw string list entries unchanged on current main (agent/bedrock_adapter.py:512). Please sanitize a content array such as ["\n"] too, and cover it with a regression test.
This was referenced Aug 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
�gent/bedrock_adapter.py uses a single space ({"text": " "}) as a placeholder for empty/missing message content and for the synthetic user-padding turns that enforce Converse's strict user/assistant alternation requirement. AWS Bedrock's Converse/ConverseStream API - when fronting Anthropic Claude models - rejects whitespace-only text blocks:
ValidationException: text content blocks must contain non-whitespace textThis is the sequel to #9486. That fix replaced empty strings with " ", which passes the non-empty check but fails the non-whitespace check introduced subsequently by the Converse validation layer. The result is a hard, non-retryable failure that fires every time a persisted session is resumed whose earliest stored message is an assistant turn (triggering the leading-user padding path).
Impact
Every �edrock / �edrock_converse request that hits any of the following paths produces an unrecoverable ValidationException:
Fix
Replace all seven {"text": " "} placeholder occurrences in _convert_content_to_converse() and convert_messages_to_converse() with {"text": "(empty message)"}, mirroring the already-correct handling in �gent/anthropic_adapter.py::_convert_user_message. Also tighten the truthiness gate on individual text parts from ext if text to ext if text.strip() so that genuinely whitespace-only text blocks (e.g. "\n") are also caught and replaced with the non-whitespace placeholder.
No behaviour change for any request that does not hit these paths.
Closes #39829