crewAIInc/crewAI · error · ValueError

File not found: {self.path}

Error message

File not found: {self.path}

What it means

Straightforward existence check in FilePath's model_validator: Path.exists() is False for the supplied path, so validation fails with the path in the message. It runs after the traversal and symlink guards, so if you get this (rather than error 131/132) the path passed security checks but nothing is there — deleted, not yet written, typo, or wrong working directory for a relative path.

Source

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

    _content_type: str = PrivateAttr()

    @model_validator(mode="after")
    def _validate_file_exists(self) -> FilePath:
        """Validate that the file exists, is secure, and within size limits."""
        from crewai_files.processing.exceptions import FileTooLargeError

        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."""

View on GitHub (pinned to 754d7323be)

Solutions

  1. Check Path(...).exists() (and log the absolute path via .resolve()) right before constructing FilePath.
  2. Use absolute paths derived from a known anchor (__file__ or a configured ROOT) rather than CWD-relative strings.
  3. In async pipelines, await the producer/write task before building the file source.

Example fix

# before
src = FilePath(path=Path("uploads/x.pdf"))  # written later by another task

# after
await write_task.join()
p = UPLOAD_DIR / "x.pdf"
assert p.exists(), f"missing {p.resolve()}"
src = FilePath(path=p)
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path

def file_ready(p: Path) -> bool:
    return p.exists() and p.is_file()

Try / catch

try:
    FilePath(path=p)
except ValidationError as e:
    if "File not found" in str(e):
        # re-check with absolute path for logging
        print("missing:", p.resolve())

Prevention

When it happens

Trigger: FilePath(path=Path("uploads/x.pdf")) before the upload completed; relative path resolved against an unexpected CWD; race where the file was removed between listing and validation.

Common situations: Async pipelines that construct the model before the writer task finishes; relative paths in containers/servers where CWD differs from the app root; files cleaned up by temp-dir lifecycle (pytest tmp_path deleted).

Related errors


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