#3059·agentscope

[Bug]: WordParser silently drops images embedded inside table cells

Author: liwenjie200543Created Sep 30, 2026Updated Sep 30, 2026
Labelstriage/confirmed

Prerequisites

  • I have searched the existing issues and discussions and this is not a duplicate.
  • This is a bug, not a usage question.

Description

In WordParser.parse() (src/agentscope/rag/_parser/_word.py, body-walk loop, lines 311–366 on e101864), the CT_P branch extracts embedded images via _extract_image_blocks() when include_image=True. The CT_Tbl branch, however, only renders cell text (markdown/JSON) and never touches images:

python
elif isinstance(element, CT_Tbl):
    table_data = _extract_table_data(Table(element, doc))
    rendered = (...)
    if not rendered:
        continue
    ...

Any w:drawing / w:pict located inside a table cell is therefore silently discarded, although the class docstring states that embedded images are emitted as their own Section instances with no table exclusion. Pasting screenshots into table cells is common (spec sheets, test reports, financial documents), so RAG indexing of such DOCX files permanently loses every image under the default include_image=True.

Reproduce

No error is raised; the parser silently returns altered content.

python
import asyncio, io, base64
from docx import Document
from agentscope.rag import WordParser

png = base64.b64decode(
    "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJ"
    "AAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
)  # 1x1 PNG

doc = Document()
doc.add_paragraph("Intro")
doc.add_paragraph().add_run().add_picture(io.BytesIO(png))   # body image — extracted
cell = doc.add_table(rows=1, cols=1).cell(0, 0)
cell.text = "see screenshot"
cell.add_paragraph().add_run().add_picture(io.BytesIO(png))  # cell image — dropped
doc.add_paragraph("Outro")
buf = io.BytesIO()
doc.save(buf)

sections = asyncio.run(WordParser().parse(buf.getvalue(), "a.docx"))
# Actual:   3 sections, exactly one DataBlock (the body-level image)
# Expected: 4 sections, two DataBlocks (the cell image is preserved)

Environment

  • agentscope main @ e101864 (2026-09-30)
  • Python 3.12.14
  • Windows 10 (19045); behavior is platform-independent
  • python-docx 1.1+ (agentscope[rag] extra)

Source: agentscope-ai/agentscope