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

  1. Rename the filename argument to end with .pkl: `crewai train 5 memory.pkl` — the message wording is inverted; the code requires the extension.
  2. If maintaining this file, fix the message to 'The filename must end with .pkl' to match the check.
  3. 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

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


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/a2c9fe529d89bb7e. Report an issue: GitHub.