Skip to content

fix: filter whitespace-only text blocks to prevent API 400 errors#307

Merged
lsdefine merged 1 commit into
lsdefine:mainfrom
wangjc683:fix/empty-text-block-in-native-chat
May 9, 2026
Merged

fix: filter whitespace-only text blocks to prevent API 400 errors#307
lsdefine merged 1 commit into
lsdefine:mainfrom
wangjc683:fix/empty-text-block-in-native-chat

Conversation

@wangjc683

Copy link
Copy Markdown
Contributor

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") alongside tool_result blocks.

This is rejected by strict API proxies/relays with:

HTTP 400: "The last user message has empty content. Provide a non-empty user prompt."

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.

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.
@lsdefine
lsdefine merged commit cde1620 into lsdefine:main May 9, 2026
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.
lsdefine pushed a commit that referenced this pull request Jul 23, 2026
)

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants