{"record":{"id":"3434087008d535fe","repo":"crewAIInc/crewAI","slug":"pdf-file-not-found-file-path","errorCode":null,"errorMessage":"PDF file not found: {file_path}","messagePattern":"PDF file not found: (.+?)","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/rag/loaders/pdf_loader.py","lineNumber":112,"sourceCode":"            source_name = Path(urlparse(file_path).path).name or \"downloaded.pdf\"\n        else:\n            source_name = Path(file_path).name\n\n        text_content: list[str] = []\n        metadata: dict[str, Any] = {\n            \"source\": file_path,\n            \"file_name\": source_name,\n            \"file_type\": \"pdf\",\n        }\n\n        try:\n            if is_url:\n                doc = pymupdf.open(\n                    stream=self._fetch_from_url(file_path, kwargs), filetype=\"pdf\"\n                )\n            else:\n                if not os.path.isfile(file_path):\n                    raise FileNotFoundError(f\"PDF file not found: {file_path}\")\n                doc = pymupdf.open(file_path)\n\n            # Closed in a finally so a failure mid-extraction still releases the\n            # document handle.\n            try:\n                metadata[\"num_pages\"] = len(doc)\n\n                for page_num, page in enumerate(doc, 1):\n                    page_text = page.get_text()\n                    if page_text.strip():\n                        text_content.append(f\"Page {page_num}:\\n{page_text}\")\n            finally:\n                doc.close()\n        except FileNotFoundError:\n            raise\n        except Exception as e:\n            raise ValueError(f\"Error reading PDF from {file_path}: {e!s}\") from e\n","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/rag/loaders/pdf_loader.py#L94-L130","documentation":"Raised by PDFLoader.load() when a local (non-URL) source path is not an existing regular file — os.path.isfile fails. This is the local-file counterpart of the download error: before pymupdf opens the path, the loader verifies it exists; directories, dangling symlinks, and missing files all fail here with FileNotFoundError.","triggerScenarios":"PDFLoader().load(SourceContent('/data/missing.pdf')) where the file was never created, was deleted, lives in an unmounted volume, or the relative path resolves against the wrong cwd; also when a directory path is passed instead of a .pdf file.","commonSituations":"Docker deployments without the volume mounted at the expected path; notebooks where cwd differs from the project root; race conditions where the PDF is still being written/downloaded when load is called; typos or unexpanded ~ in configured paths.","solutions":["Check existence first: Path(src).expanduser().resolve().is_file() and fail with your own context.","Use absolute paths anchored to a known base instead of cwd-relative strings.","If the file is produced asynchronously, wait for a completion marker (e.g. .part suffix removed) before loading."],"exampleFix":"# before\nresult = PDFLoader().load(SourceContent('downloads/report.pdf'))  # cwd mismatch\n\n# after\nfrom pathlib import Path\npdf = Path('downloads/report.pdf').resolve()\nassert pdf.is_file(), f'missing PDF: {pdf}'\nresult = PDFLoader().load(SourceContent(str(pdf)))","handlingStrategy":"validation","validationCode":"from pathlib import Path\\n\\ndef assert_pdf_file(path: str) -> None:\\n    p = Path(path).expanduser().resolve()\\n    if not p.is_file():\\n        raise FileNotFoundError(f'PDF file not found: {p}')","typeGuard":"from pathlib import Path\\n\\ndef is_pdf_file(s: str) -> bool:\\n    return s.startswith(('http://', 'https://')) or (Path(s).expanduser().is_file() and s.lower().endswith('.pdf'))","tryCatchPattern":"try:\\n    result = PDFLoader().load(source)\\nexcept FileNotFoundError:\\n    logger.warning('missing PDF skipped: %s', source.source)\\n    result = None","preventionTips":["Anchor PDF paths to absolute locations resolved from config.","Verify Docker volume mounts before batch ingestion.","Only load files after their writer signals completion (no .part suffix)."],"tags":["pdf","filesystem","validation","loader"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}