Exception output after the workflow was published as a tool #5149

Closed
opened 2026-02-21 18:09:37 -05:00 by yindo · 8 comments
Owner

Originally created by @skywolf123 on GitHub (Aug 21, 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.7.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. I did a workflow that was very simple. I started typing a string, passed through an LLM, and the result was the text output by the LLM
  2. Then I published this workflow as a tool
  3. In a new workflow, I started typing a string, connecting an LLM, and then connecting the tool that was just released. The output text of the LLM is given to the tool, and then the output of the tool is given to the result.
  4. However, the output at this time is {"text": "XXXX"} instead of normal XXXXX
    image

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @skywolf123 on GitHub (Aug 21, 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.7.1 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce 1. I did a workflow that was very simple. I started typing a string, passed through an LLM, and the result was the text output by the LLM 2. Then I published this workflow as a tool 3. In a new workflow, I started typing a string, connecting an LLM, and then connecting the tool that was just released. The output text of the LLM is given to the tool, and then the output of the tool is given to the result. 4. However, the output at this time is {"text": "XXXX"} instead of normal XXXXX ![image](https://github.com/user-attachments/assets/bf80c802-15ae-427f-8c59-58de18b48cf2) ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 18:09:37 -05:00
yindo closed this issue 2026-02-21 18:09:37 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 21, 2024):

The output of your tool in the new workflow shows {"text": "XXXX"} instead of the expected normal XXXXX because the text is being returned as a JSON object with a key "text" rather than a plain string. This behavior is likely due to the configuration of the tool or the way the output is being handled in the workflow.

To resolve this, you need to adjust the workflow or tool configuration to extract the value of the text key from the JSON object before displaying it. Here is an example of how you might adjust the workflow to extract the text value:

def create_text_message(self, text: str, save_as: str = '') -> ToolInvokeMessage:
    """
        create a text message

        :param text: the text of the message
        :return: the text message
    """

In this example, you would need to parse the JSON object and extract the value of the text key to display the plain text XXXX instead of the JSON object {"text": "XXXX"}. This can be done by modifying the tool's output handling to directly return the text value [1][2].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Aug 21, 2024): <!-- Answer --> The output of your tool in the new workflow shows `{"text": "XXXX"}` instead of the expected normal `XXXXX` because the text is being returned as a JSON object with a key `"text"` rather than a plain string. This behavior is likely due to the configuration of the tool or the way the output is being handled in the workflow. To resolve this, you need to adjust the workflow or tool configuration to extract the value of the `text` key from the JSON object before displaying it. Here is an example of how you might adjust the workflow to extract the text value: ```python def create_text_message(self, text: str, save_as: str = '') -> ToolInvokeMessage: """ create a text message :param text: the text of the message :return: the text message """ ``` In this example, you would need to parse the JSON object and extract the value of the `text` key to display the plain text `XXXX` instead of the JSON object `{"text": "XXXX"}`. This can be done by modifying the tool's output handling to directly return the text value <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/constants/recommended_apps.json)</sup><sup>[[2]](https://github.com/langgenius/dify-docs/blob/main/en/guides/tools/advanced-tool-integration.md)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@skywolf123 commented on GitHub (Aug 21, 2024):

To be honest, I didn't understand this AI reply

@skywolf123 commented on GitHub (Aug 21, 2024): To be honest, I didn't understand this AI reply
Author
Owner

@dosubot[bot] commented on GitHub (Aug 21, 2024):

To adjust the workflow or tool configuration to extract the value of the text key from the JSON object and display the plain text instead, you can use the JSONParseTool class provided in the Dify platform. This class allows you to extract data from JSON content using a JSON filter.

Here is an example of how you can configure and use this tool to extract and display the plain text value of the text key from a JSON object:

import json
from core.tools.provider.builtin.json_process.tools.parse import JSONParseTool

def extract_and_display_text(json_object):
    tool = JSONParseTool()
    content = json.dumps(json_object)
    json_filter = '$.text'
    tool_parameters = {
        'content': content,
        'json_filter': json_filter,
        'ensure_ascii': True
    }
    result = tool._invoke(user_id='example_user', tool_parameters=tool_parameters)
    return result.content

# Example usage
json_object = {
    "text": "This is a sample text."
}

plain_text = extract_and_display_text(json_object)
print(plain_text)  # Output: This is a sample text.

In this example, the extract_and_display_text function initializes the JSONParseTool, sets up the JSON content and filter, and then invokes the tool to extract the value of the text key. The resulting plain text is then returned and can be displayed as needed [1][2].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Aug 21, 2024): <!-- Answer --> To adjust the workflow or tool configuration to extract the value of the `text` key from the JSON object and display the plain text instead, you can use the `JSONParseTool` class provided in the Dify platform. This class allows you to extract data from JSON content using a JSON filter. Here is an example of how you can configure and use this tool to extract and display the plain text value of the `text` key from a JSON object: ```python import json from core.tools.provider.builtin.json_process.tools.parse import JSONParseTool def extract_and_display_text(json_object): tool = JSONParseTool() content = json.dumps(json_object) json_filter = '$.text' tool_parameters = { 'content': content, 'json_filter': json_filter, 'ensure_ascii': True } result = tool._invoke(user_id='example_user', tool_parameters=tool_parameters) return result.content # Example usage json_object = { "text": "This is a sample text." } plain_text = extract_and_display_text(json_object) print(plain_text) # Output: This is a sample text. ``` In this example, the `extract_and_display_text` function initializes the `JSONParseTool`, sets up the JSON content and filter, and then invokes the tool to extract the value of the `text` key. The resulting plain text is then returned and can be displayed as needed <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/tools/provider/builtin/hap/tools/list_worksheet_records.py)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/api/core/tools/provider/builtin/json_process/tools/parse.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@crazywoola commented on GitHub (Aug 21, 2024):

It's expected behavior, if you don't want the text key, you could use a jinja or code node to extract it. It's the same as retrieving things from HTTP. It should answer with a structure.

I noticed you have already submit a bug report but actually it's not and this one. So next time, please make sure search existing issue or use the discussion to ask a question.

@crazywoola commented on GitHub (Aug 21, 2024): It's expected behavior, if you don't want the text key, you could use a jinja or code node to extract it. It's the same as retrieving things from HTTP. It should answer with a structure. I noticed you have already submit a bug report but actually it's not and this one. So next time, please make sure search existing issue or use the discussion to ask a question.
Author
Owner

@skywolf123 commented on GitHub (Aug 21, 2024):

Leave a record for novice users like me.

Here you need to use a Jinja template converter to take out the required string from the json output part of the tool, note that the json here is an array.

image
image
image

If you use the text section to directly perform string conversion, it may cause no results to be displayed on the published page!

@skywolf123 commented on GitHub (Aug 21, 2024): Leave a record for novice users like me. Here you need to use a Jinja template converter to take out the required string from the json output part of the tool, note that the json here is an array. ![image](https://github.com/user-attachments/assets/fa421d82-07a2-4a71-bed6-d9d50ecb3863) ![image](https://github.com/user-attachments/assets/0c566fb0-7260-4476-9610-208bfef27ad0) ![image](https://github.com/user-attachments/assets/2456c70f-58cc-4911-bf0e-666e8869c4fb) If you use the text section to directly perform string conversion, it may cause no results to be displayed on the published page!
Author
Owner

@yuweimian-shy commented on GitHub (Aug 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.7.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. I did a workflow that was very simple. I started typing a string, passed through an LLM, and the result was the text output by the LLM
  2. Then I published this workflow as a tool
  3. In a new workflow, I started typing a string, connecting an LLM, and then connecting the tool that was just released. The output text of the LLM is given to the tool, and then the output of the tool is given to the result.
  4. However, the output at this time is {"text": "XXXX"} instead of normal XXXXX
    image

✔️ Expected Behavior

No response

Actual Behavior

No response

can you tell me how to publish workflow to tools, Why is the button for my publishing tool grayed out
微信图片_20240822154101

@yuweimian-shy commented on GitHub (Aug 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.7.1 > > ### Cloud or Self Hosted > Self Hosted (Docker) > > ### Steps to reproduce > 1. I did a workflow that was very simple. I started typing a string, passed through an LLM, and the result was the text output by the LLM > 2. Then I published this workflow as a tool > 3. In a new workflow, I started typing a string, connecting an LLM, and then connecting the tool that was just released. The output text of the LLM is given to the tool, and then the output of the tool is given to the result. > 4. However, the output at this time is {"text": "XXXX"} instead of normal XXXXX > ![image](https://private-user-images.githubusercontent.com/34243902/359862585-bf80c802-15ae-427f-8c59-58de18b48cf2.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQzMTI1NjMsIm5iZiI6MTcyNDMxMjI2MywicGF0aCI6Ii8zNDI0MzkwMi8zNTk4NjI1ODUtYmY4MGM4MDItMTVhZS00MjdmLThjNTktNThkZTE4YjQ4Y2YyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIyVDA3Mzc0M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTBhZmM0OTA0ZDMxZTJiOTQzN2Y2MWEzY2UzMzA0OWFlYmI3NmJhZGY2ZmQyN2Q1NDkwMTI0ZjRkNDQ0ZGU3MWUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.Hylt5SCzAbvc8ekxTz2DHiuRrHKAaRU8hn3j9mw3s3k) > > ### ✔️ Expected Behavior > _No response_ > > ### ❌ Actual Behavior > _No response_ can you tell me how to publish workflow to tools, Why is the button for my publishing tool grayed out ![微信图片_20240822154101](https://github.com/user-attachments/assets/3a221524-ee53-4a71-8072-d6dd5a1286f6)
Author
Owner

@skywolf123 commented on GitHub (Aug 22, 2024):

I don't know why you're graying out here, I released this workflow first, and it works normally as a publishing page, and then I click on publishing as a tool, and I haven't encountered your situation.

You can open an issue or a discussion. The maintainers of this seem to be quite busy, they don't like us to ask questions in the form of issues, and they don't like to explain to novice users like me, you can ask people to see if they have encountered your situation.

@skywolf123 commented on GitHub (Aug 22, 2024): I don't know why you're graying out here, I released this workflow first, and it works normally as a publishing page, and then I click on publishing as a tool, and I haven't encountered your situation. You can open an issue or a discussion. The maintainers of this seem to be quite busy, they don't like us to ask questions in the form of issues, and they don't like to explain to novice users like me, you can ask people to see if they have encountered your situation.
Author
Owner

@crazywoola commented on GitHub (Aug 22, 2024):

You can open an issue or a discussion. The maintainers of this seem to be quite busy, they don't like us to ask questions in the form of issues, and they don't like to explain to novice users like me, you can ask people to see if they have encountered your situation.

For questions, it's better to open them in discussions. We already highlighted it in the self checks. But I already answered your questions. :)

@crazywoola commented on GitHub (Aug 22, 2024): > You can open an issue or a discussion. The maintainers of this seem to be quite busy, they don't like us to ask questions in the form of issues, and they don't like to explain to novice users like me, you can ask people to see if they have encountered your situation. For questions, it's better to open them in discussions. We already highlighted it in the self checks. But I already answered your questions. :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5149