Unterminated string starting at: line 19column 24 (char 23) #20469

Closed
opened 2026-02-21 20:07:35 -05:00 by yindo · 5 comments
Owner

Originally created by @KannibalH on GitHub (Nov 20, 2025).

Dify version

1.9.2

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Problem Description

This is an intermittent bug. Each time a Q&A session is conducted, tools are invoked, and they return JSON results for subsequent tools to use. Sometimes the error occurs after calling the first tool, and other times it happens later when calling subsequent tools, but the error is always the same.
It has been confirmed that the error is not caused by the system prompt.

Environment Information

  • Dify Version: 1.9.2
  • Dify Plugin: vllm and OpenAPI-API-compatible
  • Network: Pure Offline Environment
  • OS: CentOS 7

✔️ Expected Behavior

Image

Do not allow such errors to occur.

Actual Behavior

Image Image

An error has occurred.

Originally created by @KannibalH on GitHub (Nov 20, 2025). ### Dify version 1.9.2 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce ### Problem Description This is an intermittent bug. Each time a Q&A session is conducted, tools are invoked, and they return JSON results for subsequent tools to use. Sometimes the error occurs after calling the first tool, and other times it happens later when calling subsequent tools, but the error is always the same. It has been confirmed that the error is not caused by the system prompt. ### Environment Information - Dify Version: 1.9.2 - Dify Plugin: vllm and OpenAPI-API-compatible - Network: Pure Offline Environment - OS: CentOS 7 ### ✔️ Expected Behavior <img width="1409" height="812" alt="Image" src="https://github.com/user-attachments/assets/063b2881-8bcc-430c-9101-841bdd88b524" /> Do not allow such errors to occur. ### ❌ Actual Behavior <img width="1344" height="675" alt="Image" src="https://github.com/user-attachments/assets/031e1ed5-0401-4773-99f8-f7e394545643" /> <img width="2254" height="870" alt="Image" src="https://github.com/user-attachments/assets/0fb6b799-29a6-4bf5-a2ca-ccc1aedd2732" /> An error has occurred.
yindo added the 🐞 bug label 2026-02-21 20:07:35 -05:00
yindo closed this issue 2026-02-21 20:07:35 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Nov 20, 2025):

Hi @KannibalH! I'm Dosu and I’m helping the dify team.

Your errors are likely caused by malformed or mismatched tool outputs and parameter formats in your workflow. The "Unterminated string" JSON parsing error usually happens when a tool returns incomplete or invalid JSON, often due to tool parameters being passed as a string instead of a dictionary, or when the AI response doesn't match the expected structure. Make sure all tool parameters are dictionaries, not strings, and that any JSON returned by tools is well-formed and complete. If you use a JSON string, always parse it into a dictionary before passing it to the tool—otherwise, you'll see errors like tool_parameters should be a dict, but got a string and downstream JSON parsing failures. See this discussion for details and code examples.

For the datetime ValueError, tools like timezone_conversion expect datetime strings in the format %Y-%m-%d %H:%M:%S. If a previous tool (like current_time) outputs a string without seconds (e.g., 2025-11-20 20:00), the next tool will fail to parse it. Always set the format parameter explicitly to %Y-%m-%d %H:%M:%S in your time-related tools to ensure compatibility between steps. See the tool implementation and timezone conversion logic.

A recent fix also improved how tool responses (including JSON) are concatenated and output, preventing duplication and malformed outputs in some cases. If you are able to update, consider reviewing this pull request.

To prevent these errors: always use explicit, matching formats for datetime strings across tools, ensure tool parameters are dictionaries, and validate that all tool outputs are valid JSON before passing them to the next step.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Nov 20, 2025): <!-- Greeting --> Hi @KannibalH! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the dify team. <!-- Answer --> Your errors are likely caused by malformed or mismatched tool outputs and parameter formats in your workflow. The "Unterminated string" JSON parsing error usually happens when a tool returns incomplete or invalid JSON, often due to tool parameters being passed as a string instead of a dictionary, or when the AI response doesn't match the expected structure. Make sure all tool parameters are dictionaries, not strings, and that any JSON returned by tools is well-formed and complete. If you use a JSON string, always parse it into a dictionary before passing it to the tool—otherwise, you'll see errors like `tool_parameters should be a dict, but got a string` and downstream JSON parsing failures. See [this discussion for details and code examples](https://github.com/langgenius/dify/issues/14224). For the datetime ValueError, tools like `timezone_conversion` expect datetime strings in the format `%Y-%m-%d %H:%M:%S`. If a previous tool (like `current_time`) outputs a string without seconds (e.g., `2025-11-20 20:00`), the next tool will fail to parse it. Always set the `format` parameter explicitly to `%Y-%m-%d %H:%M:%S` in your time-related tools to ensure compatibility between steps. See [the tool implementation](https://github.com/langgenius/dify/blob/ae5b5a6aa9b570d54944cc7ffbe227f5972c4c76/api/core/tools/builtin_tool/providers/time/tools/current_time.py#L11-L36) and [timezone conversion logic](https://github.com/langgenius/dify/blob/ae5b5a6aa9b570d54944cc7ffbe227f5972c4c76/api/core/tools/builtin_tool/providers/time/tools/timezone_conversion.py#L34-L53). A recent fix also improved how tool responses (including JSON) are concatenated and output, preventing duplication and malformed outputs in some cases. If you are able to update, consider reviewing [this pull request](https://github.com/langgenius/dify/pull/27706). To prevent these errors: always use explicit, matching formats for datetime strings across tools, ensure tool parameters are dictionaries, and validate that all tool outputs are valid JSON before passing them to the next step. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/6531ac04-6b3b-4868-a6cd-293e1b9698a7?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/6531ac04-6b3b-4868-a6cd-293e1b9698a7?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/6531ac04-6b3b-4868-a6cd-293e1b9698a7?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/6531ac04-6b3b-4868-a6cd-293e1b9698a7?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/6531ac04-6b3b-4868-a6cd-293e1b9698a7?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/6531ac04-6b3b-4868-a6cd-293e1b9698a7?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/6531ac04-6b3b-4868-a6cd-293e1b9698a7?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/28491)
Author
Owner

@KannibalH commented on GitHub (Nov 20, 2025):

@dosu
This is an intermittent bug. Each time a Q&A session is conducted, tools are invoked, and they return JSON results for subsequent tools to use. Sometimes the error occurs after calling the first tool, and other times it happens later when calling subsequent tools, but the error is always the same.
It has been confirmed that the error is not caused by the system prompt.

@KannibalH commented on GitHub (Nov 20, 2025): @dosu This is an intermittent bug. Each time a Q&A session is conducted, tools are invoked, and they return JSON results for subsequent tools to use. Sometimes the error occurs after calling the first tool, and other times it happens later when calling subsequent tools, but the error is always the same. It has been confirmed that the error is not caused by the system prompt.
Author
Owner

@dosubot[bot] commented on GitHub (Nov 20, 2025):

This intermittent "Unterminated string" JSON parsing error is most often caused by malformed or incomplete JSON being passed between tools in your workflow. In Dify, tool outputs are streamed and concatenated, and if a tool returns partial, duplicated, or mixed text/JSON output, the next tool may fail to parse it—especially if the output is not strictly valid JSON or if tool parameters are passed as a string instead of a dictionary. This is a known systemic issue in agent workflows, especially when chaining tools or using plugins that sometimes omit expected keys or return inconsistent output formats (details, code reference).

Immediate steps to reduce or avoid these errors:

  • Always ensure tool parameters are dictionaries, not strings. If you receive a string, parse it to a dict before passing it to the next tool (code reference).
  • Validate that every tool output is well-formed JSON before chaining it to the next tool. If possible, preprocess plugin outputs to match the expected schema and add defensive checks for missing keys (e.g., use .get() or provide default values).
  • If you use streaming or function-calling with vLLM or OpenAPI-compatible plugins, try disabling streaming (set enable_stream to false) to see if the error disappears, as streaming can sometimes cause partial or malformed outputs (example).
  • For time/datetime tools, always set the output format explicitly (e.g., %Y-%m-%d %H:%M:%S) to avoid downstream parsing errors.
  • If you have custom plugins or tools, add error handling around JSON parsing and ensure outputs always include all expected keys, even if empty.

There are ongoing requests for more robust defensive checks and retries in Dify's agent node, but for now, careful validation and preprocessing of tool outputs is the best workaround (discussion). If you need code examples for defensive checks or output validation, let me know your workflow details.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Nov 20, 2025): <!-- Answer --> This intermittent "Unterminated string" JSON parsing error is most often caused by malformed or incomplete JSON being passed between tools in your workflow. In Dify, tool outputs are streamed and concatenated, and if a tool returns partial, duplicated, or mixed text/JSON output, the next tool may fail to parse it—especially if the output is not strictly valid JSON or if tool parameters are passed as a string instead of a dictionary. This is a known systemic issue in agent workflows, especially when chaining tools or using plugins that sometimes omit expected keys or return inconsistent output formats ([details](https://github.com/langgenius/dify-official-plugins/issues/1704), [code reference](https://github.com/langgenius/dify/blob/ae5b5a6aa9b570d54944cc7ffbe227f5972c4c76/api/core/workflow/nodes/tool/tool_node.py#L61-L447)). Immediate steps to reduce or avoid these errors: - Always ensure tool parameters are dictionaries, not strings. If you receive a string, parse it to a dict before passing it to the next tool ([code reference](https://github.com/langgenius/dify/blob/ae5b5a6aa9b570d54944cc7ffbe227f5972c4c76/api/core/tools/tool_engine.py#L62-L265)). - Validate that every tool output is well-formed JSON before chaining it to the next tool. If possible, preprocess plugin outputs to match the expected schema and add defensive checks for missing keys (e.g., use .get() or provide default values). - If you use streaming or function-calling with vLLM or OpenAPI-compatible plugins, try disabling streaming (set `enable_stream` to false) to see if the error disappears, as streaming can sometimes cause partial or malformed outputs ([example](https://github.com/langgenius/dify-official-plugins/issues/1121)). - For time/datetime tools, always set the output format explicitly (e.g., `%Y-%m-%d %H:%M:%S`) to avoid downstream parsing errors. - If you have custom plugins or tools, add error handling around JSON parsing and ensure outputs always include all expected keys, even if empty. There are ongoing requests for more robust defensive checks and retries in Dify's agent node, but for now, careful validation and preprocessing of tool outputs is the best workaround ([discussion](https://github.com/langgenius/dify-official-plugins/issues/1704)). If you need code examples for defensive checks or output validation, let me know your workflow details. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/7bffb1ca-5641-4117-bbc0-1ec44b3a3e0c?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/7bffb1ca-5641-4117-bbc0-1ec44b3a3e0c?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/7bffb1ca-5641-4117-bbc0-1ec44b3a3e0c?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/7bffb1ca-5641-4117-bbc0-1ec44b3a3e0c?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/7bffb1ca-5641-4117-bbc0-1ec44b3a3e0c?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/7bffb1ca-5641-4117-bbc0-1ec44b3a3e0c?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/7bffb1ca-5641-4117-bbc0-1ec44b3a3e0c?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/28491)
Author
Owner

@KannibalH commented on GitHub (Nov 21, 2025):

@fatelei
thx! Could this be an issue with the Qwen3 model? After I set stream function calling in the plugin to false, this error has no longer occurred.

@KannibalH commented on GitHub (Nov 21, 2025): @fatelei thx! Could this be an issue with the Qwen3 model? After I set stream function calling in the plugin to false, this error has no longer occurred.
Author
Owner

@dosubot[bot] commented on GitHub (Dec 28, 2025):

Hi, @KannibalH. I'm Dosu, and I'm helping the Dify team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported an intermittent "Unterminated string" JSON parsing error during Q&A sessions using vllm and OpenAPI plugins in Dify v1.9.2.
  • The error occurred unpredictably after tool calls and was not caused by the system prompt.
  • The root cause was identified as malformed or incomplete JSON outputs, often due to passing tool parameters as strings instead of dictionaries or streaming partial outputs.
  • Disabling streaming resolved the issue, and best practices include passing tool parameters as dictionaries, validating JSON outputs, and setting explicit datetime formats.
  • Ongoing improvements are planned, but these workarounds remain effective for now.

Next Steps:

  • Please confirm if this issue is still relevant with the latest version of Dify; if so, feel free to keep the discussion open by commenting here.
  • Otherwise, I will automatically close this issue in 15 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Dec 28, 2025): Hi, @KannibalH. I'm [Dosu](https://dosu.dev), and I'm helping the Dify team manage their backlog and am marking this issue as stale. **Issue Summary:** - You reported an intermittent "Unterminated string" JSON parsing error during Q&A sessions using vllm and OpenAPI plugins in Dify v1.9.2. - The error occurred unpredictably after tool calls and was not caused by the system prompt. - The root cause was identified as malformed or incomplete JSON outputs, often due to passing tool parameters as strings instead of dictionaries or streaming partial outputs. - Disabling streaming resolved the issue, and best practices include passing tool parameters as dictionaries, validating JSON outputs, and setting explicit datetime formats. - Ongoing improvements are planned, but these workarounds remain effective for now. **Next Steps:** - Please confirm if this issue is still relevant with the latest version of Dify; if so, feel free to keep the discussion open by commenting here. - Otherwise, I will automatically close this issue in 15 days. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#20469