Repository navigation
Conversation
…ragraph tag name _try_extract_docx_text split paragraphs on any tag whose name begins with "w:p", so <w:proofErr>, which Word writes around each flagged misspelling, broke a paragraph into several lines. Match only the paragraph tag itself.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
Problem:
_try_extract_docx_textsplitsword/document.xmlinto paragraphs with<w:p(?:[^>]*)>. Nothing requires the tag name to end afterw:p, so the pattern also matches<w:proofErr>,<w:pPr>,<w:permStart>,<w:pgSz>and every other tag whose name starts withw:p. Word writes a<w:proofErr>pair around each word its spell checker flags, soload_artifactshands the model a paragraph broken into several lines at each flagged word.Solution:
Require the tag name to end where the paragraph tag ends:
<w:p(?=[\s/>])[^>]*>. This still matches<w:p>,<w:p/>,<w:p w:rsidR="...">and a tag name followed by a newline or tab, and no longer matches longer tag names. It is a one-line change; the namespace-prefix handling and the text extraction are untouched.Known limitation, left out on purpose: text separated only by
<w:ptab/>used to land on separate lines as a side effect of this bug and is now joined, the same way text around<w:tab/>and<w:br/>already is today. Turning tabs and breaks inside a run into whitespace is a separate change.Testing Plan
Unit Tests:
New test
test_load_artifacts_keeps_docx_paragraph_with_proofing_marks_on_one_linegoes throughload_artifacts_tool.process_llm_requestlike the neighbouring docx tests. It fails onmainand passes with the fix:Full tox matrix on Linux for commit
8cd1b4fc6494bf39db34058cb0c68277efd09a9b, isolated environments,pytest tests/unittests -n 2:The workflow and the dependency lock it uses live on a separate fork branch and are not part of this PR.
For transparency: a local
toxrun on Windows 11 has 70 to 104 failures per Python version in unrelated areas (BigQuery plugin, telemetry, Cloud Run deploy, shell and path tests). None are in the docx tests, and the files that failed on 3.13 fail the same way on untouchedmain.pyink25.12.0,isort8.0.1,ruffandcodespellare clean on both changed files.Manual End-to-End (E2E) Tests:
Setup: a real
RunnerwithInMemoryArtifactService, anLlmAgentwith theload_artifactstool, and areport.docxsaved from Microsoft Word 16 containing two paragraphs and three misspelled words (six<w:proofErr>tags). The model is a local stub that callsload_artifactsonce and prints the artifact text it is then sent, so no external model is called.I also built the wheel with
uv build, installed it into a clean virtual environment, and reran the same script from outside the checkout with the same passing result.Runner script
Run as
python run_e2e.py report.docx.Checklist
Additional context
#7088 edits the next line of the same function (entity decoding) and does not change the split. The two changes merge without a textual conflict.
Prepared with AI assistance.
🤖 Generated with Claude Code