You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: WordParser drops soft line breaks and tabs inside DOCX paragraphs #2839
I have searched the existing issues and discussions, and this is not a duplicate.
This is a bug, not a usage question. (For questions, please use Discussions instead.)
Background / Description
WordParser.parse() silently removes soft line breaks and tabs inside a
nonempty DOCX paragraph. The surrounding text is concatenated without a
separator, corrupting the content passed to RAG chunking and indexing.
A soft line break, such as one inserted with Shift+Enter in Word, stays
inside the same paragraph. It is represented by a w:br element; a tab is
represented by w:tab. The reproduction below creates both using python-docx
and confirms that they survive saving and reopening the DOCX.
Expected: preserve the internal separators:
'Name\tAlice\nDepartment\tEngineering'
Actual: the fields and lines are joined together:
'NameAliceDepartmentEngineering'
This concerns separators inside a single paragraph, rather than blank lines
between separate paragraphs.
Error Messages
Expected: 'Name\tAlice\nDepartment\tEngineering'
Actual: 'NameAliceDepartmentEngineering'
AssertionError
The assertion is from the reproduction. The parser itself returns the altered
text without raising an error.
Steps to Reproduce
From a checkout of AgentScope, install the project and the Word parser dependency:
python -m pip install -e . python-docx
Save the following as repro.py and run python repro.py. It creates a real
DOCX in memory and requires no API key or external service.
importasyncioimportiofromdocximportDocumentfromagentscope.ragimportWordParserasyncdefmain():
expected="Name\tAlice\nDepartment\tEngineering"document=Document()
document.add_paragraph(expected)
buffer=io.BytesIO()
document.save(buffer)
data=buffer.getvalue()
# Check that the DOCX itself retains the tabs and soft line break.assertDocument(io.BytesIO(data)).paragraphs[0].text==expectedsections=awaitWordParser(include_image=False).parse(data, "example.docx")
assertlen(sections) ==1actual=sections[0].content.textprint(f"Expected: {expected!r}")
print(f"Actual: {actual!r}")
assertactual==expectedasyncio.run(main())
Environment
AgentScope: 2.0.8, editable install at 083cbd1975c7b5ed055c69b0d19c150727e7f606.
Python: 3.11
python-docx: 1.2.0.
OS: Windows.
On that checkout, the existing WordParser tests pass: python -m pytest tests/rag_parser_test.py -k WordParser -q → 14 passed.
The reproduction above fails.
The same reproduction also fails when loading _word.py from PR fix(rag): keep text inside nested Word tables #2759's
final commit (4a16631de82fce3e3d15fa6cc059422ccc6b4107) and upstream main
(a38821287f35e9e45ed193d9d864cb46f263c946, checked on 2026-09-25) against
the local environment. These additional checks exercised the parser file,
not the full test suite of those revisions.
Prerequisites
Background / Description
WordParser.parse()silently removes soft line breaks and tabs inside anonempty DOCX paragraph. The surrounding text is concatenated without a
separator, corrupting the content passed to RAG chunking and indexing.
A soft line break, such as one inserted with Shift+Enter in Word, stays
inside the same paragraph. It is represented by a
w:brelement; a tab isrepresented by
w:tab. The reproduction below creates both using python-docxand confirms that they survive saving and reopening the DOCX.
Expected: preserve the internal separators:
Actual: the fields and lines are joined together:
This concerns separators inside a single paragraph, rather than blank lines
between separate paragraphs.
Error Messages
Steps to Reproduce
From a checkout of AgentScope, install the project and the Word parser dependency:
python -m pip install -e . python-docxSave the following as
repro.pyand runpython repro.py. It creates a realDOCX in memory and requires no API key or external service.
Environment
083cbd1975c7b5ed055c69b0d19c150727e7f606.python -m pytest tests/rag_parser_test.py -k WordParser -q→ 14 passed.The reproduction above fails.
_word.pyfrom PR fix(rag): keep text inside nested Word tables #2759'sfinal commit (
4a16631de82fce3e3d15fa6cc059422ccc6b4107) and upstream main(
a38821287f35e9e45ed193d9d864cb46f263c946, checked on 2026-09-25) againstthe local environment. These additional checks exercised the parser file,
not the full test suite of those revisions.