crewAIInc/crewAI · error · FileNotFoundError

File does not exist: {source_ref}

Error message

File does not exist: {source_ref}

What it means

FileNotFoundError raised during auto-detection in the adapter's content-add path: the argument's extension is a known file type, it is not a URL scheme (http/https/file), and os.path.isfile says no such file exists. It protects against typos and wrong working directories before a loader is chosen.

Source

Thrown at lib/crewai-tools/src/crewai_tools/adapters/crewai_rag_adapter.py:208

            ".md",
        }

        for arg in content_items:
            source_ref: str
            if isinstance(arg, dict):
                source_ref = str(arg.get("source", arg.get("content", "")))
            else:
                source_ref = str(arg)

            if not data_type:
                ext = os.path.splitext(source_ref)[1].lower()
                is_url = source_ref.startswith(("http://", "https://", "file://"))
                if (
                    ext in file_extensions
                    and not is_url
                    and not os.path.isfile(source_ref)
                ):
                    raise FileNotFoundError(f"File does not exist: {source_ref}")
                data_type = DataTypes.from_content(source_ref)

            if data_type == DataType.DIRECTORY:
                if not os.path.isdir(source_ref):
                    raise ValueError(f"Directory does not exist: {source_ref}")

                # Define binary and non-text file extensions to skip
                binary_extensions = {
                    ".pyc",
                    ".pyo",
                    ".png",
                    ".jpg",
                    ".jpeg",
                    ".gif",
                    ".bmp",
                    ".ico",
                    ".svg",
                    ".webp",

View on GitHub (pinned to 754d7323be)

Solutions

  1. Pass absolute paths: os.path.abspath(path) or Path(...).resolve() before calling the adapter.
  2. Verify existence at the call site: assert Path(path).is_file().
  3. For remote content, pass a full URL (http://...) so the URL branch is taken instead of the file check.

Example fix

# before
adapter("docs/report.pdf")  # FileNotFoundError if cwd differs

# after
from pathlib import Path
p = Path("docs/report.pdf").resolve()
assert p.is_file(), f"missing: {p}"
adapter(str(p))
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path

p = Path(source_ref)
if not p.is_absolute():
    p = p.resolve()
if p.suffix.lower() in KNOWN_EXTENSIONS and not p.is_file():
    raise FileNotFoundError(f"missing input file: {p}")
adapter(str(p))

Type guard

def input_file_exists(source_ref: str) -> bool:
    from pathlib import Path
    p = Path(source_ref)
    return p.is_file() or source_ref.startswith(("http://", "https://", "file://"))

Try / catch

try:
    adapter(source_ref)
except FileNotFoundError as e:
    logger.error("missing input: %s", e)
    raise

Prevention

When it happens

Trigger: Passing 'docs/report.pdf' (or any known extension) as a positional arg or via path/file_path kwargs when the file is absent, relative to the process's current working directory rather than the caller's intent.

Common situations: Relative paths resolved from a different cwd (service started from another directory); file deleted or not yet written when the tool runs; path built with a missing prefix in env-specific config.

Related errors


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