GRACE-DOCX: Making Large .docx Files LLM-Friendly Without Context Rot
LLMs often break when editing big .docx files: they lose sections, mess up synchronization, and cause iterative drift. GRACE-DOCX fixes this by embedding a module map, contracts, and verification right into the document. One prompt turns the file into a self-managing powerhouse—the agent follows built-in rules, slashing token errors by 80%.
Context Rot in Transformers: Why Big Documents Are a Nightmare to Edit
Transformers degrade as context grows. A 2025 Chroma study on 18 frontier models showed accuracy dropping over 30% for mid-context info (Stanford). BABILong from AIRI/MIPT confirms it: GPT-4.1, Claude Opus 4, and Gemini 2.5 all struggle the same way.
In .docx files, this shows up in two ways:
- One-shot failures: The model skips the right paragraph amid thousands.
- Iterative drift: After 3–5 edits, the agent rewrites unrelated stuff, breaks tables, and loses links.
Standard chat pipeline for .docx:
- Unzip the file.
- Extract word/document.xml.
- Load everything into context.
- Find the spot.
- Generate the edit.
- Repack.
Problems:
- No map for navigation.
- No rules (e.g., don't touch table columns).
- No XML/structure verification.
RAG or templating tools like docxtpl help but are overkill for one-offs.
GRACE-DOCX: Contract-Based Editing Powered by Graphs
Adapting GRACE (Graph-RAG Anchored Code Engineering) for .docx. The document teaches the agent itself:
- Structure: Modules with IDs (M-PROC, M-APP-A).
- Rules: What to touch/sync.
- Verification: Invariants.
The GRACE-DOCX methodology (Governed, Recoverable, Autonomous, Contract-based Editing) weaves knowledge into the .docx XML parts.
Activation process—one prompt:
Step 1. Analysis: Parse document.xml, lock down H1/H2, tables, cross-links.
Step 2. Map: Module IDs for sections, paragraph ranges.
Step 3. Metadata: 5 XML files (manifest, graph, contracts, instructions, verification).
Step 4. Bookmarks: w:bookmarkStart/End on H1s.
Step 5. Registration: [Content_Types].xml, _rels.
Step 6. Pack up.
Step 7. Report: N modules, bookmarks, links.
Now the agent reads the manifest, follows the contract, and checks invariants. Behavior is consistent across sessions and models.
Benefits and Limitations
Solves:
- Surgical edits in 200+ page docs.
- Drift: Edits stay isolated.
- Syncing (update thresholds—propagates everywhere).
- Up to 80% token savings, smaller context windows.
Doesn't solve:
- Semantics (that's on the LLM).
- Content versioning (but it logs changes).
Open challenges:
- .xlsx (sheets as modules).
- .pptx (slides/objects).
- Images, complex tables.
- Tool integration (MCP).
Key Takeaways
- Embeds map and rules in .docx—the agent isn't flying blind.
- Cuts context rot and drift without huge windows.
- Works for any Office format (ZIP+XML).
- Open-source repo: github.com/xronocode/grace-docx.
— Editorial Team
No comments yet.