Skip to content

IndexError: list index out of range in msword_backend.py when processing DOCX files with empty paragraph runs #2367

Description

@hlra

Summary

Docling throws an IndexError: list index out of range when processing certain DOCX files that contain paragraphs with empty runs collections.

Error Details

Root Cause

In msword_backend.py at line 395, the code attempts to access c.runs[0] without checking if the runs list is empty:

When a paragraph contains no runs (i.e., c.runs is an empty list), this results in an IndexError.

Expected Behavior

Docling should gracefully handle DOCX files with paragraphs that have empty runs collections, either by:

  • Skipping empty paragraphs
  • Using a default format when no runs are available
  • Providing a more descriptive error message

Actual Behavior

The parsing fails completely with an IndexError, preventing the document from being processed.

Minimal Reproduction

This occurs with DOCX files that contain paragraphs with no text runs. While I cannot share the specific file due to confidentiality.

Environment

Docling version: 2.36.1
Python version: 3.11
Platform: Databricks runtime

Proposed Fix

Add a bounds check before accessing c.runs[0]:

Impact

This affects users processing DOCX files with certain structural patterns, causing complete parsing failure rather than graceful degradation.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingdocxissue related to docx backendgood first issueIssues and pull requests for new contributors

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions