assafelovic/gpt-researcher · error · ValueError

🤷 Failed to load any documents!

Error message

🤷 Failed to load any documents!

What it means

After walking local paths and loading files, if zero documents were successfully produced (empty dir, unsupported extensions, or all _load_document calls failed), load raises this ValueError.

Source

Thrown at gpt_researcher/document/document.py:60

        # for root, dirs, files in os.walk(self.path):
        #     for file in files:
        #         file_path = os.path.join(root, file)
        #         file_name, file_extension_with_dot = os.path.splitext(file_path)
        #         file_extension = file_extension_with_dot.strip(".")
        #         tasks.append(self._load_document(file_path, file_extension))

        docs = []
        for pages in await asyncio.gather(*tasks):
            for page in pages:
                if page.page_content:
                    docs.append({
                        "raw_content": page.page_content,
                        "url": os.path.basename(page.metadata['source'])
                    })
                    
        if not docs:
            raise ValueError("🤷 Failed to load any documents!")

        return docs

    async def _load_document(self, file_path: str, file_extension: str) -> list:
        ret_data = []
        try:
            loader_dict = {
                "pdf": PyMuPDFLoader(file_path),
"epub": UnstructuredEPubLoader(file_path),
                "txt": TextLoader(file_path),
                "doc": UnstructuredWordDocumentLoader(file_path),
                "docx": UnstructuredWordDocumentLoader(file_path),
                "pptx": UnstructuredPowerPointLoader(file_path),
                "csv": UnstructuredCSVLoader(file_path, mode="elements"),
                "xls": UnstructuredExcelLoader(file_path, mode="elements"),
                "xlsx": UnstructuredExcelLoader(file_path, mode="elements"),
                "md": UnstructuredMarkdownLoader(file_path),
                "html": BSHTMLLoader(file_path),

View on GitHub (pinned to 6f998577d5)

Solutions

  1. Verify the directory contains supported file types (pdf, txt, md, docx, html, ...)
  2. Check the path exists and is the intended one; print os.listdir first
  3. Look at earlier per-file warnings—files may be failing individually

Example fix

# before
loader = DocumentLoader('./uploads')
# after
import os
p = './uploads'
assert os.path.isdir(p) and any(f.endswith(('.pdf','.txt','.md')) for f in os.listdir(p))
loader = DocumentLoader(p)
Defensive patterns

Strategy: validation

Validate before calling

import os
EXTS = {'.pdf','.txt','.md','.docx','.html','.csv'}
files = [f for f in os.listdir(path) if os.path.splitext(f)[1].lower() in EXTS]
assert files, f"no loadable documents in {path}"

Type guard

def has_loadable_docs(path: str) -> bool:
    return any(os.path.splitext(f)[1].lower in {'.pdf','.txt','.md','.docx'} for f in os.listdir(path))

Try / catch

try:
    docs = loader.load()
except ValueError as e:
    if "Failed to load any documents" in str(e):
        docs = []  # treat as empty corpus, degrade gracefully
    else: raise

Prevention

When it happens

Trigger: Pointing DocumentLoader at an empty directory; a dir of .xyz files with no matching loader; all files failing to parse so docs stays empty.

Common situations: Wrong DOC_PATH; documents filtered out by extension; corrupt files silently skipped per-file.

Related errors


AI-assisted analysis of assafelovic/gpt-researcher@6f998577d5 (2026-08-28). Data as JSON: /api/errors/65ab5f20c4e9088e. Report an issue: GitHub.