keywords moderation #909

Closed
opened 2026-02-21 17:28:58 -05:00 by yindo · 5 comments
Owner

Originally created by @ShirohaUmi on GitHub (Jan 15, 2024).

Originally assigned to: @GarfieldDai on GitHub.

Self Checks

Dify version

0.4.6

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

/api/core/moderation/keywords/keywords.py-----moderation_for_inputs

keywords_list = self.config['keywords'].split('\n')

if the keywords is "a\n",then the keywords_list will be "a" and "". Then each input will violate the rule because "" is in every string.

After that,when moderating ouput, "" is also in the response. So we will see the output is violated the rules instead of the input.


关键词分割的时候会分割出来”“空字符串,然后输入过不了审查。可以分割之后判空,同时去掉空格。
输入审查不通过,然后输入审查不通过的预设语句也过不了输出审查,结果最后看到是输出审查失败,可以从业务层面思考一下如何处理这种情况

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @ShirohaUmi on GitHub (Jan 15, 2024). Originally assigned to: @GarfieldDai on GitHub. ### Self Checks - [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 file this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). ### Dify version 0.4.6 ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce /api/core/moderation/keywords/keywords.py-----moderation_for_inputs ```python keywords_list = self.config['keywords'].split('\n') ``` if the keywords is "a\n",then the keywords_list will be "a" and "". Then each input will violate the rule because "" is in every string. After that,when moderating ouput, "" is also in the response. So we will see the output is violated the rules instead of the input. ----- 关键词分割的时候会分割出来”“空字符串,然后输入过不了审查。可以分割之后判空,同时去掉空格。 输入审查不通过,然后输入审查不通过的预设语句也过不了输出审查,结果最后看到是输出审查失败,可以从业务层面思考一下如何处理这种情况 ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 17:28:58 -05:00
yindo closed this issue 2026-02-21 17:28:58 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jan 15, 2024):

🤖

It's great to see that you've identified an issue and proposed a solution for the keyword moderation in dify. Your input on handling the empty string and whitespace after splitting the keywords is valuable. Encouraging you to go ahead and create a pull request with your proposed changes. Your contribution will help improve the dify platform for everyone. Thank you for your willingness to contribute!


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

@dosubot[bot] commented on GitHub (Jan 15, 2024): _🤖_ <!-- Answer --> It's great to see that you've identified an issue and proposed a solution for the keyword moderation in dify. Your input on handling the empty string and whitespace after splitting the keywords is valuable. Encouraging you to go ahead and create a pull request with your proposed changes. Your contribution will help improve the dify platform for everyone. Thank you for your willingness to contribute! --- This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot.
Author
Owner

@GarfieldDai commented on GitHub (Jan 15, 2024):

#2042 Fixed.

@GarfieldDai commented on GitHub (Jan 15, 2024): #2042 Fixed.
Author
Owner

@ShirohaUmi commented on GitHub (Jan 16, 2024):

the same situation will happen again when moderating output....

输出也要改的。
然后输入审查失败的预设回复过不了输出审查的情况是否需要考虑一下?

@ShirohaUmi commented on GitHub (Jan 16, 2024): the same situation will happen again when moderating output.... ---- 输出也要改的。 然后输入审查失败的预设回复过不了输出审查的情况是否需要考虑一下?
Author
Owner

@GarfieldDai commented on GitHub (Jan 20, 2024):

@ShirohaUmi Output moderation has been fixed. #2108

@GarfieldDai commented on GitHub (Jan 20, 2024): @ShirohaUmi Output moderation has been fixed. #2108
Author
Owner

@GarfieldDai commented on GitHub (Jan 20, 2024):

「然后输入审查失败的预设回复过不了输出审查的情况是否需要考虑一下?」
@ShirohaUmi Can you give me a real example?

@GarfieldDai commented on GitHub (Jan 20, 2024): 「然后输入审查失败的预设回复过不了输出审查的情况是否需要考虑一下?」 @ShirohaUmi Can you give me a real example?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#909