Docling OCRIndependent Docling guide

Troubleshooting

Docling Troubleshooting: Production Pitfalls & Hard-Won Fixes

Beyond basic configuration errors, running Docling in automated pipelines reveals subtle engineering challenges: silent fallbacks from GPU to CPU, 72 DPI layout blindspots that miss dense tables, PDF text-span cell clumping, and multi-stage queue stalls. Here is the architectural guide to diagnose and resolve each one.

Updated 2026-11-02 · 6 min read

The short version

  • –PyMuPDF 2.0+ transitively installs CPU onnxruntime via pymupdf-layout, silently shadowing onnxruntime-gpu and forcing OCR onto CPU without raising an error.
  • –Bare onnxruntime-gpu lacks CUDA runtime libraries; install onnxruntime-gpu[cuda,cudnn] and configure LD_LIBRARY_PATH for PyTorch bundled NVIDIA libraries.
  • –Docling layout detection defaults to 72 DPI rendering (scale=1.0). Dense, small-font tables frequently register 0 tables unless re-checked with an increased layout rasterization scale.
  • –When a digital PDF emits an entire row of values as a single text span, do_cell_matching=True packs all data into one column. Disabling cell matching restores word-level geometric boundaries.
  • –StandardPdfPipeline defaults to a 0.5s batch polling interval, injecting latency into single-document requests. Lowering it to 20ms drastically cuts response times.
  • –If TableFormer predicts 0 cells on a detected table region, Docling drops the text from both markdown and tables. Always implement a bounding-box text fallback to prevent silent data loss.

The production failure matrix

Most introductory guides cover basic missing dependencies or OOM errors. In production pipelines processing diverse document formats, failures are often silent: throughput degrades without raising exceptions, or columns collapse due to PDF stream anomalies.

Symptom / FailureRoot CauseBattle-Tested Fix
OCR runs significantly slower on GPU containerPyMuPDF 2.0+ pulls CPU onnxruntime; bare ORT-GPU missing CUDA libsPin pymupdf>=1.24.0,<2.0; install onnxruntime-gpu[cuda,cudnn] and set LD_LIBRARY_PATH
GPU container uses 0 CUDA devices after snapshotModel prewarming during container build freezes CUDA device probeSet DOCLING_PREWARM=0 during build; initialize models in runtime worker hooks
Dense document detects 0 tablesLayout object detection defaults to 72 DPI (scale=1.0), blurring fine bordersRetry 0-table pages with an increased layout resolution scale (e.g. 2.0x / 144 DPI)
All values in a row crammed into a single columnPDF text stream emits row as one text span; do_cell_matching dumps span into single cellSet table_structure_options.do_cell_matching = False to match by geometric word coordinates
Text vanishes from both Markdown and tablesLayout detects table box, but TableFormer extracts 0 rows/cols; Docling discards regionIntercept 0-cell tables and clip raw text layer via PDF coordinate rectangle (fitz.Rect)
Multi-page continuation tables parsed as body textContinuation pages lack borders/headers; layout model fails to recognize table geometryProject column x-coordinates from Page 1 across continuation pages to reconstruct tabular rows
Single-document API has multi-second latencybatch_polling_interval_seconds defaults to 0.5s across 3 queue stagesSet batch_polling_interval_seconds = 0.02 (20ms) and tune batch sizes
CPU thrashing while GPU idlesThread oversubscription (OMP/MKL/Docling threads exceed container CPU quota)Align OMP_NUM_THREADS, MKL_NUM_THREADS, and DOCLING_NUM_THREADS with actual CPU cores
Bounding boxes misaligned on web/canvas overlaysDocling and PDF coordinate origin is bottom-left; web view is top-leftNormalize coordinates: top = page_height - bottom; bottom = page_height - top
Multi-column table collapses into fewer columnsUsing pypdfium2 backend merges text spans across column rulesSwitch to native docling-parse backend to preserve fine column segmentation

1. Silent GPU degradation & the CUDA / ONNX Runtime dependency trap

A deceptive issue in document AI pipelines is when GPU acceleration quietly deactivates without throwing an error. The process logs success, but conversion times increase significantly because inference has silently dropped to CPU.

This silent downgrade typically stems from library conflicts:

1

PyMuPDF 2.0+ transitively bundled CPU ONNX Runtime

PyMuPDF 2.0 introduces pymupdf-layout, which lists onnxruntime (CPU) as a direct dependency. When pip installs PyMuPDF 2.0+, it downloads the CPU wheel of ONNX Runtime, which overwrites the onnxruntime module namespace of onnxruntime-gpu. RapidOCR and layout models then detect no CUDA Execution Provider and fall back to CPU. The fix is pinning: pip install "pymupdf>=1.24.0,<2.0".

2

Bare onnxruntime-gpu missing CUDA shared libraries

Installing a bare pip install onnxruntime-gpu provides provider binaries that dynamically link against CUDA and cuDNN libraries (such as libcurand.so.10). If these are not present in the system library path, dynamic loading fails silently. Always install with explicit extras: pip install "onnxruntime-gpu[cuda,cudnn]>=1.27".

3

Torch wheel bundled NVIDIA dynamic library paths

PyTorch wheels bundle their own CUDA shared libraries inside site-packages/nvidia/*/lib (CUDA 12) or site-packages/nvidia/cu13/lib (CUDA 13). Because ONNX Runtime uses system-level dynamic linking, it will not discover these libraries unless LD_LIBRARY_PATH explicitly includes them.

4

Explicit AcceleratorDevice over AUTO

Avoid relying on AcceleratorDevice.AUTO in production services. If CUDA initialization suffers any issue, AUTO quietly defaults to CPU. Pass AcceleratorDevice.CUDA explicitly so failures raise immediately rather than degrading performance unnoticed.

Dockerfile / Container Environment Setup
# Ensure PyMuPDF does not pull CPU onnxruntime
pip install "pymupdf>=1.24.0,<2.0"

# Install GPU ONNX Runtime with full CUDA and cuDNN extras
pip install "onnxruntime-gpu[cuda,cudnn]>=1.27" "docling==2.142.1"

# Configure LD_LIBRARY_PATH to include PyTorch's bundled CUDA libraries
ENV LD_LIBRARY_PATH="/usr/local/nvidia/lib:/usr/local/nvidia/lib64:/usr/local/cuda/lib64:/usr/local/lib/python3.11/site-packages/nvidia/cudnn/lib:/usr/local/lib/python3.11/site-packages/nvidia/cublas/lib:/usr/local/lib/python3.11/site-packages/nvidia/curand/lib:/usr/local/lib/python3.11/site-packages/nvidia/cusolver/lib:/usr/local/lib/python3.11/site-packages/nvidia/cu13/lib"

# Set thread concurrency to match exact CPU allocation to prevent thread fighting
ENV OMP_NUM_THREADS="4"
ENV MKL_NUM_THREADS="4"
ENV DOCLING_NUM_THREADS="4"

2. High-density tables detecting 0 tables (The 72 DPI layout blindspot)

Docling may produce accurate text extraction on standard documents, but return zero tables on dense invoices, financial tables, and receipts with small typography, tight row spacing, or delicate grid lines, dumping tabular line items into plain paragraphs.

The underlying cause is that Docling's layout object detection model defaults to rasterizing pages at scale=1.0 (standard 72 DPI). For documents with small typography and thin dividing rules, 72 DPI merges adjacent characters and dividing lines into indistinct pixel blocks. The layout model fails to identify a table boundary and predicts 0 tables. TableFormer is never invoked.

A practical architectural solution is a conditional two-pass check: if the first pass yields 0 tables on a PDF page that contains tabular content or grid structures, re-run layout detection with an increased scale (such as 2.0x / 144 DPI). Because Docling normalizes bounding boxes against page_width / image.width, output coordinates remain accurate in point space.

Python — High-Resolution Layout Retry Pattern
from docling.document_converter import DocumentConverter, PdfFormatOption
from docling.datamodel.base_models import InputFormat
from docling.datamodel.pipeline_options import PdfPipelineOptions

def convert_with_hires_fallback(pdf_path: str):
    pipeline_options = PdfPipelineOptions()
    pipeline_options.do_table_structure = True

    converter = DocumentConverter(
        format_options={InputFormat.PDF: PdfFormatOption(pipeline_options=pipeline_options)}
    )
    result = converter.convert(pdf_path)

    # If zero tables were detected on a document suspected to contain tables:
    if not getattr(result.document, "tables", None):
        pipeline_options.images_scale = 2.0
        hires_converter = DocumentConverter(
            format_options={InputFormat.PDF: PdfFormatOption(pipeline_options=pipeline_options)}
        )
        hires_result = hires_converter.convert(pdf_path)
        if getattr(hires_result.document, "tables", None):
            return hires_result

    return result

3. Cell matching clumping entire rows into one column

When converting digital PDFs, tables may sometimes appear where several columns are blank, while one column contains all the values from the row concatenated into a single cell.

This happens because PDF rendering engines often emit an entire line of data as a single text span in the underlying stream. By default, Docling's table pipeline enables table_structure_options.do_cell_matching = True, which assigns raw PDF text spans into TableFormer's predicted grid cells. Because the PDF presents the line as a single atomic text span, cell matching places the entire string into one cell.

Setting do_cell_matching = False disables whole-span assignment. Docling will instead project individual word-level and token-level geometric bounding boxes into the grid, properly distributing data across their respective columns.

Python — Disabling span-level cell matching on dense tables
from docling.datamodel.pipeline_options import PdfPipelineOptions, TableFormerMode

pipeline_options = PdfPipelineOptions()
pipeline_options.do_table_structure = True
pipeline_options.table_structure_options.mode = TableFormerMode.ACCURATE

# Disable whole-span cell matching to force word-level geometric assignment:
pipeline_options.table_structure_options.do_cell_matching = False

4. The vanishing table trap (Recovering 0-cell drops)

In documents containing complex layouts or atypical table structures, Docling's layout model may mark a region as a table bounding box, but TableFormer subsequently predicts 0 rows and 0 columns.

Because the region was classified as a table, Docling omits it from normal body paragraphs. And because TableFormer returned 0 cells, it is also omitted from exported tables. The text is discarded from both Markdown and spreadsheet outputs.

To prevent data loss in automated processing, inspect all extracted tables. For any table where num_rows == 0 or cells are empty, use PyMuPDF or pdfplumber to extract text directly from the table's bounding box (clip=fitz.Rect(x0, y0, x1, y1)) and retain it as unparsed tabular content.

Python — Bounding-Box Fallback for Dropped Tables
import fitz

def recover_dropped_tables(conv_result, pdf_bytes: bytes) -> list[dict]:
    empty_regions = []
    for table in conv_result.document.tables:
        cells = getattr(table.data, "table_cells", None) or getattr(table, "cells", None)
        nrows = getattr(table.data, "num_rows", 0)
        ncols = getattr(table.data, "num_cols", 0)
        
        # Table region detected, but 0 cells extracted by TableFormer
        if not cells or nrows == 0 or ncols == 0:
            prov = getattr(table, "prov", None)
            if prov and prov[0].bbox:
                empty_regions.append((prov[0].page_no, prov[0].bbox))
                
    if not empty_regions:
        return []
        
    doc = fitz.open(stream=pdf_bytes, filetype="pdf")
    recovered = []
    for page_no, bbox in empty_regions:
        page = doc[page_no - 1]
        # Invert PDF bottom-left coordinates to PyMuPDF top-left coordinates
        rect = fitz.Rect(bbox.l, page.rect.height - bbox.t, bbox.r, page.rect.height - bbox.b)
        raw_text = page.get_text("text", clip=rect).strip()
        if raw_text:
            recovered.append({"page": page_no, "text": raw_text})
    doc.close()
    return recovered

5. Pipeline queue latency in StandardPdfPipeline

In Docling 2.x, StandardPdfPipeline implements a multi-stage producer-consumer architecture connecting OCR, layout detection, and table structure stages via bounded queues. While well-suited for high-throughput batch workloads, its default queue settings introduce delay on single-document interactive APIs:

By default, batch_polling_interval_seconds is set to 0.5s (500ms). Each stage waits up to half a second to accumulate a full batch. For short PDFs traversing 3 stages in mini-batches, the request can spend seconds in queue waiting.

For interactive web or API services, reduce the polling interval to 20ms and increase batch sizes so short documents process in a single unified sweep.

Python — Eliminating queue latency for real-time APIs
pipeline_options = PdfPipelineOptions()

# Cut queue polling interval from 500ms down to 20ms
if hasattr(pipeline_options, "batch_polling_interval_seconds"):
    pipeline_options.batch_polling_interval_seconds = 0.02

# Ensure single-document pages are processed in a single batch pass
if hasattr(pipeline_options, "ocr_batch_size"):
    pipeline_options.ocr_batch_size = 16
if hasattr(pipeline_options, "layout_batch_size"):
    pipeline_options.layout_batch_size = 16
if hasattr(pipeline_options, "table_batch_size"):
    pipeline_options.table_batch_size = 16

6. Thread oversubscription and GPU starvation

When deploying Docling inside containers, a common performance mistake is mismatching CPU core quotas with inference thread pools. Layout postprocessing, PDF parsing, and cell matching run primarily on CPU, while model forward passes run on GPU.

If a container is allocated 2 CPU cores, but environment variables like OMP_NUM_THREADS, MKL_NUM_THREADS, or DOCLING_NUM_THREADS default to 4 or 8, the operating system spends excessive time context switching and thrashing CPU caches. The GPU sits idle waiting for the CPU postprocessing stages to deliver batches.

Always set thread concurrency strictly equal to your provisioned physical CPU cores.

7. Multi-page borderless continuation tables

When a long table spans across multiple pages, Page 1 typically has complete borders and column headers, which Docling recognizes cleanly. However, continuation pages often have no borders and no repeated headers.

Docling's layout model frequently misclassifies continuation pages as standard paragraphs because they lack visual table cues. The table extraction ends prematurely on Page 1.

A reliable approach is geometric column projection: capture the column x-coordinates (x_min and x_max) from the recognized table on Page 1, and project those column boundaries across continuation pages to group words into rows and columns geometrically.

8. Coordinate system normalization: bottom-left vs top-left

Docling's native bounding boxes follow the standard PDF coordinate system, where the coordinate origin (0, 0) is located at the bottom-left of the page. In contrast, web browsers, PDF.js canvas viewers, and frontend DOM coordinates place (0, 0) at the top-left.

If you display cell provenance bounding boxes directly on a web PDF viewer without inverting the Y-axis, highlights will appear vertically inverted.

The conversion formula is:

  • top_web = page_height - bbox.top_pdf (where bbox.top_pdf is the upper Y value)
  • bottom_web = page_height - bbox.bottom_pdf (where bbox.bottom_pdf is the lower Y value)
  • Always record the coordinate origin in your serialized response (e.g. coordOrigin: "topleft") so downstream clients never second-guess orientation.

9. Verbatim fidelity vs post-processing hallucination

A risky pattern in document pipelines is piping Docling output through an LLM to "clean up" the tables. While tempting, this introduces unpreventable hallucinations on sensitive documents:

LLMs frequently round floating-point numbers, rewrite negative number formats, strip leading zeroes from alphanumeric identifiers, and alter unfamiliar codes or abbreviations.

Maintain strict verbatim fidelity: keep Docling's extracted strings untouched. Run deterministic validation checks in code, and highlight discrepancies for human review rather than allowing an AI model to silently alter raw data.

10. Running Docling inside your network

To run upstream Docling inside a private network, download the required model and OCR assets before deployment. Review the network access and storage settings of the pipeline you choose.

The self-hosted Docling guide covers local setup and the options to check before exposing a Docling Serve endpoint.

Frequently asked questions

Why does Docling run slowly on GPU despite CUDA being available?+

Check for CPU onnxruntime package collision. PyMuPDF 2.0+ transitively installs CPU onnxruntime via pymupdf-layout, which silently overwrites onnxruntime-gpu. RapidOCR and layout models then fail to detect a CUDA Execution Provider and fall back to CPU without raising an error. Pin "pymupdf>=1.24.0,<2.0", install "onnxruntime-gpu[cuda,cudnn]", and ensure LD_LIBRARY_PATH includes CUDA shared libraries.

Why does Docling detect 0 tables on my invoice or dense PDF?+

Docling layout object detection defaults to rasterizing pages at 72 DPI (scale=1.0). Dense documents like invoices, receipts, and financial statements with small fonts and hairline borders blur together at 72 DPI, causing the layout model to miss the table boundary completely. Re-run layout detection with an increased resolution scale (e.g. images_scale=2.0 / 144 DPI).

Why are all values in a row bunched into one column?+

The PDF content stream emitted the row as a single text object, and do_cell_matching=True assigned the entire object to one cell. Set pipeline_options.table_structure_options.do_cell_matching = False to force geometric word-level assignment.

Why did text disappear from both Markdown and table exports?+

The layout model classified a region as a table, but TableFormer extracted 0 cells. Because it was marked as a table, Docling skipped body text extraction. Add a fallback to extract text from the bounding box using PyMuPDF clip.

How do I reduce Docling API latency for single-page documents?+

Lower pipeline_options.batch_polling_interval_seconds from 0.5s down to 0.02s (20ms). The default 0.5s queue delay causes multi-stage pipelines to spend seconds waiting for batches on small requests.

How do I convert Docling bounding boxes to web preview coordinates?+

PDF coordinates use a bottom-left origin, while web viewers use top-left. Convert with: top = page_height - pdf_top; bottom = page_height - pdf_bottom.

Try it online

Run the same pipeline in the browser — no install, no uploads stored.

Try it in the browser

Keep reading