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 arrays should convert to empty string in LLM prompts (#23590)

-LAN-7230497bf4a4
diff --git a/api/core/variables/segments.py b/api/core/variables/segments.py
index 13274f4e0e1..a99f5eece3e 100644
--- a/api/core/variables/segments.py
+++ b/api/core/variables/segments.py
@@ -119,6 +119,13 @@ class ObjectSegment(Segment):
class ArraySegment(Segment):
+ @property
+ def text(self) -> str:
+ # Return empty string for empty arrays instead of "[]"
+ if not self.value:
+ return ""
+ return super().text
+
@property
def markdown(self) -> str:
items = []
@@ -155,6 +162,9 @@ class ArrayStringSegment(ArraySegment):
@property
def text(self) -> str:
+ # Return empty string for empty arrays instead of "[]"
+ if not self.value:
+ return ""
return json.dumps(self.value, ensure_ascii=False)