From 7230497bf4a499ca215daff76359b406f5795ec2 Mon Sep 17 00:00:00 2001 From: -LAN- Date: Fri, 8 Aug 2025 08:50:37 +0800 Subject: [PATCH] fix: empty arrays should convert to empty string in LLM prompts (#23590) --- api/core/variables/segments.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/api/core/variables/segments.py b/api/core/variables/segments.py index 13274f4e0..a99f5eece 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)