crewAIInc/crewAI · error · ValueError
The filename must not end with .pkl
Error message
The filename must not end with .pkl
What it means
ValueError raised by train_crew() when `not filename.endswith('.pkl')` — i.e. the training memory filename MUST end with .pkl. The message text is misleadingly worded ('must not end with .pkl'); the code actually requires the .pkl extension, because the artifact is a pickled memory object.
Source
Thrown at lib/cli/src/crewai_cli/train_crew.py:20
import click
def train_crew(n_iterations: int, filename: str) -> None:
"""
Train the crew by running a command in the UV environment.
Args:
n_iterations (int): The number of iterations to train the crew.
"""
command = ["uv", "run", "train", str(n_iterations), filename]
try:
if n_iterations <= 0:
raise ValueError("The number of iterations must be a positive integer.")
if not filename.endswith(".pkl"):
raise ValueError("The filename must not end with .pkl")
result = subprocess.run(command, capture_output=False, text=True, check=True) # noqa: S603
if result.stderr:
click.echo(result.stderr, err=True)
except subprocess.CalledProcessError as e:
click.echo(f"An error occurred while training the crew: {e}", err=True)
click.echo(e.output, err=True)
except Exception as e:
click.echo(f"An unexpected error occurred: {e}", err=True)
View on GitHub (pinned to 754d7323be)
Solutions
- Rename the filename argument to end with .pkl: `crewai train 5 memory.pkl` — the message wording is inverted; the code requires the extension.
- If maintaining this file, fix the message to 'The filename must end with .pkl' to match the check.
- Strip directory-traversal or quote issues that might truncate the extension in shell invocation.
Example fix
# before (misleading message)
if not filename.endswith(".pkl"):
raise ValueError("The filename must not end with .pkl")
# after
if not filename.endswith(".pkl"):
raise ValueError("The filename must end with .pkl") Defensive patterns
Strategy: validation
Validate before calling
filename = sys.argv[2]
if not filename.endswith(".pkl"):
raise SystemExit("filename must end with .pkl (message text in older CLI is inverted)") Type guard
def is_pkl_filename(name: str) -> bool:
return isinstance(name, str) and name.endswith(".pkl") Prevention
- Always name training memory files *.pkl
- Remember the shipped error message wording is inverted — the extension is required
When it happens
Trigger: Calling crewai train with a filename lacking the .pkl extension, e.g. `crewai train 5 memory` or `crewai train 5 model.json`. The condition `not filename.endswith('.pkl')` is true for those, so the ValueError fires.
Common situations: Developments stumped by the inverted message text; users renaming the memory file to .pickle or .bin; scripts passing a path whose extension was stripped.
Related errors
- The number of iterations must be a positive integer.
- An error occurred while training the crew: {e}
- Invalid JSON payload provided as argument
- Invalid JSON payload provided as argument
- Failed to publish tool. Local changes need to be resolved be
AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15).
Data as JSON: /api/errors/a2c9fe529d89bb7e.
Report an issue: GitHub.