{"record":{"id":"c883be5f2bae88b1","repo":"docling-project/docling","slug":"incompatible-file-format-self-input-format-was-p-c883be","errorCode":null,"errorMessage":"Incompatible file format {self.input_format} was passed to a PdfDocumentBackend. Valid format are {','.join(self.supported_formats())}.","messagePattern":"Incompatible file format (.+?) was passed to a PdfDocumentBackend\\. Valid format are (.+?)\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"docling/backend/pdf_backend.py","lineNumber":74,"sourceCode":"        pass\n\n\nclass PdfDocumentBackend(PaginatedDocumentBackend):\n    supports_random_page_access: ClassVar[bool] = True\n\n    def __init__(\n        self,\n        in_doc: InputDocument,\n        path_or_stream: Union[BytesIO, Path],\n        options: Optional[PdfBackendOptions] = None,\n    ):\n        if options is None:\n            options = PdfBackendOptions()\n        super().__init__(in_doc, path_or_stream, options)\n        self.options: PdfBackendOptions\n\n        if self.input_format not in self.supported_formats():\n            raise RuntimeError(\n                f\"Incompatible file format {self.input_format} was passed to a PdfDocumentBackend. Valid format are {','.join(self.supported_formats())}.\"\n            )\n\n    @abstractmethod\n    def load_page(self, page_no: int) -> PdfPageBackend:\n        pass\n\n    @abstractmethod\n    def page_count(self) -> int:\n        pass\n\n    def iter_pages(self) -> Iterator[PdfPageBackend]:\n        for page_index in range(self.page_count()):\n            yield self.load_page(page_index)\n\n    def get_document_outline(self) -> list[_PdfOutlineItem]:\n        \"\"\"Return the PDF bookmark / table-of-contents outline.\n","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/docling-project/docling/blob/61d76f1ff3f8428065465889f7b4577da7df704c/docling/backend/pdf_backend.py#L56-L92","documentation":"RuntimeError raised by PdfDocumentBackend.__init__ when the InputDocument's format is not in the concrete backend's supported_formats(). It is an internal dispatch assertion: e.g. a PdfDocumentBackend subclass receiving InputFormat.AUDIO or DOCX means format routing is misconfigured.","triggerScenarios":"Constructing any PdfDocumentBackend subclass (pypdfium2, docling-parse, etc.) with an InputDocument whose input_format is not PDF/Image — typically when user code instantiates a backend manually instead of via the format-based backend factory.","commonSituations":"Custom pipelines that hard-code a PDF backend while feeding mixed-format InputDocuments; tests that reuse one fixture across formats; forks that add formats without updating the factory.","solutions":["Use the standard backend-selection path (DocumentConverter / _get_backend) instead of instantiating PdfDocumentBackend subclasses directly.","Filter inputs by InputFormat.PDF before routing to a PDF backend.","If writing a custom backend, verify supported_formats() overlaps the dispatched format."],"exampleFix":"# before\nbackend = PyPdfiumDocumentBackend(in_doc, path)  # RuntimeError for non-PDF input\n\n# after\nfrom docling.datamodel.base_models import InputFormat\nif in_doc.format == InputFormat.PDF:\n    backend = PyPdfiumDocumentBackend(in_doc, path)","handlingStrategy":"type-guard","validationCode":"from docling.datamodel.base_models import InputFormat\nif in_doc.format not in backend.supported_formats():\n    raise ValueError(f'{in_doc.format} unsupported by {type(backend).__name__}')","typeGuard":"def accepts(backend_cls, in_doc) -> bool:\n    return in_doc.format in backend_cls.supported_formats()","tryCatchPattern":"if in_doc.format not in type(backend).supported_formats():\n    backend = select_backend_for(in_doc)  # route to correct backend\nresult = backend.convert()","preventionTips":["Use DocumentConverter's built-in backend factory rather than manual construction","Filter inputs by InputFormat before dispatch","Add tests covering mixed-format routing"],"tags":["pdf","format-dispatch","internal-error"],"backgroundTag":null,"analyzedSha":"61d76f1ff3f8428065465889f7b4577da7df704c","analyzedAt":"2026-08-14T23:53:18.727Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}