Tool node extract_tool_response_text add empty elements to list #6892

Closed
opened 2026-02-21 18:17:51 -05:00 by yindo · 1 comment
Owner

Originally created by @pedrogomes02 on GitHub (Nov 22, 2024).

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 search for existing issues, 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

0.11.2

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Use a tool that outputs only more than one ToolInvokeMessage.MessageType.JSON.
Check tool output on tracing. Only the "json" output should be filled, the "text" output should be empty or an empty string.

✔️ Expected Behavior

Only the "json" output should be filled, the "text" output should be empty or an empty string.

Actual Behavior

The "json" output should is filled, but the "text" output is an list of "\n".

Originally created by @pedrogomes02 on GitHub (Nov 22, 2024). ### 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 [search for existing issues](https://github.com/langgenius/dify/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 0.11.2 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce Use a tool that outputs only more than one ToolInvokeMessage.MessageType.JSON. Check tool output on tracing. Only the "json" output should be filled, the "text" output should be empty or an empty string. ### ✔️ Expected Behavior Only the "json" output should be filled, the "text" output should be empty or an empty string. ### ❌ Actual Behavior The "json" output should is filled, but the "text" output is an list of "\n".
yindo added the 🐞 bug label 2026-02-21 18:17:51 -05:00
yindo closed this issue 2026-02-21 18:17:51 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Nov 22, 2024):

The issue you're experiencing with the extract_tool_response_text function is due to the way the list comprehension is structured in the _extract_tool_response_text method. Specifically, it adds an empty string "" for any ToolInvokeMessage that is not of type TEXT or LINK. This results in a list of empty strings, which when joined with "\n", produces a string of newline characters.

Here's the relevant part of the code:

def _extract_tool_response_text(self, tool_response: list[ToolInvokeMessage]) -> str:
    return "\n".join(
        [
            f"{message.message}"
            if message.type == ToolInvokeMessage.MessageType.TEXT
            else f"Link: {message.message}"
            if message.type == ToolInvokeMessage.MessageType.LINK
            else ""
            for message in tool_response
        ]
    )

The else "" part is responsible for adding empty strings for message types that are neither TEXT nor LINK [1].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Nov 22, 2024): <!-- Answer --> The issue you're experiencing with the `extract_tool_response_text` function is due to the way the list comprehension is structured in the `_extract_tool_response_text` method. Specifically, it adds an empty string `""` for any `ToolInvokeMessage` that is not of type `TEXT` or `LINK`. This results in a list of empty strings, which when joined with `"\n"`, produces a string of newline characters. Here's the relevant part of the code: ```python def _extract_tool_response_text(self, tool_response: list[ToolInvokeMessage]) -> str: return "\n".join( [ f"{message.message}" if message.type == ToolInvokeMessage.MessageType.TEXT else f"Link: {message.message}" if message.type == ToolInvokeMessage.MessageType.LINK else "" for message in tool_response ] ) ``` The `else ""` part is responsible for adding empty strings for message types that are neither `TEXT` nor `LINK` <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/workflow/nodes/tool/tool_node.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#6892