From b17017696c780a9c71dc9cbf0c271d37ab9409e5 Mon Sep 17 00:00:00 2001 From: keenborder786 <21110290@lums.edu.pk> Date: Sun, 27 Apr 2025 18:24:10 +0500 Subject: [PATCH] [fix]: Raise Value Error when no password is provided --- .../langchain_community/document_loaders/parsers/pdf.py | 3 +++ 1 file changed, 3 insertions(+) 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",