From 43cb2d1f6652a47985ac7c762a4827d259faae03 Mon Sep 17 00:00:00 2001 From: "Frieda (Jingying) Huang" Date: Sun, 15 Dec 2024 13:28:17 -0500 Subject: [PATCH] Fixed yaml config is not escaped properly for output requirements --- src/crewai/task.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/crewai/task.py b/src/crewai/task.py index b585e0c69..05188f164 100644 --- a/src/crewai/task.py +++ b/src/crewai/task.py @@ -308,7 +308,18 @@ class Task(BaseModel): if inputs: self.description = self._original_description.format(**inputs) - self.expected_output = self._original_expected_output.format(**inputs) + self.expected_output = self.interpolate_only( + input_string=self._original_expected_output, inputs=inputs + ) + + def interpolate_only(self, input_string: str, inputs: Dict[str, Any]) -> str: + """Interpolate placeholders (e.g., {key}) in a string while leaving JSON untouched.""" + escaped_string = input_string.replace("{", "{{").replace("}", "}}") + + for key in inputs.keys(): + escaped_string = escaped_string.replace(f"{{{{{key}}}}}", f"{{{key}}}") + + return escaped_string.format(**inputs) def increment_tools_errors(self) -> None: """Increment the tools errors counter."""