run-llama/llama_index · error · ValueError

Must provide either `input_dir` or `input_files`.

Error message

Must provide either `input_dir` or `input_files`.

What it means

SimpleDirectoryReader requires exactly one input source: a directory (input_dir) or an explicit file list (input_files). The constructor raises ValueError('Must provide either `input_dir` or `input_files`.') when both are falsy, so an instance never exists without a source.

Source

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

        exclude: Optional[list] = None,
        exclude_hidden: bool = True,
        exclude_empty: bool = False,
        errors: str = "ignore",
        recursive: bool = False,
        encoding: str = "utf-8",
        filename_as_id: bool = False,
        required_exts: Optional[list[str]] = None,
        file_extractor: Optional[dict[str, BaseReader]] = None,
        num_files_limit: Optional[int] = None,
        file_metadata: Optional[Callable[[str], dict]] = None,
        raise_on_error: bool = False,
        fs: fsspec.AbstractFileSystem | None = None,
    ) -> None:
        """Initialize with parameters."""
        super().__init__()

        if not input_dir and not input_files:
            raise ValueError("Must provide either `input_dir` or `input_files`.")

        self.fs = fs or get_default_fs()
        self.errors = errors
        self.encoding = encoding

        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):

View on GitHub (pinned to afd0fef371)

Solutions

  1. Pass input_dir="./data" or input_files=["a.pdf", "b.txt"]
  2. Validate upstream config before constructing: raise a clear config error when neither is set
  3. Check for typos/renames in the keyword arguments you pass

Example fix

// before
input_dir = args.dir  # None when flag omitted
reader = SimpleDirectoryReader(input_dir=input_dir, input_files=args.files)  # both empty -> raises

// after
if not args.dir and not args.files:
    raise SystemExit("Provide --dir or --files")
reader = SimpleDirectoryReader(
    input_dir=args.dir,
    input_files=args.files or None,
)
Defensive patterns

Strategy: validation

Validate before calling

def make_reader(input_dir=None, input_files=None, **kw):
    if not input_dir and not input_files:
        raise ValueError("Reader config error: set input_dir or input_files")
    return SimpleDirectoryReader(
        input_dir=input_dir or None,
        input_files=input_files or None,
        **kw,
    )

Prevention

When it happens

Trigger: SimpleDirectoryReader() with no arguments, or with input_dir=None/input_files=[] when forwarding optional config (CLI flags, env vars, parsed YAML) that resolved to nothing.

Common situations: Config plumbing where a missing CLI arg becomes None and is passed through; typos like input_dirr=... leave both real parameters unset.

Related errors


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