[BUG] Custom prompt_file rejects UTF-8 JSON files with a BOM
Description
I18N(prompt_file=...) rejects a custom prompt file saved as UTF-8 with a byte-order mark. The same JSON without a BOM loads successfully. This is a source-review finding reproduced offline against main@40bb2d3b586e8367d206090cc62df5242206008f, not a reported production incident.
The custom-file branch of I18N.load_prompts opens the file with encoding="utf-8". That leaves the leading U+FEFF in the decoded string, so json.load raises Unexpected UTF-8 BOM. The loader wraps that as Error decoding JSON from the prompts file.
Steps to Reproduce
Run against an installed checkout of the commit above:
import json
from pathlib import Path
from tempfile import TemporaryDirectory
from crewai.utilities.i18n import I18N
with TemporaryDirectory() as directory:
path = Path(directory) / "prompts.json"
path.write_text(
json.dumps({"slices": {"role_playing": "Research assistant"}}),
encoding="utf-8-sig",
)
print(I18N(prompt_file=str(path)).slice("role_playing"))
Change only encoding="utf-8-sig" to encoding="utf-8" in path.write_text for the passing control. No provider or API key is required.
Expected behavior
The custom prompt JSON loads with or without a UTF-8 BOM, producing the same prompt string. A U+FEFF within a prompt value should remain unchanged, and malformed JSON should still fail.
Screenshots/Code snippets
The source opens the custom prompt file with encoding="utf-8" in lib/crewai/src/crewai/utilities/i18n.py:38. A BOM-encoded file starts with bytes EF BB BF.
Operating System
Native Windows (the exact Windows product edition is not claimed).
Python Version
3.12.8
crewAI Version
1.15.28, editable checkout of main at the SHA above.
crewAI Tools Version
Not installed or involved in this reproduction.
Virtual Environment
Venv created by uv. Dependencies installed with uv sync --locked --package crewai --group dev --python <Python-3.12.8>.
Evidence
With a parameterized regression for plain UTF-8 / UTF-8 with BOM, plus malformed-JSON controls and the existing I18N tests, the unchanged implementation gives 1 failed, 9 passed. The failure is the BOM-valid-JSON case:
json.decoder.JSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1 (char 0)
The above exception was the direct cause of the following exception:
Exception: Error decoding JSON from the prompts file.
Possible Solution
Use encoding="utf-8-sig" for the user-supplied prompt file. This consumes only an optional leading signature, continues to read plain UTF-8, and preserves U+FEFF characters in prompt values. Keep the built-in prompt resource and existing error handling unchanged. The repository's JSONLoader already uses this decoding policy for local JSON files; this report concerns the separate I18N path.
Additional context
Searches of Issues and all-state PRs for I18N/prompt_file combined with BOM/encoding did not identify an existing matching fix when this was prepared. Prompt propagation work such as #7855 addresses a different path.
AI assistance: Codex inspected the source, reproduced the behavior, prepared a focused patch and tests, and drafted this report. Per the contribution policy, please add llm-generated; this external account cannot apply repository labels.
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.
This issue was closed because it has been stalled for 5 days with no activity.