Skip to content

DOCXToDocument drops the text of a table nested inside a table cell #13905

In review

Description

@astroknot-sheep

Describe the bug
When a DOCX table has another table inside one of its cells, DOCXToDocument silently drops the nested table's text. _cell_text only reads cell.paragraphs, which are the direct paragraphs of the cell, so a w:tbl inside the cell is never reached. This happens with both table_format="csv" and "markdown". Nested tables are quite common in Word forms, invoices and CV templates.

To Reproduce

import io, docx
from haystack.components.converters import DOCXToDocument
from haystack.dataclasses import ByteStream

d = docx.Document()
outer = d.add_table(rows=1, cols=2)
outer.cell(0, 0).text = "outer"
outer.cell(0, 1).add_table(rows=1, cols=1).cell(0, 0).text = "NESTED"
buf = io.BytesIO(); d.save(buf)

print(DOCXToDocument().run(sources=[ByteStream(buf.getvalue())])["documents"][0].content)
# outer,

Expected behavior
The nested table's text is kept, e.g. outer,NESTED.

System

  • Haystack: main (68497ec)
  • python-docx 1.2.0, Python 3.13, Linux

I have a small fix with a test ready and can open a PR if this is fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions