Build agents that edit DOCX documents
Learn how to choose document tools, connect an agent, and return edits users can review. Follow the path below or find a guide for the problem you are solving.
Start here
From tool selection to a reviewable edit
- Step 1
Choose your tools
Match libraries and MCP servers to the document workflow you need to build.
- Step 2
Build an editing agent
Connect document tools, manage a session, and deliver the updated DOCX.
- Step 3
Preserve formatting
Scope the edit and check surrounding text, tables, images, and document structure.
- Step 4
Return changes for review
Run a contract edit and inspect the native revisions and preservation checks.
Working example
Inspect a contract edit from input to output
Start with a sample DOCX, runnable Python code, recorded API outputs, and preservation checks. The guide explains what was verified and what still needs checking in Word.
Choosing DOCX tools
Start with the document your application needs to deliver. Compare libraries, converters, and MCP servers by whether you need to generate a file, extract content, or edit an existing document.
Start with this guide
DOCX libraries for AI agents: choose by editing workflow
Compare Python DOCX editing, JavaScript generation, templates, HTML conversion, and Vespper MCP based on the document task your agent must perform.
Agent and editor integration
Connect document tools to your application and return the edited file to the user. Start with the session lifecycle, then use the Office.js example if your agent needs to work inside Word.
Start with this guide
Build an AI agent that edits existing DOCX documents
Connect a document-editing agent to Vespper DOCX MCP: open a session, read or search, apply targeted edits, save the document, and close the session.
Build an AI Word add-in with Office.js and Vespper
Build a Word add-in with Office.js, React, and Vespper DOCX MCP. Run our open-source example, stream AI edits into Word, and review tracked changes.
Editing existing documents
Locate the right passage, make a targeted change, and check what survives the edit. These guides cover formatting, ambiguous matches, and finding content in long documents.
Start with this guide
Preserving DOCX formatting when an AI agent edits a file
Understand run formatting, targeted HTML edits, document structure, and practical checks for preserving an uploaded DOCX during agent-driven editing.
Find and edit a passage in a large DOCX document
Use document search, page ranges, unique HTML anchors, and revision checks to target edits in long Word files without loading the whole file into an agent.
Review and validation
Return edits as native Word tracked changes so a person can review them. Use a sample contract, recorded API outputs, and verification code to inspect the result and understand the checks' limits.
Start with this guide
DOCX tracked changes API: redline a contract with an agent
Return agent edits as native Word tracked changes. Run a Python contract-editing example with a sample DOCX, revision authors, and preservation checks.
Python DOCX troubleshooting
Use Python for document changes your application can specify directly. Work through text split across runs, table cells, missing images, and review comments before connecting those operations to an agent.
Start with this guide
python-docx: create and edit Word documents in Python
Install python-docx, read and edit existing Word files, and replace text while keeping run formatting. Runnable examples, comments, and tracked-change limits.
Add review comments to DOCX with python-docx
Use python-docx 1.2.0 to anchor a review comment to runs. Understand sentence boundaries, comment authors, and the difference between comments and tracked edits.
Find and replace text in DOCX tables with Python
Find text in table-cell paragraphs, including nested tables, without treating merged cells as separate values or overwriting the whole cell.
Replace text split across runs in python-docx
Replace a phrase that spans multiple Word runs without flattening the paragraph. Decide how replacement text inherits formatting and handle ambiguous matches.
Why images disappear after python-docx text replacement
Avoid removing inline drawings when changing DOCX text. Inspect run content, skip unmatched runs, and verify images before and after the edit.