Issue when agent uses workflow as a tool with JSON string as paragraph input #4568

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

Originally created by @sepa85 on GitHub (Jul 11, 2024).

Originally assigned to: @laipz8200 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 search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.13

Cloud or Self Hosted

Cloud

Steps to reproduce

Use a workflow as a tool, a feature provided by Dify, designed to accept input fields of type paragraph.
Have an agent use this workflow to send a JSON string that includes characters requiring escaping (e.g., backslashes, newlines).
Execute the request through the agent.

Example JSON Strings That May Cause the Error:

{
  "example": "This is a test string with a newline character\nand a backslash \\ character."
}
{
  "data": [
    {
      "id": "123",
      "description": "Line1\nLine2"
    },
    {
      "id": "456",
      "description": "Path\\to\\file"
    }
  ]
}

Observe the response from the agent.

Examples That Will Cause the Bug:

Example with Newline and Backslash:

{
  "operation": "set",
  "new_text": "[{\"uuid\":\"727f978c-176d-4996-94f2-401fa540177b\",\"node_type\":\"node--instruction\",\"updated_text\":\"Example instruction with special characters\\n\\n# Example\\r\\n\\r\\nThis is a test string with a newline character\\nand a backslash \\\\\\\\ character.\\r\\n\\r\\n## Data Section\\r\\n### Example Data:\\r\\n```json { \\\"data\\\": [ { \\\"id\\\": \\\"123\\\", \\\"description\\\": \\\"Line1\\\\nLine2\\\" }, { \\\"id\\\": \\\"456\\\", \\\"description\\\": \\\"Path\\\\\\\\to\\\\\\\\file\\\" } ] }```\"}]"
}

Example with Multiple Backslashes:

{
  "operation": "set",
  "new_text": "[{\"uuid\":\"727f978c-176d-4996-94f2-401fa540177b\",\"node_type\":\"node--instruction\",\"updated_text\":\"Example instruction with special characters\n\n# Example\r\n\r\nThis is a test string with multiple backslashes \\\\\\\\\\\\\\.\r\n\r\n## Data Section\r\n### Example Data:\r\n```json { \\\"data\\\": [ { \\\"id\\\": \\\"123\\\", \\\"description\\\": \\\"Path\\\\\\\\to\\\\\\\\file\\" } ] }```\"]"
}

Example with Incorrect Escaping:

{
  "operation": "set",
  "new_text": "[{\"uuid\":\"727f978c-176d-4996-94f2-401fa540177b\",\"node_type\":\"node--instruction\",\"updated_text\":\"Incorrect escaping example\n\n# Example\r\n\r\nThis example has incorrect escaping for newline \n and backslash \\. It should fail.\r\n\r\n## Data Section\r\n### Example Data:\r\n```json { \"data\": [ { \"id\": \"123\", \"description\": \"Line1\nLine2\" }, { \"id\": \"456\", \"description\": \"Path\to\file\\" } ] }```\"]"
}

This is our worflow as a tool inputs. Pay attention to "new text" paragraph input:

Screenshot from 2024-07-11 16-48-09

✔️ Expected Behavior

When using the proposed JSON directly as input in the workflow (manually, not via the agent), the workflow processes successfully without errors. The agent should also correctly handle escaped characters in the JSON string and process the input without errors.

Actual Behavior

When the agent uses the workflow, it returns a SyntaxError related to bad escaped characters in JSON, indicating that there is an issue with how the agent processes and escapes certain characters before sending them to the workflow.

Probable Causes of the Bug:

  • Character Escaping: There may be an issue with how many backslashes are used for escaping special characters. Using too many or too few can result in invalid JSON.

  • Newline and Carriage Return Handling: The handling of newline (\n) and carriage return (\r) characters might be inconsistent when processed by the agent.

  • Formatting: The format of the JSON block within the text might cause issues if not correctly escaped.
    Here is an example of corrected JSON that works when used directly in the workflow:

{
  "operation": "set",
  "new_text": "[{\"uuid\":\"727f978c-176d-4996-94f2-401fa540177b\",\"node_type\":\"node--instruction\",\"updated_text\":\"Example instruction with special characters\n\n# Example\r\n\r\nThis is a test string with a newline character\nand a backslash \\\\\\ character.\r\n\r\n## Data Section\r\n### Example Data:\r\n```json { \\\"data\\\": [ { \\\"id\\\": \\\"123\\\", \\\"description\\\": \\\"Line1\\\\nLine2\\\" }, { \\\"id\\\": \\\"456\\\", \\\"description\\\": \\\"Path\\\\to\\\\file\\" } ] }```\"]"
}

This is the error from the tool, invoked by the agent, with a json working if used as input in workflow (not as tool):

Screenshot from 2024-07-11 17-24-49

And this is the same tool, working with a simplier updated_text:

Screenshot from 2024-07-11 17-26-42

Originally created by @sepa85 on GitHub (Jul 11, 2024). Originally assigned to: @laipz8200 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 [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] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.6.13 ### Cloud or Self Hosted Cloud ### Steps to reproduce Use a workflow as a tool, a feature provided by Dify, designed to accept input fields of type paragraph. Have an agent use this workflow to send a JSON string that includes characters requiring escaping (e.g., backslashes, newlines). Execute the request through the agent. **Example JSON Strings That May Cause the Error:** ```json { "example": "This is a test string with a newline character\nand a backslash \\ character." } ``` ```Json { "data": [ { "id": "123", "description": "Line1\nLine2" }, { "id": "456", "description": "Path\\to\\file" } ] } ``` Observe the response from the agent. **Examples That Will Cause the Bug:** **Example with Newline and Backslash:** ```Json { "operation": "set", "new_text": "[{\"uuid\":\"727f978c-176d-4996-94f2-401fa540177b\",\"node_type\":\"node--instruction\",\"updated_text\":\"Example instruction with special characters\\n\\n# Example\\r\\n\\r\\nThis is a test string with a newline character\\nand a backslash \\\\\\\\ character.\\r\\n\\r\\n## Data Section\\r\\n### Example Data:\\r\\n```json { \\\"data\\\": [ { \\\"id\\\": \\\"123\\\", \\\"description\\\": \\\"Line1\\\\nLine2\\\" }, { \\\"id\\\": \\\"456\\\", \\\"description\\\": \\\"Path\\\\\\\\to\\\\\\\\file\\\" } ] }```\"}]" } ``` **Example with Multiple Backslashes:** ```Json { "operation": "set", "new_text": "[{\"uuid\":\"727f978c-176d-4996-94f2-401fa540177b\",\"node_type\":\"node--instruction\",\"updated_text\":\"Example instruction with special characters\n\n# Example\r\n\r\nThis is a test string with multiple backslashes \\\\\\\\\\\\\\.\r\n\r\n## Data Section\r\n### Example Data:\r\n```json { \\\"data\\\": [ { \\\"id\\\": \\\"123\\\", \\\"description\\\": \\\"Path\\\\\\\\to\\\\\\\\file\\" } ] }```\"]" } ``` **Example with Incorrect Escaping:** ```Json { "operation": "set", "new_text": "[{\"uuid\":\"727f978c-176d-4996-94f2-401fa540177b\",\"node_type\":\"node--instruction\",\"updated_text\":\"Incorrect escaping example\n\n# Example\r\n\r\nThis example has incorrect escaping for newline \n and backslash \\. It should fail.\r\n\r\n## Data Section\r\n### Example Data:\r\n```json { \"data\": [ { \"id\": \"123\", \"description\": \"Line1\nLine2\" }, { \"id\": \"456\", \"description\": \"Path\to\file\\" } ] }```\"]" } ``` This is our worflow as a tool inputs. Pay attention to "new text" paragraph input: ![Screenshot from 2024-07-11 16-48-09](https://github.com/langgenius/dify/assets/19758187/e924d0fe-8f99-463a-99ab-bdd67fd52745) ### ✔️ Expected Behavior When using the proposed JSON directly as input in the workflow (manually, not via the agent), the workflow processes successfully without errors. The agent should also correctly handle escaped characters in the JSON string and process the input without errors. ### ❌ Actual Behavior When the agent uses the workflow, it returns a SyntaxError related to bad escaped characters in JSON, indicating that there is an issue with how the agent processes and escapes certain characters before sending them to the workflow. **Probable Causes of the Bug:** - Character Escaping: There may be an issue with how many backslashes are used for escaping special characters. Using too many or too few can result in invalid JSON. - Newline and Carriage Return Handling: The handling of newline (\n) and carriage return (\r) characters might be inconsistent when processed by the agent. - Formatting: The format of the JSON block within the text might cause issues if not correctly escaped. Here is an example of corrected JSON that works when used directly in the workflow: ```Json { "operation": "set", "new_text": "[{\"uuid\":\"727f978c-176d-4996-94f2-401fa540177b\",\"node_type\":\"node--instruction\",\"updated_text\":\"Example instruction with special characters\n\n# Example\r\n\r\nThis is a test string with a newline character\nand a backslash \\\\\\ character.\r\n\r\n## Data Section\r\n### Example Data:\r\n```json { \\\"data\\\": [ { \\\"id\\\": \\\"123\\\", \\\"description\\\": \\\"Line1\\\\nLine2\\\" }, { \\\"id\\\": \\\"456\\\", \\\"description\\\": \\\"Path\\\\to\\\\file\\" } ] }```\"]" } ``` This is the error from the tool, invoked by the agent, with a json working if used as input in workflow (not as tool): ![Screenshot from 2024-07-11 17-24-49](https://github.com/langgenius/dify/assets/19758187/d4ae2ad5-a90a-4e5f-b229-eaaf41023510) And this is the same tool, working with a simplier `updated_text`: ![Screenshot from 2024-07-11 17-26-42](https://github.com/langgenius/dify/assets/19758187/a5dbe136-549e-4227-88ea-61297b3c3f84)
yindo added the 🐞 bug🤖 feat:agent labels 2026-02-21 18:07:03 -05:00
yindo closed this issue 2026-02-21 18:07:03 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jul 11, 2024):

To resolve the SyntaxError related to bad escaped characters in JSON when using a workflow as a tool in Dify version 0.6.13 (Cloud) with input fields of type paragraph, ensure that the JSON strings are properly escaped. Specifically, you need to escape characters like backslashes (\), double quotes ("), and other special characters within the JSON strings.

Here is an example of how to properly escape a JSON string:

{
  "paragraph": "This is a paragraph with a newline character\\n and a double quote \\\" that needs to be escaped."
}

In the context of Dify, if you are setting up a variable of type paragraph, make sure the input is correctly formatted and escaped:

const variableConfig = {
  fieldType: 'paragraph',
  description: 'Setare pentru variabila {{varName}}',
  string: 'Text scurt',
  'text-input': 'Text scurt',
  'paragraph': 'Paragraf',
  'select': 'Selectați',
  'number': 'Număr',
  'notSet': 'Nesetat, încercați să tastați {{input}} în promptul de prefix',
  'stringTitle': 'Opțiuni casetă text formular',
  'maxLength': 'Lungime maximă',
  'options': 'Opțiuni',
};

Ensure that any JSON data you are working with in the workflow is properly escaped to avoid syntax errors [1].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Jul 11, 2024): <!-- Answer --> To resolve the `SyntaxError` related to bad escaped characters in JSON when using a workflow as a tool in Dify version 0.6.13 (Cloud) with input fields of type paragraph, ensure that the JSON strings are properly escaped. Specifically, you need to escape characters like backslashes (`\`), double quotes (`"`), and other special characters within the JSON strings. Here is an example of how to properly escape a JSON string: ```json { "paragraph": "This is a paragraph with a newline character\\n and a double quote \\\" that needs to be escaped." } ``` In the context of Dify, if you are setting up a variable of type paragraph, make sure the input is correctly formatted and escaped: ```ts const variableConfig = { fieldType: 'paragraph', description: 'Setare pentru variabila {{varName}}', string: 'Text scurt', 'text-input': 'Text scurt', 'paragraph': 'Paragraf', 'select': 'Selectați', 'number': 'Număr', 'notSet': 'Nesetat, încercați să tastați {{input}} în promptul de prefix', 'stringTitle': 'Opțiuni casetă text formular', 'maxLength': 'Lungime maximă', 'options': 'Opțiuni', }; ``` Ensure that any JSON data you are working with in the workflow is properly escaped to avoid syntax errors <sup>[[1]](https://github.com/langgenius/dify/blob/main/web/i18n/ro-RO/app-debug.ts)</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#4568