crewAIInc/crewAI · error · ValueError
Directory does not exist: {source_ref}
Error message
Directory does not exist: {source_ref} What it means
ValueError raised when the resolved data type is DataType.DIRECTORY but os.path.isdir is False for the source reference: the adapter was told (or auto-detected) the input is a directory, and that directory does not exist at the given path.
Source
Thrown at lib/crewai-tools/src/crewai_tools/adapters/crewai_rag_adapter.py:213
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",
".pdf",
".zip",
".tar",
".gz",
".bz2",View on GitHub (pinned to 754d7323be)
Solutions
- Use the absolute, resolved directory path and confirm it exists before ingestion.
- Re-check configuration after moving a knowledge folder.
- Validate at startup: for each configured source, assert os.path.isdir(source) or os.path.isfile(source).
Example fix
# before
adapter("./knowledge/base", data_type="directory") # ValueError if missing
# after
from pathlib import Path
d = Path("./knowledge/base").resolve()
assert d.is_dir(), f"missing dir: {d}"
adapter(str(d), data_type=DataType.DIRECTORY) Defensive patterns
Strategy: validation
Validate before calling
import os
if data_type == DataType.DIRECTORY and not os.path.isdir(source_ref):
raise ValueError(f"configured knowledge dir missing: {source_ref}")
adapter(source_ref, data_type=data_type) Type guard
def directory_source_ok(source_ref: str) -> bool:
import os
return os.path.isdir(source_ref) Try / catch
try:
adapter(source_ref, data_type=DataType.DIRECTORY)
except ValueError as e:
if "Directory does not exist" in str(e):
logger.error("fix configured knowledge dir path")
raise Prevention
- Resolve directory sources to absolute paths in configuration.
- Add startup validation for every configured knowledge directory.
- Re-verify paths after moving/renaming knowledge folders.
When it happens
Trigger: Passing a directory path whose data_type resolves to directory (e.g. via auto-detection of a path with no file extension) while the directory is missing, renamed, or the path is relative to a different cwd.
Common situations: Knowledge-source directory moved or renamed after configuration; relative directory paths in services with unpredictable cwd; trailing characters/typos in configured paths.
Related errors
- Invalid data_type: '{raw_data_type}'. Valid values are: 'fil
- File does not exist: {source_ref}
- URL directory loading is not supported. Please provide a loc
- Invalid --definition path: {definition} is not a file.
- Invalid --definition path: {definition} does not exist.
AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15).
Data as JSON: /api/errors/e652563a12d285fd.
Report an issue: GitHub.