Preserve falsy TemplateTask rule matches (#1261)

This commit is contained in:
HuaTNA
2026-09-23 13:22:36 -04:00
parent 262b03027e
commit 48a34e21c3
2 changed files with 21 additions and 1 deletions
+1 -1
View File
@@ -37,7 +37,7 @@ class TemplateTask(Task):
def prepare(self, element):
# Check if element matches any processing rules
match = self.match(element)
if match:
if match is not None:
return match
# Apply template processing, if applicable
+20
View File
@@ -485,6 +485,26 @@ class TestWorkflow(unittest.TestCase):
results = list(workflow([{"text": "prompt"}]))
self.assertEqual(results[0], "This is a prompt")
def testTemplateRulesFalsy(self):
"""
Test that falsy rule matches bypass template formatting
"""
for value in ("", 0, False):
with self.subTest(value=value):
workflow = Workflow([TemplateTask(template="This is a {text}", rules={"text": value})])
results = list(workflow([{"text": value}, {"text": "prompt"}]))
self.assertEqual(results, [value, "This is a prompt"])
self.assertIs(type(results[0]), type(value))
def testTemplateRulesMissingField(self):
"""
Test that a falsy rule match does not require template fields
"""
workflow = Workflow([TemplateTask(template="This is a {text}", rules={"status": ""})])
self.assertEqual(list(workflow([{"status": ""}])), [""])
def testTemplateRag(self):
"""
Test rag template task