fix: filter whitespace-only text blocks to prevent API 400 errors#307
Merged
lsdefine merged 1 commit intoMay 9, 2026
Merged
Conversation
When the model only outputs tool calls with no meaningful text, combined_content may contain only whitespace text blocks (e.g. '\n'). Strict API proxies reject this with HTTP 400 'empty content' error. Filter out such blocks before sending to the API.
FeiNiaoBF
pushed a commit
to FeiNiaoBF/GenericAgent
that referenced
this pull request
May 11, 2026
…sdefine#307) When the model only outputs tool calls with no meaningful text, combined_content may contain only whitespace text blocks (e.g. '\n'). Strict API proxies reject this with HTTP 400 'empty content' error. Filter out such blocks before sending to the API.
bendusy
pushed a commit
to bendusy/GenericAgent
that referenced
this pull request
May 14, 2026
…sdefine#307) When the model only outputs tool calls with no meaningful text, combined_content may contain only whitespace text blocks (e.g. '\n'). Strict API proxies reject this with HTTP 400 'empty content' error. Filter out such blocks before sending to the API.
RocketLi
pushed a commit
to RocketLi/GenericAgent
that referenced
this pull request
May 18, 2026
…sdefine#307) When the model only outputs tool calls with no meaningful text, combined_content may contain only whitespace text blocks (e.g. '\n'). Strict API proxies reject this with HTTP 400 'empty content' error. Filter out such blocks before sending to the API.
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.
Problem
When the model only outputs tool calls with no meaningful text response,
NativeToolClient.chat()may produce a user message containing only whitespace text blocks (e.g."\n") alongsidetool_resultblocks.This is rejected by strict API proxies/relays with:
Fix
Filter out whitespace-only text blocks before constructing the merged message in
NativeToolClient.chat()(llmcore.py ~L997).Testing
Verified with model response logs showing
{"type":"text","text":"\n"}being sent, causing 400 errors on proxied Anthropic API channels. After the fix, such empty blocks are filtered out and the request succeeds.