Repository navigation
Description
Bug
The webvtt, markdown and asciidoc backends decode their input as plain utf-8, so a leading
UTF-8 BOM (U+FEFF) survives into the first line of the source.
For WebVTT this is a hard failure. The file body grammar in https://www.w3.org/TR/webvtt1 lists
"an optional U+FEFF BYTE ORDER MARK (BOM) character" before the WEBVTT string, but
WebVTTFile.verify_signature() requires the content to start with WEBVTT, so is_valid()
returns False and the conversion fails with "The document backend could not parse the input".
For Markdown and AsciiDoc it is silent. The first line becomes \ufeff# Title / \ufeff= Title,
which is no longer a heading, so the document title is demoted to body text and the BOM itself
ends up in the exported text. InputFormat.MD also covers .txt, .qmd and .rmd, which is
where BOM-prefixed files show up most often (PowerShell's Out-File -Encoding utf8 and Notepad's
"UTF-8 with BOM" both write one).
CSV had the same defect and was fixed in #4098 by decoding utf-8-sig. These three are the
remaining text backends where the BOM changes the result. The html backend is unaffected
(BeautifulSoup drops it) and latex is unaffected.
Steps to reproduce
import io
from docling.datamodel.base_models import DocumentStream
from docling.document_converter import DocumentConverter
BOM = "\ufeff"
SOURCES = {
"sample.vtt": "WEBVTT\n\n00:00:01.000 --> 00:00:05.000\nHello there\n",
"sample.md": "# Title\n\nSome body text.\n",
"sample.adoc": "= Document Title\n\nSome body text.\n",
}
converter = DocumentConverter()
for name, text in SOURCES.items():
for label, payload in (("no BOM", text), ("BOM ", BOM + text)):
stream = DocumentStream(name=name, stream=io.BytesIO(payload.encode()))
try:
doc = converter.convert(stream, raises_on_error=True).document
items = [(type(i).__name__, getattr(i, "text", "")) for i, _ in doc.iterate_items()]
print(f"{name:12} {label} {items}")
except Exception as e:
print(f"{name:12} {label} {type(e).__name__}: {e}")Output on main (2.123.1):
sample.vtt no BOM [('TextItem', 'Hello there')]
sample.vtt BOM ConversionError: Conversion failed for: sample.vtt with status: failure. Errors: The document backend could not parse the input.
sample.md no BOM [('TitleItem', 'Title'), ('TextItem', 'Some body text.')]
sample.md BOM [('TextItem', '\ufeff# Title'), ('TextItem', 'Some body text.')]
sample.adoc no BOM [('TitleItem', 'Document Title'), ('TextItem', 'Some body text.')]
sample.adoc BOM [('TextItem', '\ufeff= Document Title'), ('TextItem', 'Some body text.')]
Expected: the BOM row matches the no-BOM row in all three cases.
The same happens when converting a file path instead of a DocumentStream; each backend decodes
the two branches separately.
Docling version
Docling version: 2.123.1
Docling Core version: 2.92.0
Docling IBM Models version: 3.14.0
Docling Parse version: 7.16.0
Python: cpython-312 (3.12.14)
Platform: macOS-26.6.2-arm64-arm-64bit
Python version
Python 3.12.14
Activity
dosubot commentedon Aug 29, 2026
@aniketwaghh, confirmed — the code on
mainmatches your report exactly.WebVTTDocumentBackend.__init__decodes with plain"utf-8"[1], andWebVTTFile.verify_signature()in docling-core requires the content to start literally with"WEBVTT"[2]. A leading\ufeffmakescontent.startswith("WEBVTT")false, sois_valid()returnsFalseand conversion fails.AsciiDocBackend.__init__also decodes with plain"utf-8"on both branches [3], so a BOM survives intoself.lines[0]and demotes\ufeff= Titlefrom a heading to body text.MarkdownDocumentBackend.__init__does the same [4], producing\ufeff# Titleas body text instead of aTitleItem.Your read of #4098 is accurate: that PR switched
CsvDocumentBackendto decode with"utf-8-sig"on both theBytesIOandPathbranches [5], and its description explicitly scoped itself to CSV only, namingasciidoc_backend,boxnote_backend,webvtt_backend, andmd_backendas follow-up candidates using the same decode pattern [6].The fix would mirror #4098: swap
decode("utf-8")→decode("utf-8-sig")andencoding="utf-8"→encoding="utf-8-sig"inwebvtt_backend.py,asciidoc_backend.py,md_backend.py, and likelyboxnote_backend.py, for both the stream and file-path branches. For WebVTT specifically,verify_signatureandparseoperate onself.contentafter decoding [7], so stripping the BOM at decode time is sufficient — no change needed in docling-core'sverify_signatureitself.To reply, just mention @dosu.
Docs are dead. Just use Dosu.