Skip to content

fix: normalize content to "" instead of dropping it for assistant too…#4003

Open
kanxiao wants to merge 3 commits into
OpenHands:mainfrom
kanxiao:fix/assistant-tool-calls-content-null
Open

fix: normalize content to "" instead of dropping it for assistant too…#4003
kanxiao wants to merge 3 commits into
OpenHands:mainfrom
kanxiao:fix/assistant-tool-calls-content-null

Conversation

@kanxiao

@kanxiao kanxiao commented Jul 6, 2026

Copy link
Copy Markdown

HUMAN:

Fix assistant tool-call messages returning HTTP 422 on some LLMs due to content=null.


AGENT:

Why

Some LLMs (e.g. Gause) return HTTP 422 when an assistant message has tool_calls and content=null. The _remove_content_if_empty() method was dropping the content key entirely, producing content=null in the serialized payload. Some providers require content to be present (even if empty string).

Summary

  • Changed _remove_content_if_empty() to set content="" instead of message_dict.pop("content", None), in both the string and list content branches.
  • Updated two unit tests to assert result["content"] == "" instead of assert "content" not in result.

Issue Number

N/A

How to Test

# Run the unit tests for message serialization
cd openhands-sdk
pytest tests/sdk/llm/test_message.py::test_message_tool_calls_drop_empty_string_content -v
pytest tests/sdk/llm/test_message.py::test_message_tool_calls_strip_blank_list_content -v
pytest tests/sdk/llm/test_message.py::test_message_with_tool_calls -v
pytest tests/sdk/llm/test_message.py::test_empty_assistant_message_uses_string_content_in_list_serializer -v
pytest tests/sdk/llm/test_message.py::test_empty_assistant_from_llm_chat_message_uses_string_content_in_list_serializer -v

Expected: all 5 tests pass, and assistant messages with tool_calls + empty content now serialize as {"role": "assistant", "content": "", "tool_calls": [...]} instead of having the content key absent.

Video/Screenshots

N/A

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

This is consistent with the existing _normalize_empty_assistant_content() behavior which already sets content="" for non-tool-call assistant messages. The change only affects the wire format sent to LLM providers — internal Message objects are unchanged.

kanxiao and others added 2 commits July 6, 2026 21:54
…l-call messages

Some LLMs (e.g. Gause) return HTTP 422 when an assistant message has
tool_calls and content=null. Previously _remove_content_if_empty() dropped
the content key entirely, which produced content=null in the serialized
payload. Now it sets content="" instead, matching the behavior that
_normalize_empty_assistant_content() already uses for non-tool-call messages.
@all-hands-bot

Copy link
Copy Markdown
Collaborator

[Automatic Post]: It has been a while since there was any activity on this PR. @kanxiao, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up.

This comment was posted by an AI agent (OpenHands) on behalf of the user.

@all-hands-bot

Copy link
Copy Markdown
Collaborator

[Automatic Post]: It has been a while since there was any activity on this PR. @kanxiao, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up.

This comment was created by an AI agent (OpenHands) on behalf of the user.

@all-hands-bot
all-hands-bot requested a review from enyst July 19, 2026 12:51
@all-hands-bot

Copy link
Copy Markdown
Collaborator

[Automatic Post]: I have assigned @enyst as a reviewer based on the repository MAINTAINERS file. Thanks in advance for the help!

This comment was created by an AI agent (OpenHands) on behalf of the repository maintainers.

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