The files Docling will not read
Lesson 18's bad file was refused for the right reason. Refusing files on purpose is a separate and useful thing.
from docling.document_converter import DocumentConverter
from docling.exceptions import ConversionError
try:
DocumentConverter().convert("notes.xyz")
except ConversionError as refused:
print(refused)File format not allowed, and the status inside is skipped rather than failure. Docling draws that line carefully: skipped means it would not try, failure means it tried and could not.
Refusing on purpose
A converter can be built to accept only some formats. Anything else is skipped with the same message, even though Docling knows perfectly well how to read it.
from docling.datamodel.base_models import InputFormat
only_text = DocumentConverter(allowed_formats=[InputFormat.MD, InputFormat.HTML])
print(only_text.convert("shipping.md").status.name)
try:
only_text.convert("returns.pdf")
except ConversionError as refused:
print(refused)Two good reasons to do this. A service that should never spend two minutes on a PDF can refuse them at the door, and a pipeline that expects Word files can fail loudly when someone drops in a spreadsheet instead of silently converting it.
The thirty-three
from docling.datamodel.base_models import InputFormat
names = sorted(fmt.value for fmt in InputFormat)
print(len(names))
print(names[:10])
print(names[-8:])Office documents, images, audio, video, email, EPUB and several XML schemas. The ones this course uses are four of them. A format being on the list does not mean it needs no extra install: audio and video need the speech recognition extra, and the older Office formats need LibreOffice on the machine.
The extension is the guess
Docling decides the format from the file name first and sniffs the contents second. That is why orders.txt and orders.csv holding identical bytes are read differently, and why the stream in lesson 20 has to be given a name.
raises_on_error=False a skipped file produces a result whose document is empty. Indexing it adds nothing and hides the problem.- Build a converter allowing only
InputFormat.PDFand run it over all four files. - Rename
refunds.htmltorefunds.txtand see which backend reads it. - Print
result.statusfor a.mdfile that does not exist, and compare it with the skipped one.
This is what real progress feels like.