run-llama/llama_index · error · ValueError

Directory {input_dir} does not exist.

Error message

Directory {input_dir} does not exist.

What it means

SimpleDirectoryReader raises this ValueError during __init__ when an input_dir is passed but self.fs.isdir(input_dir) returns False. The reader validates the directory exists (on the local filesystem or the provided fsspec filesystem) before enumerating files. It exists to fail fast on a bad path instead of silently producing an empty index.

Source

Thrown at llama-index-core/llama_index/core/readers/file/base.py:295

        self.exclude = exclude
        self.recursive = recursive
        self.exclude_hidden = exclude_hidden
        self.exclude_empty = exclude_empty
        self.required_exts = required_exts
        self.num_files_limit = num_files_limit
        self.raise_on_error = raise_on_error
        _Path = Path if is_default_fs(self.fs) else PurePosixPath

        if input_files:
            self.input_files = []
            for path in input_files:
                if not self.fs.isfile(path):
                    raise ValueError(f"File {path} does not exist.")
                input_file = _Path(path)
                self.input_files.append(input_file)
        elif input_dir:
            if not self.fs.isdir(input_dir):
                raise ValueError(f"Directory {input_dir} does not exist.")
            self.input_dir = _Path(input_dir)
            self.exclude = exclude
            self.input_files = self._add_files(self.input_dir)

        self.file_extractor = file_extractor or {}
        self.file_metadata = file_metadata or _DefaultFileMetadataFunc(self.fs)
        self.filename_as_id = filename_as_id

    def is_hidden(self, path: Path | PurePosixPath) -> bool:
        return any(
            part.startswith(".") and part not in [".", ".."] for part in path.parts
        )

    def is_empty_file(self, path: Path | PurePosixPath) -> bool:
        return self.fs.isfile(str(path)) and self.fs.info(str(path)).get("size", 0) == 0

    def _is_directory(self, path: Path | PurePosixPath) -> bool:
        """

View on GitHub (pinned to afd0fef371)

Solutions

  1. Verify the directory exists and is readable from the process running the code: os.path.isdir(input_dir) or ls the absolute path.
  2. Resolve the path to an absolute path before constructing the reader: Path(input_dir).resolve().
  3. If using a custom fs argument, check the path against that filesystem's root (e.g. 'bucket/prefix' without a leading slash for s3fs), not the local filesystem.
  4. Ensure the directory is mounted/copied into the container or VM if running in Docker/CI.

Example fix

// before
reader = SimpleDirectoryReader(input_dir="./data")

// after
from pathlib import Path
data_dir = Path("./data").resolve()
assert data_dir.is_dir(), f"missing dir: {data_dir}"
reader = SimpleDirectoryReader(input_dir=data_dir)
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path
input_dir = "./data"
assert Path(input_dir).is_dir(), f"Directory does not exist: {input_dir}"

Prevention

When it happens

Trigger: Constructing SimpleDirectoryReader(input_dir='./data') where './data' does not exist; passing a relative path while the process cwd differs from the assumed one; passing a path on a non-default fsspec filesystem (e.g. s3fs) where isdir() is False because the prefix/bucket is wrong or credentials lack access; passing a file path instead of a directory.

Common situations: Notebooks run from a different working directory; typos or trailing spaces in the path; Docker containers where the data volume was not mounted at the expected path; S3/GCS prefixes that do not end the way the user expects; paths from config files or CLI args that are wrong on a new machine.

Related errors


AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15). Data as JSON: /api/errors/ce9afb27eec5f6a2. Report an issue: GitHub.