Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions tests/entrypoints/unit_tests/test_chat_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2930,9 +2930,36 @@ def test_postprocess_messages_null_arguments_string():
_postprocess_messages(messages)
tool_calls = messages[0]["tool_calls"]
assert tool_calls is not None
assert messages[0]["content"] == ""
assert tool_calls[0]["function"]["arguments"] == {}


def test_postprocess_messages_null_content_with_tool_calls():
"""Assistant content=null + tool_calls must not reach templates as None.

OpenAI agent clients commonly send this shape. Jinja chat templates that
render {{ content }} would otherwise emit the literal string "None".
"""
messages: list[ConversationMessage] = [
{
"role": "assistant",
"content": None,
"tool_calls": [
{
"id": "call_1",
"type": "function",
"function": {"name": "bash", "arguments": '{"cmd": "ls"}'},
}
],
}
]
_postprocess_messages(messages)
assert messages[0]["content"] == ""
assert messages[0]["tool_calls"][0]["function"]["arguments"] == {
"cmd": "ls"
}


@pytest.mark.asyncio
async def test_resolve_items_does_not_leak_tasks_on_partial_failure():
"""Regression test: one failing media fetch must not abandon the other
Expand Down
10 changes: 10 additions & 0 deletions vllm/entrypoints/chat_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2036,6 +2036,16 @@ def _postprocess_messages(messages: list[ConversationMessage]) -> None:
# so, for messages that have tool_calls, parse the string (which we get
# from openAI format) to dict
for message in messages:
if (
message.get("role") == "assistant"
and message.get("content") is None
and "tool_calls" in message
):
# Agent clients send assistant messages with content=null and
# tool_calls. Templates that render {{ content }} emit a literal
# "None" into the context, which degrades multi-turn generation.
message["content"] = ""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I'm not entirely sure whether this fix is correct or whether it should be a general change. I feel that setting content to None would be more appropriate than setting it to "".

@lllakshit lllakshit Aug 31, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look - leaving content as None is what triggers the bug.

Jinja chat templates that render {{ content }} stringify Python None to the literal text None. That is the prompt pollution reported in #54337 (especially over many tool-calling turns).

Empty string is intentional here because:

  1. OpenAI-style clients already send assistant turns as content: null + tool_calls; the model-facing prompt should treat that as "no text", not the token/None string.
  2. This stays scoped to assistant messages that also have tool_calls, so we do not change general null-content handling elsewhere.

Happy to adjust if you prefer deleting the key instead of an empty string, but keeping None would not fix the reported template behavior.


if message["role"] == "assistant" and "tool_calls" in message:
tool_calls = message.get("tool_calls")
if not isinstance(tool_calls, list):
Expand Down
Loading