Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: empty keywords moderation. (#2108)

Garfield Dai0a5de0ff0b10
diff --git a/api/core/moderation/keywords/keywords.py b/api/core/moderation/keywords/keywords.py
index e367ccfb69e..ca562ad987c 100644
--- a/api/core/moderation/keywords/keywords.py
+++ b/api/core/moderation/keywords/keywords.py
@@ -30,7 +30,10 @@ class KeywordsModeration(Moderation):
if query:
inputs['query__'] = query
+
+ # Filter out empty values
keywords_list = [keyword for keyword in self.config['keywords'].split('\n') if keyword]
+
flagged = self._is_violated(inputs, keywords_list)
return ModerationInputsResult(flagged=flagged, action=ModerationAction.DIRECT_OUTPUT, preset_response=preset_response)
@@ -40,7 +43,9 @@ class KeywordsModeration(Moderation):
preset_response = ""
if self.config['outputs_config']['enabled']:
- keywords_list = self.config['keywords'].split('\n')
+ # Filter out empty values
+ keywords_list = [keyword for keyword in self.config['keywords'].split('\n') if keyword]
+
flagged = self._is_violated({'text': text}, keywords_list)
preset_response = self.config['outputs_config']['preset_response']