fix: reject Docling conversions that failed inside an HTTP 200 response (#30107)

Uploading a file that Docling declines or fails to convert either dies with `TypeError: argument of type 'NoneType' is not iterable`, or silently succeeds and stores the literal string `<No text content found>` as the document's text, which then gets indexed and handed to the model as if it were the file. Docling returns the conversion outcome inside the HTTP 200 body, so checking only the HTTP status made a refused conversion look identical to a successful one, and the `errors` array that says why in plain words was never read.

Failed and skipped conversions are now rejected with the messages Docling returned, so an unsupported format surfaces as "File format not allowed: example.dxf" and the traceback is gone. The markdown field is also read as nullable, because Docling returns JSON `null` for every content format it was not asked to produce, which any Docling Parameters setting `to_formats` without `md` will hit, and that null was what raised the TypeError.

Successful conversions with empty markdown keep the existing `<No text content found>` placeholder, matching what TikaLoader and the Mistral loader already do in the same package.

Fixes #29808
This commit is contained in:
Classic298
2026-09-17 17:39:35 -04:00
committed by GitHub
parent 58b36765a7
commit 0837f310be
+10 -1
View File
@@ -290,8 +290,17 @@ class DoclingLoader:
)
if r.ok:
result = r.json()
# Docling reports failed and skipped conversions inside HTTP 200 responses.
conversion_status = result.get('status')
if conversion_status in ['failure', 'skipped']:
error_details = (
'; '.join(filter(None, (error.get('error_message') for error in result.get('errors', []))))
or 'no error message provided'
)
raise Exception(f'Error calling Docling: conversion status {conversion_status} - {error_details}')
document_data = result.get('document', {})
md_content = document_data.get('md_content', '')
md_content = document_data.get('md_content') or ''
text = md_content or '<No text content found>'
metadata = {'Content-Type': self.mime_type} if self.mime_type else {}