Skip to content

fix: read content controls in DOCXToDocument - #13164

Open
LindseyZ1205 wants to merge 2 commits into
deepset-ai:mainfrom
LindseyZ1205:fix/docx-content-controls
Open

LindseyZ1205 wants to merge 2 commits into
deepset-ai:mainfrom
LindseyZ1205:fix/docx-content-controls

Conversation

@LindseyZ1205

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

DOCXToDocument._extract_elements only handled the direct w:p and w:tbl children of the document body. Block-level content controls (w:sdt) keep their paragraphs and tables in w:sdtContent, so their content was dropped without any warning. Word uses them for cover pages, tables of contents and template fields.

A new _block_elements helper lists the body's children and replaces each content control with the elements in its w:sdtContent, recursively, so nested content controls are expanded too. _extract_elements iterates this list, so paragraphs (including text boxes, page breaks and links) and tables inside a content control go through the existing handling, in reading order.

How did you test it?

  • Added test_run_reads_text_inside_a_content_control (paragraphs, including a nested content control, in reading order) and test_run_reads_a_table_inside_a_content_control. Both fail on main and pass with this change.
  • Renamed the test helper _docx_with_text_box to _docx_with_block, since it now also builds the content-control documents. The text box tests are unchanged.
  • hatch run test:unit (full unit suite), hatch run fmt, hatch run test:types, and pre-commit on the changed files.

Notes for the reviewer

Word also stores the table of contents in a block-level content control, so its entries now appear in the converted text, as they do in the document. If you'd rather skip the table of contents (its w:sdtPr has a w:docPartGallery of "Table of Contents"), I can add that.

This PR was generated with an AI assistant (Claude Code), including finding the bug. I have reviewed the changes and run the relevant tests locally.

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes.
  • I have added unit tests and updated the docstrings.
  • I've used one of the conventional commit types for my PR title.
  • I have documented my code.
  • I have added a release note file.
  • I have run pre-commit hooks and fixed any issue.

🤖 Generated with Claude Code

_extract_elements only handled the direct w:p and w:tbl children of the
document body. Block-level content controls (w:sdt) keep their
paragraphs and tables in w:sdtContent, so their content was dropped
without any warning. Word uses them for cover pages, tables of contents
and template fields.

Expand content controls, including nested ones, into the elements they
hold before the existing paragraph and table handling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@LindseyZ1205
LindseyZ1205 requested a review from a team as a code owner October 7, 2026 14:24
@LindseyZ1205
LindseyZ1205 requested review from julian-risch and removed request for a team October 7, 2026 14:24
@vercel

vercel Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

@LindseyZ1205 is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added topic:tests type:documentation Improvements on the docs labels Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/converters
  docx.py 258
Project Total  

This report was generated by python-coverage-comment-action

This branch has not been deployed

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

Labels

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DOCXToDocument drops the paragraphs and tables inside block-level content controls (w:sdt)

2 participants