Doclingdocling 2.127.0 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
26 small wins to finish your pathNext lesson

What comes back from convert

Lesson 2 reached straight through .document and threw the rest away. The rest is how you find out whether the conversion went well.

convert returns a ConversionResult. The document is one field on it. The others say what was read, how it went, and what went wrong.

Example
from docling.document_converter import DocumentConverter

result = DocumentConverter().convert("refunds.html")
print(result.status)
print(result.errors)

status is one of four values: success, partial success, skipped, failure. errors is a list, empty here, that fills with one entry per thing that went wrong. Lesson 18 converts a folder and reads both of these for every file in it.

What was read

Example
print(result.input.file.name)
print(result.input.format)
print(result.input.page_count)

result.input describes the file that went in, including the format Docling decided it was. The page count is zero because HTML has no pages; only the formats that are laid out on paper fill it in, and lesson 14 reads it for the PDF.

The document knows where it came from

Example
document = result.document
print(document.name)
print(document.origin.filename, "|", document.origin.mimetype)

The origin travels with the document, which matters more than it looks. In lesson 29 a chunk of text taken from this document still knows it came from refunds.html, and that is what makes a citation possible.

A failed conversion still returns a result. When you convert one file at a time Docling raises instead, which is usually what you want. When you convert many, lesson 18 shows the switch that turns raising back into a status you can read.
Try it yourself
  • Print result.input.format.value for all three text files.
  • Convert shipping.md and compare document.origin.mimetype with the HTML one.
  • Print result.status.name and note it is a plain string you can put in a report.

Slow is fine. Stopping is the only problem.