{"record":{"id":"a2c9fe529d89bb7e","repo":"crewAIInc/crewAI","slug":"the-filename-must-not-end-with-pkl","errorCode":null,"errorMessage":"The filename must not end with .pkl","messagePattern":"The filename must not end with \\.pkl","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/cli/src/crewai_cli/train_crew.py","lineNumber":20,"sourceCode":"\nimport click\n\n\ndef train_crew(n_iterations: int, filename: str) -> None:\n    \"\"\"\n    Train the crew by running a command in the UV environment.\n\n    Args:\n        n_iterations (int): The number of iterations to train the crew.\n    \"\"\"\n    command = [\"uv\", \"run\", \"train\", str(n_iterations), filename]\n\n    try:\n        if n_iterations <= 0:\n            raise ValueError(\"The number of iterations must be a positive integer.\")\n\n        if not filename.endswith(\".pkl\"):\n            raise ValueError(\"The filename must not end with .pkl\")\n\n        result = subprocess.run(command, capture_output=False, text=True, check=True)  # noqa: S603\n\n        if result.stderr:\n            click.echo(result.stderr, err=True)\n\n    except subprocess.CalledProcessError as e:\n        click.echo(f\"An error occurred while training the crew: {e}\", err=True)\n        click.echo(e.output, err=True)\n\n    except Exception as e:\n        click.echo(f\"An unexpected error occurred: {e}\", err=True)\n","sourceCodeStart":2,"sourceCodeEnd":33,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/cli/src/crewai_cli/train_crew.py#L2-L33","documentation":"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.","triggerScenarios":"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.","commonSituations":"Developments stumped by the inverted message text; users renaming the memory file to .pickle or .bin; scripts passing a path whose extension was stripped.","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."],"exampleFix":"# before (misleading message)\nif not filename.endswith(\".pkl\"):\n    raise ValueError(\"The filename must not end with .pkl\")\n\n# after\nif not filename.endswith(\".pkl\"):\n    raise ValueError(\"The filename must end with .pkl\")","handlingStrategy":"validation","validationCode":"filename = sys.argv[2]\nif not filename.endswith(\".pkl\"):\n    raise SystemExit(\"filename must end with .pkl (message text in older CLI is inverted)\")","typeGuard":"def is_pkl_filename(name: str) -> bool:\n    return isinstance(name, str) and name.endswith(\".pkl\")","tryCatchPattern":null,"preventionTips":["Always name training memory files *.pkl","Remember the shipped error message wording is inverted — the extension is required"],"tags":["crewai","cli","training","validation","misleading-message"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}