fix: preserve None content in assistant messages (#11906)#12470
Open
Sanjays2402 wants to merge 1 commit into
Open
fix: preserve None content in assistant messages (#11906)#12470Sanjays2402 wants to merge 1 commit into
Sanjays2402 wants to merge 1 commit into
Conversation
Empty content was normalized to "" via `or ""`, causing Anthropic-compatible proxies to reject responses with empty text blocks. Now None stays None so tool-call-only messages never emit spurious content.
Contributor
|
LGTM! Clean minimal fix. Good: preserves None, conditional sanitization, clear comments, tests cover tool-call-only case. Minor suggestion: use |
Collaborator
19 tasks
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.
What does this PR do?
_build_assistant_message()normalizedNonecontent to""viaor "". This caused Anthropic-compatible proxies to reject responses containing empty text blocks — the proxy sees{"type": "text", "text": ""}and returns HTTP 400.Fix: keep
NoneasNoneinstead of coercing to empty string. Only apply surrogate sanitization when content is truthy.Before:
_raw_content = assistant_message.content or ""After:
_raw_content = assistant_message.content+ conditional sanitizationRelated Issue
Fixes #11906
Type of Change
Changes Made
_build_assistant_message(): stop coercingNonecontent to""; sanitize surrogates only when content is truthy.test_empty_content→test_none_content_preserved(assertsNonenot"").test_none_content_with_tool_callsfor tool-call-only responses.How to Test
Run Hermes against an Anthropic-compatible proxy that rejects empty text blocks.
Produce a tool-call-only assistant response (no text content).
Before: HTTP 400 from the proxy. After: request succeeds; assistant message carries
content=Noneand tool calls only.Run unit tests:
Checklist
Code
fix:)pytest tests/ -qand all tests passDocumentation & Housekeeping
cli-config.yaml.example— N/ACONTRIBUTING.md/AGENTS.md— N/AScreenshots / Logs
N/A — internal message normalization; covered by new unit tests.