From ce1d90ab1e48d98c5b3ebd00c890ea4b16f7c3f2 Mon Sep 17 00:00:00 2001 From: Vidit Ostwal Date: Wed, 29 Jan 2025 20:09:30 +0530 Subject: [PATCH] Added a Pydantic Error Check between output_log_file and save_as_json parameter --- src/crewai/crew.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/crewai/crew.py b/src/crewai/crew.py index b84b4bf65..e435af5d1 100644 --- a/src/crewai/crew.py +++ b/src/crewai/crew.py @@ -440,6 +440,13 @@ class Crew(BaseModel): f"Task '{task.description}' has a context dependency on a future task '{context_task.description}', which is not allowed." ) return self + + @model_validator(mode="after") + def validate_output_log_file_and_save_as_json_compatibility(self): + """Validates that saving as JSON is not enabled when output logging is disabled, as this would be an invalid configuration.""" + if not self.output_log_file and self.save_as_json: # handles False, None, empty string + raise PydanticCustomError("Cannot save as JSON when output logging is disabled") + return self @property def key(self) -> str: