crewAIInc/crewAI · error · ValueError
Path is not a file: {self.path}
Error message
Path is not a file: {self.path} What it means
Validation error from FilePath: the path exists but Path.is_file() is False, meaning it is a directory, FIFO, device, or socket. FilePath must load file content, so non-regular targets are rejected. Distinct from the existence check (error 133) — here the entry exists but is the wrong kind.
Source
Thrown at lib/crewai-files/src/crewai_files/core/sources.py:236
@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."""
return self.path.name
View on GitHub (pinned to 754d7323be)
Solutions
- Point at a specific file inside the directory (join the filename).
- Filter candidates with Path.is_file() when iterating directory listings before constructing FilePath.
- Check for a trailing slash or missing filename in constructed paths.
Example fix
# before
src = FilePath(path=Path("data/attachments")) # directory
# after
src = FilePath(path=Path("data/attachments") / "invoice.pdf") Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
def is_regular_file(p: Path) -> bool:
return p.is_file() Try / catch
try:
FilePath(path=p)
except ValidationError as e:
if "not a file" in str(e):
for child in p.iterdir():
if child.is_file():
return FilePath(path=child) Prevention
- Always join the concrete filename: dir / filename, never the bare directory.
- Filter iterdir()/glob() results with .is_file() before constructing sources.
When it happens
Trigger: FilePath(path=Path("uploads")) pointing at the directory instead of a file inside it; passing /dev/null works (it is a file-ish device) but a named pipe or a directory fails; glob patterns that matched a directory.
Common situations: Users pass the containing folder expecting the library to discover files; os.listdir results that include subdirectories fed straight into FilePath.
Related errors
- File not found: {self.path}
- Expected an async readable object with async read() method
- Expected a binary file-like object with read() and seek()
- Path traversal not allowed: {self.path}
- Symlink escapes allowed directory: {self.path}
AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15).
Data as JSON: /api/errors/aa3e57d83cc1dab7.
Report an issue: GitHub.