diff --git a/libs/community/langchain_community/document_loaders/parsers/pdf.py b/libs/community/langchain_community/document_loaders/parsers/pdf.py index 46ad300be96..65a3e02f7c6 100644 --- a/libs/community/langchain_community/document_loaders/parsers/pdf.py +++ b/libs/community/langchain_community/document_loaders/parsers/pdf.py @@ -995,8 +995,11 @@ class PyMuPDFParser(BaseBlobParser): doc = pymupdf.open(file_path) else: doc = pymupdf.open(stream=file_path, filetype="pdf") + if doc.is_encrypted and self.password is None: + raise ValueError("Password is required to open encrypted PDFs.") if doc.is_encrypted: doc.authenticate(self.password) + doc_metadata = { "producer": "PyMuPDF", "creator": "PyMuPDF",