[Deepseek]: _clean_messages drops ToolPromptMessage with empty content, causing message corruption #971

Closed
opened 2026-02-16 10:21:09 -05:00 by yindo · 0 comments
Owner

Originally created by @Nov1c444 on GitHub (Feb 10, 2026).

Originally assigned to: @Nov1c444 on GitHub.

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues Dify issues & Dify Official Plugins, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.12.0

Plugin version

0.0.10

Cloud or Self Hosted

Self Hosted (Source)

Description

When a tool call returns successfully but produces no output (empty string content), the _clean_messages method in DeepseekLargeLanguageModel incorrectly filters it out. This happens because the empty-content check (line 45) executes before the ToolPromptMessage protection logic (line 49).
The removal of a ToolPromptMessage has two cascading effects:

  1. The tool call / tool response pairing is broken — the API expects every tool_call to have a corresponding tool response message.
  2. The adjacent AssistantPromptMessages that were previously separated by the ToolPromptMessage become consecutive same-role messages and get erroneously merged, corrupting the conversation history.
    Reproduction: Use DeepSeek in an agent workflow where a tool call succeeds with no stdout (e.g. a Python script that writes a file but prints nothing). The subsequent messages get merged and the structured tool-call flow is destroyed.
    Fix: Move the ToolPromptMessage / SystemPromptMessage guard before the empty-content filter so these message types are always preserved regardless of content.
Originally created by @Nov1c444 on GitHub (Feb 10, 2026). Originally assigned to: @Nov1c444 on GitHub. ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [Dify issues](https://github.com/langgenius/dify/issues) & [Dify Official Plugins](https://github.com/langgenius/dify-official-plugins/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.12.0 ### Plugin version 0.0.10 ### Cloud or Self Hosted Self Hosted (Source) ### Description When a tool call returns successfully but produces no output (empty string content), the _clean_messages method in DeepseekLargeLanguageModel incorrectly filters it out. This happens because the empty-content check (line 45) executes before the ToolPromptMessage protection logic (line 49). The removal of a ToolPromptMessage has two cascading effects: 1. The tool call / tool response pairing is broken — the API expects every tool_call to have a corresponding tool response message. 2. The adjacent AssistantPromptMessages that were previously separated by the ToolPromptMessage become consecutive same-role messages and get erroneously merged, corrupting the conversation history. Reproduction: Use DeepSeek in an agent workflow where a tool call succeeds with no stdout (e.g. a Python script that writes a file but prints nothing). The subsequent messages get merged and the structured tool-call flow is destroyed. Fix: Move the ToolPromptMessage / SystemPromptMessage guard before the empty-content filter so these message types are always preserved regardless of content.
yindo added the bug label 2026-02-16 10:21:09 -05:00
yindo closed this issue 2026-02-16 10:21:09 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-official-plugins#971