Skip to content

fix: preserve None content for assistant messages to avoid Anthropic HTTP 400 - #11945

Closed
vominh1919 wants to merge 1 commit into
NousResearch:mainfrom
vominh1919:fix/11906-anthropic-empty-content
Closed

fix: preserve None content for assistant messages to avoid Anthropic HTTP 400#11945
vominh1919 wants to merge 1 commit into
NousResearch:mainfrom
vominh1919:fix/11906-anthropic-empty-content

Conversation

@vominh1919

Copy link
Copy Markdown
Contributor

Fixes #11906

When assistant_message.content is None (tool-call-only response), the previous code converted it to an empty string. Anthropic-compatible proxies reject empty text content blocks with HTTP 400: "messages: text content blocks must be non-empty".

Fix: Preserve None as None when no tool calls are present. Only coalesce to empty string when tool_calls exist (some APIs require non-None content alongside tool_calls).

Changes:

  • run_agent.py: Change assistant_message.content or "" to assistant_message.content in the message builder
  • Add safety check: when tool_calls are present but content is None, set to empty string

…HTTP 400

When assistant_message.content is None (tool-call-only response), the
previous code converted it to an empty string. Anthropic-compatible
proxies reject empty text content blocks with HTTP 400:
'messages: text content blocks must be non-empty'.

Fix: preserve None as None when no tool calls are present. Only
coalesce to empty string when tool_calls exist (some APIs require
non-None content alongside tool_calls).

Fixes NousResearch#11906
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the contribution, @vominh1919!

Closing this as a duplicate of #12470 (by @Sanjays2402), which targets the same fix/feature. We're consolidating on that PR for review.

If you want to help push it over the line, please jump in there — or if you think your approach is better for a specific reason that isn't covered in the other PR, let us know and we can reopen.

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.

[Bug]: Assistant messages with empty content cause HTTP 400 on Anthropic-compatible proxies

2 participants