When the response format is JSON, invalid JSON data is returned in the tongyi plugin #79

Closed
opened 2026-02-16 10:18:00 -05:00 by yindo · 1 comment
Owner

Originally created by @MBP888 on GitHub (Mar 14, 2025).

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.0.1

Plugin version

0.0.11

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

When using the qwen model, if the response format is set to JSON, there is a probability that the resulting JSON string will be missing quotes, rendering the generated JSON string unparsable.

The issue occurs in the method: _handle_generate_stream_response. The problematic code is as follows:

assistant_prompt_message = AssistantPromptMessage(
    content=resp_content.replace(full_text, "", 1)
)
full_text = resp_content

Because when constructing the request earlier, during streaming output, it was already set to incremental response:

response = Generation.call(
    **params,
    result_format="message",
    stream=stream,
    incremental_output=stream,
)

So should full_text = resp_content be changed to full_text += resp_content
Or should

assistant_prompt_message = AssistantPromptMessage(
    content=resp_content.replace(full_text, "", 1)
)

be changed to:

assistant_prompt_message = AssistantPromptMessage(
    content=resp_content
)

✔️ Error log

No response

Originally created by @MBP888 on GitHub (Mar 14, 2025). ### 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.0.1 ### Plugin version 0.0.11 ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce When using the qwen model, if the response format is set to JSON, there is a probability that the resulting JSON string will be missing quotes, rendering the generated JSON string unparsable. The issue occurs in the method: _handle_generate_stream_response. The problematic code is as follows: ```python assistant_prompt_message = AssistantPromptMessage( content=resp_content.replace(full_text, "", 1) ) full_text = resp_content ``` Because when constructing the request earlier, during streaming output, it was already set to incremental response: ```python response = Generation.call( **params, result_format="message", stream=stream, incremental_output=stream, ) ``` So should `full_text = resp_content` be changed to `full_text += resp_content` Or should ```python assistant_prompt_message = AssistantPromptMessage( content=resp_content.replace(full_text, "", 1) ) ``` be changed to: ```python assistant_prompt_message = AssistantPromptMessage( content=resp_content ) ``` ### ✔️ Error log _No response_
yindo added the bug label 2026-02-16 10:18:00 -05:00
yindo closed this issue 2026-02-16 10:18:00 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 16, 2025):

Hi, @MBP888. I'm Dosu, and I'm helping the dify-official-plugins team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported that the qwen model in the tongyi plugin sometimes returns invalid JSON due to missing quotes.
  • The issue seems related to how the _handle_generate_stream_response method updates the full_text variable.
  • You suggested modifying the code to accumulate full_text or adjust content assignment to fix JSON formatting.
  • There has been no further activity or comments on this issue since your report.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of the dify-official-plugins repository by commenting here.
  • If I do not hear back within 5 days, I will automatically close this issue.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Aug 16, 2025): Hi, @MBP888. I'm [Dosu](https://dosu.dev), and I'm helping the dify-official-plugins team manage their backlog and am marking this issue as stale. **Issue Summary:** - You reported that the qwen model in the tongyi plugin sometimes returns invalid JSON due to missing quotes. - The issue seems related to how the `_handle_generate_stream_response` method updates the `full_text` variable. - You suggested modifying the code to accumulate `full_text` or adjust content assignment to fix JSON formatting. - There has been no further activity or comments on this issue since your report. **Next Steps:** - Please let me know if this issue is still relevant with the latest version of the dify-official-plugins repository by commenting here. - If I do not hear back within 5 days, I will automatically close this issue. 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-official-plugins#79