Merge pull request #1262 from HuaTNA/fix-template-falsy-rules

Preserve falsy TemplateTask rule matches
This commit is contained in:
David Mezzetti
2026-09-23 16:36:47 -04:00
committed by GitHub
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