{"record":{"id":"c7e1a1b5b1e41388","repo":"crewAIInc/crewAI","slug":"error-loading-docx-file-e-s","errorCode":null,"errorMessage":"Error loading DOCX file: {e!s}","messagePattern":"Error loading DOCX file: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/rag/loaders/docx_loader.py","lineNumber":85,"sourceCode":"                    text_parts.append(paragraph.text)  # noqa: PERF401\n\n            content = \"\\n\".join(text_parts)\n\n            metadata = {\n                \"format\": \"docx\",\n                \"paragraphs\": len(doc.paragraphs),\n                \"tables\": len(doc.tables),\n            }\n\n            return LoaderResult(\n                content=content,\n                source=source_ref,\n                metadata=metadata,\n                doc_id=self.generate_doc_id(source_ref=source_ref, content=content),\n            )\n\n        except Exception as e:\n            raise ValueError(f\"Error loading DOCX file: {e!s}\") from e\n","sourceCodeStart":67,"sourceCodeEnd":86,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/rag/loaders/docx_loader.py#L67-L86","documentation":"Raised by DOCXLoader._load_from_file() when opening or parsing the DOCX fails — e.g. python-docx raises PackageNotFoundError for a non-OOXML file, or the file is corrupt/encrypted. The broad except around DocxDocument(file_path) and the paragraph/table iteration re-raises as ValueError('Error loading DOCX file: ...') with the cause chained.","triggerScenarios":"Loading a file with a .docx extension that is actually the old binary .doc format, a .docx that is a renamed ZIP bomb or truncated download, an encrypted/password-protected document, or an HTML error page saved with a .docx suffix by the URL download path.","commonSituations":"Downloads interrupted leaving truncated files; users renaming .doc to .docx; Word documents saved with password protection; SharePoint/Google Docs export glitches producing non-standard packages; temp files partially written before the process died.","solutions":["Validate the file is a real OOXML package: check the ZIP magic bytes (PK\\x03\\x04) and that word/document.xml exists inside.","Re-download or re-export the document; verify it opens in Word/LibreOffice.","If the document is password-protected, decrypt it (e.g. with msoffcrypto) to a new file before loading.","Delete and re-create partial temp files rather than retrying on the same bytes."],"exampleFix":"# before\nresult = DOCXLoader().load(SourceContent('spec.docx'))  # actually old .doc renamed\n\n# after\nimport zipfile\nif not zipfile.is_zipfile('spec.docx') or 'word/document.xml' not in zipfile.ZipFile('spec.docx').namelist():\n    raise ValueError('not a valid OOXML .docx — convert it first')\nresult = DOCXLoader().load(SourceContent('spec.docx'))","handlingStrategy":"try-catch","validationCode":"import zipfile\\n\\ndef is_valid_ooxml(path: str) -> bool:\\n    try:\\n        with zipfile.ZipFile(path) as z:\\n            return 'word/document.xml' in z.namelist()\\n    except zipfile.BadZipFile:\\n        return False","typeGuard":null,"tryCatchPattern":"try:\\n    result = DOCXLoader().load(source)\\nexcept ValueError as e:\\n    if 'Error loading DOCX' in str(e):\\n        quarantine_file(source.source)  # move aside, log, continue batch\\n    else:\\n        raise","preventionTips":["Verify ZIP magic and word/document.xml before loading.","Convert legacy .doc files to .docx upstream.","Decrypt password-protected documents before ingestion."],"tags":["docx","parsing","corruption","loader"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}