[PR #23590] fix: empty arrays should convert to empty string in LLM prompts #30314

Closed
opened 2026-02-21 20:47:15 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/23590

State: closed
Merged: Yes


Summary

  • Fixed empty array variables displaying as [] in LLM prompts
  • Empty arrays now correctly convert to empty strings

Changes

  • Override text property in ArraySegment class to return empty string for empty arrays
  • Update ArrayStringSegment.text to return empty string instead of json.dumps([]) for empty arrays

Testing

Tested all array segment types to ensure:

  • Empty arrays convert to empty strings
  • Non-empty arrays continue to work correctly
  • Template conversion with {{#sys.files#}} produces clean output

Related Issues

Fixes #23589

Example

Before:

Template: "Your files: {{#sys.files#}}"
Result: "Your files: []"

After:

Template: "Your files: {{#sys.files#}}"  
Result: "Your files: "
**Original Pull Request:** https://github.com/langgenius/dify/pull/23590 **State:** closed **Merged:** Yes --- ## Summary - Fixed empty array variables displaying as `[]` in LLM prompts - Empty arrays now correctly convert to empty strings ## Changes - Override `text` property in `ArraySegment` class to return empty string for empty arrays - Update `ArrayStringSegment.text` to return empty string instead of `json.dumps([])` for empty arrays ## Testing Tested all array segment types to ensure: - Empty arrays convert to empty strings - Non-empty arrays continue to work correctly - Template conversion with `{{#sys.files#}}` produces clean output ## Related Issues Fixes #23589 ## Example **Before:** ``` Template: "Your files: {{#sys.files#}}" Result: "Your files: []" ``` **After:** ``` Template: "Your files: {{#sys.files#}}" Result: "Your files: " ```
yindo added the pull-request label 2026-02-21 20:47:15 -05:00
yindo closed this issue 2026-02-21 20:47:15 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#30314