fix: strip empty text blocks from assistant content before Bedrock/Anthropic send - #57985
Open
strye wants to merge 1 commit into
Open
fix: strip empty text blocks from assistant content before Bedrock/Anthropic send#57985strye wants to merge 1 commit into
strye wants to merge 1 commit into
Conversation
…thropic send
_convert_assistant_message()'s empty-content guard checked list
truthiness (`blocks or content`), not whether the text inside those
blocks was actually non-empty. When the model returns assistant content
shaped like [{"type": "text", "text": ""}] (e.g. immediately after a
failed clarify tool call), that non-empty *list* containing an empty
*text block* passed the guard untouched and was sent straight to
Bedrock/Anthropic, which reject empty text blocks with HTTP 400
'text content blocks must be non-empty'. Hermes treats this 400 as a
non-retryable client error, killing the turn outright.
Fix: filter out text blocks with empty/whitespace-only text before the
emptiness check, so a genuinely-empty result still falls through to the
existing '(empty)' placeholder.
Repro:
_convert_assistant_message({'role': 'assistant', 'content': [{'type': 'text', 'text': ''}]})
# before: {'role': 'assistant', 'content': [{'type': 'text', 'text': ''}]} -> 400 from API
# after: {'role': 'assistant', 'content': [{'type': 'text', 'text': '(empty)'}]}
Verified against tests/agent/test_anthropic_adapter.py (173 tests):
170 passed / 3 pre-existing unrelated failures, same before and after.
Contributor
|
Thanks for isolating the truthiness failure in the normal assistant-content path; that behavior is still present on current main at Problems
Suggested changes
Automated hermes-sweeper review. |
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.
Summary
Fixes a crash where a turn dies with a non-retryable
HTTP 400: messages: text content blocks must be non-emptyerror from Bedrock/Anthropic.Root cause
_convert_assistant_message()inagent/anthropic_adapter.pyguards against sending empty assistant content with:This checks whether
effective(a list) is truthy, not whether the text inside its blocks is non-empty. When the model returns assistant content shaped like[{"type": "text", "text": ""}]— e.g. right after a tool call errors out (observed after a failedclarifycall with no question text) — that list is non-empty, so the guard passes it through untouched. Bedrock/Anthropic then reject the empty text block outright, and Hermes treats the resulting 400 as non-retryable, killing the turn.Fix
Filter out text blocks whose
textis empty/whitespace-only before the emptiness check, so a genuinely-empty result still falls through to the existing"(empty)"placeholder — otherwise the real content is preserved unchanged.Repro
Test plan
tests/agent/test_anthropic_adapter.py(173 tests) before and after the change: 170 passed / 3 failed both times (the 3 failures are pre-existing and unrelated —TestRunOauthSetupToken, aMagicMock/json.loadsissue, confirmed present on unmodifiedmaintoo).