crewAIInc/crewAI · warning · FileTooLargeError

File exceeds max size ({actual_size} > {self.max_size_bytes}

Error message

File exceeds max size ({actual_size} > {self.max_size_bytes})

What it means

Raised as FileTooLargeError (a dedicated exception, not ValueError) from FilePath's validator when stat().st_size exceeds max_size_bytes (default DEFAULT_MAX_FILE_SIZE_BYTES, field is settable). This guard prevents loading huge files into memory. Because it is a different exception class, a bare ValueError catch will miss it.

Source

Thrown at lib/crewai-files/src/crewai_files/core/sources.py:240

        path_str = str(self.path)
        if ".." in path_str:
            raise ValueError(f"Path traversal not allowed: {self.path}")

        if self.path.is_symlink():
            resolved = self.path.resolve()
            cwd = Path.cwd().resolve()
            if not str(resolved).startswith(str(cwd)):
                raise ValueError(f"Symlink escapes allowed directory: {self.path}")

        if not self.path.exists():
            raise ValueError(f"File not found: {self.path}")
        if not self.path.is_file():
            raise ValueError(f"Path is not a file: {self.path}")

        actual_size = self.path.stat().st_size
        if actual_size > self.max_size_bytes:
            raise FileTooLargeError(
                f"File exceeds max size ({actual_size} > {self.max_size_bytes})",
                file_name=str(self.path),
                actual_size=actual_size,
                max_size=self.max_size_bytes,
            )

        self._content_type = detect_content_type_from_path(self.path, self.path.name)
        return self

    @property
    def filename(self) -> str:
        """Get the filename from the path."""
        return self.path.name

    @property
    def content_type(self) -> str:
        """Get the content type."""
        return self._content_type

View on GitHub (pinned to 754d7323be)

Solutions

  1. Raise the limit explicitly if your use case allows: FilePath(path=p, max_size_bytes=100_000_000).
  2. Pre-check size before constructing: p.stat().st_size <= limit.
  3. Catch crewai_files.processing.exceptions.FileTooLargeError specifically and reject/downsample the file.
  4. Split or compress oversized files upstream instead of loading them whole.

Example fix

# before
src = FilePath(path=video_path)  # FileTooLargeError with default cap

# after
src = FilePath(path=video_path, max_size_bytes=500_000_000)
Defensive patterns

Strategy: try-catch

Validate before calling

from pathlib import Path

def size_ok(p: Path, limit: int) -> bool:
    return p.stat().st_size <= limit

Try / catch

from crewai_files.processing.exceptions import FileTooLargeError
try:
    src = FilePath(path=p)
except FileTooLargeError as e:
    print(f"reject {e.file_name}: {e.actual_size} > {e.max_size}")  # 413-style response in a web app

Prevention

When it happens

Trigger: FilePath(path=big_video, max_size_bytes=10_000_000) where the file is 50 MB; leaving the default cap while processing large media; logs or data dumps exceeding the configured limit.

Common situations: Accepting user uploads of arbitrary size; feeding model-context pipelines where a size cap protects the LLM context; PDFs/videos commonly exceed small defaults.

Related errors


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