crewAIInc/crewAI · warning · ValueError

Project name '{name}' contains no valid characters for a Pyt

Error message

Project name '{name}' contains no valid characters for a Python class name

What it means

Raised as UnsupportedFileTypeError by crewai-files validators when the file's MIME content_type is not in the supported_formats tuple for its type class (e.g. an ImageConstraints allowing only image/png, image/jpeg). Validation is exact string membership on the content type, so near-misses like image/jpg or application/octet-stream for a real image still fail.

Source

Thrown at lib/cli/src/crewai_cli/create_crew.py:98

    if not folder_name.isidentifier():
        raise ValueError(
            f"Project name '{name}' would generate invalid Python module name '{folder_name}'"
        )

    reserved_names = get_reserved_script_names()
    if folder_name in reserved_names:
        raise ValueError(
            f"Project name '{name}' would generate folder name '{folder_name}' which is reserved. "
            f"Reserved names are: {', '.join(sorted(reserved_names))}. "
            "Please choose a different name."
        )

    class_name = name.replace("_", " ").replace("-", " ").title().replace(" ", "")

    class_name = re.sub(r"[^a-zA-Z0-9_]", "", class_name)

    if not class_name:
        raise ValueError(
            f"Project name '{name}' contains no valid characters for a Python class name"
        )

    if class_name[0].isdigit():
        raise ValueError(
            f"Project name '{name}' would generate class name '{class_name}' which cannot start with a digit"
        )

    original_name_clean = re.sub(
        r"[^a-zA-Z0-9_]", "", name.replace("_", "").replace("-", "").lower()
    )
    if (
        keyword.iskeyword(original_name_clean)
        or keyword.iskeyword(class_name)
        or class_name in ("True", "False", "None")
    ):
        raise ValueError(
            f"Project name '{name}' would generate class name '{class_name}' which is a reserved Python keyword"

View on GitHub (pinned to 754d7323be)

Solutions

  1. Convert the file to a supported format before validation (e.g. re-encode WEBP to PNG/JPEG)
  2. Ensure the upload path sets the correct Content-Type — sniff with mimetypes.guess_type or python-magic instead of trusting the client
  3. Extend the constraints' supported_formats tuple to include the format you actually accept (e.g. add 'image/webp')
  4. Catch UnsupportedFileTypeError and reply with the supported list from the error's fields

Example fix

# before
constraints = ImageConstraints(supported_formats=('image/png', 'image/jpeg'))
validate_image(file, constraints)  # file is image/webp -> UnsupportedFileTypeError

# after
constraints = ImageConstraints(supported_formats=('image/png', 'image/jpeg', 'image/webp'))
validate_image(file, constraints)
Defensive patterns

Strategy: validation

Validate before calling

import mimetypes

def content_type_supported(path: str, supported: tuple[str, ...]) -> bool:
    guessed, _ = mimetypes.guess_type(path)
    return guessed in supported

# before validation, normalize:
# content_type = content_type.lower().split(';')[0].strip()

Try / catch

from crewai_files.processing.errors import UnsupportedFileTypeError

try:
    validate_image(img, constraints)
except UnsupportedFileTypeError as e:
    return bad_request(f"{e.file_name}: type {e.content_type} not allowed; use one of the supported formats")

Prevention

When it happens

Trigger: Calling validate_image (validators.py:210-222) with raise_on_error=True when content_type is absent from supported_formats — e.g. a WEBP sent to constraints that only list png/jpeg, or a client that sends the generic application/octet-stream because it guessed the type from the extension. With raise_on_error=False the message is only appended to the errors list.

Common situations: Newer formats (webp, avif, heic) not in a conservative supported_formats tuple; clients that don't set Content-Type and default to octet-stream; capitalization or alias mismatches ('image/JPEG', 'image/jpg'); constraints updated between versions to drop a legacy format.

Related errors


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