From bce10f597808e30b41f7cd5c334af50a6c487067 Mon Sep 17 00:00:00 2001 From: Lorenze Jay <63378463+lorenzejay@users.noreply.github.com> Date: Sun, 5 Apr 2026 22:21:18 -0700 Subject: [PATCH] fix: ensure output directory exists before writing in flow template (#5291) The `save_content` method wrote to `output/post.md` without ensuring the `output/` directory exists, causing a FileNotFoundError when the directory hasn't been created by another step. Co-authored-by: Claude Opus 4.6 (1M context) --- lib/crewai/src/crewai/cli/templates/flow/main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/crewai/src/crewai/cli/templates/flow/main.py b/lib/crewai/src/crewai/cli/templates/flow/main.py index 29f21033f..836eb65ca 100644 --- a/lib/crewai/src/crewai/cli/templates/flow/main.py +++ b/lib/crewai/src/crewai/cli/templates/flow/main.py @@ -1,4 +1,6 @@ #!/usr/bin/env python +from pathlib import Path + from pydantic import BaseModel from crewai.flow import Flow, listen, start @@ -42,7 +44,9 @@ class ContentFlow(Flow[ContentState]): @listen(generate_content) def save_content(self): print("Saving content") - with open("output/post.md", "w") as f: + output_dir = Path("output") + output_dir.mkdir(exist_ok=True) + with open(output_dir / "post.md", "w") as f: f.write(self.state.final_post) print("Post saved to output/post.md")