crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[BUG] crewai create flow writes files in the locale encoding on Windows, so the generated crew fails to load

Open devansh173 opened this issue 2 months ago • 3 comments

Description

On Windows, a project generated by crewai create flow fails as soon as its crew is loaded, before any LLM call:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x97 in position 1496: invalid start byte

_create_python_flow reads each template with encoding="utf-8" but writes the rendered file with open(dst_file, "w"), which uses the locale encoding (cp1252 on most Windows installs). The bundled crews/content_crew/config/tasks.yaml template contains an em dash ("Do not rewrite the post — refine and polish it."), so the generated file stores it as the cp1252 byte 0x97. load_yaml in crew_base.py then reads the file as UTF-8 and fails.

copy_template (crewai create crew) and tree_find_and_replace (crewai tool create) have the same read-UTF-8 / write-locale asymmetry. The crew templates are currently ASCII, but the project name is substituted into them. For example, crewai create crew "Café crew" writes description = "Caf\xe9 crew using crewAI" into pyproject.toml, which is not valid TOML (TOML must be UTF-8). Characters outside cp1252 (e.g. ✓) raise UnicodeEncodeError during scaffolding instead.

Steps to Reproduce

  1. On Windows (system locale cp1252), run crewai create flow demo_flow.
  2. cd demo_flow, then load the generated crew (this is what crewai run does first):
    python -c "from demo_flow.crews.content_crew.content_crew import ContentCrew; ContentCrew()"
    
    (with src on PYTHONPATH, or inside the project's venv)
  3. See the UnicodeDecodeError.

Expected behavior

Scaffolded files are written as UTF-8, the encoding their templates are read with and the one crewAI uses to read them back (load_yaml, TOML parsers), so a freshly generated flow runs on Windows as it does on Linux and macOS.

Screenshots/Code snippets

$ crewai create flow demo_flow
$ python -c "print(open('demo_flow/src/demo_flow/crews/content_crew/config/tasks.yaml','rb').read()[1480:1510])"
b'Do not rewrite the post \x97 refi'
  File "...\crewai\project\crew_base.py", line 392, in load_yaml
    content = yaml.safe_load(file)
  ...
  File "...\yaml\reader.py", line 178, in update_raw
    data = self.stream.read(size)
  File "<frozen codecs>", line 325, in decode
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x97 in position 1496: invalid start byte

Operating System

Windows 11

Python Version

3.13

crewAI Version

1.15.22 (also reproduced on main at 7060bf85)

crewAI Tools Version

1.15.22

Virtual Environment

Venv (uv)

Evidence

The generated tasks.yaml contains byte 0x97 (cp1252 em dash) where the template has UTF-8 E2 80 94. ContentCrew() raises the traceback above. Linux and macOS are unaffected because their default encoding is already UTF-8.

Possible Solution

Pass encoding="utf-8" to the three open(..., "w") calls that write rendered templates: create_flow.py (process_file), and copy_template and tree_find_and_replace in utils.py. The matching reads already use UTF-8. Happy to open a PR.

Additional context

Same class of issue as #7490 (checkpoint CLI reading UTF-8 files with the locale encoding).

devansh173 avatar Sep 24 '26 17:09 devansh173

Hi! I'd like to take this. Plan is to make crewai create flow write files as UTF-8 on Windows (instead of the locale encoding) so non-ASCII content stays intact, add a regression test or encoding assertion, and open a PR.

michaelkillgta avatar Sep 25 '26 07:09 michaelkillgta

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Oct 25 '26 12:10 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Oct 31 '26 12:10 github-actions[bot]