apply_changes
Apply tracked changes to .docx files and produce a Word-compatible redlined document with insertions, deletions, and comments.
Instructions
Apply tracked changes to a .docx file and save a new redlined document.
Produces Word-compatible tracked changes (``w:ins`` / ``w:del``) with comments.
Always call ``extract_fragments`` first to get fragment IDs.
Paragraph changes (use ``fragment_id``):
- ``modify``: Word-level diff. ``new_text`` required.
- ``delete``: Marks paragraph deleted. Omit ``new_text``.
- ``append_after``: Insert after target. ``new_text`` required.
Table changes (use ``cell_id`` like ``"2.1.3"``):
- ``modify_cell``: Replace cell text. ``new_text`` required. Use ``
for multi-paragraph cells. -clear_cell: Delete cell content. Omit new_text``.
Rules:
- ``delete_next_blanks`` only with ``delete``.
- ``blank_lines_before`` / ``blank_lines_after`` only with ``append_after``.
- Header/footer changes work but comments are silently dropped.
- Documents with pre-existing tracked changes are hard-rejected.
``new_text`` uses pseudo-Markdown: ``**bold**``, ``_italic_``, ``__underline__``.
Example::
changes = [
{
"fragment_id": 1,
"change_type": "modify",
"new_text": "**Updated title**",
"justification": "Fixed typo"
},
{
"cell_id": "2.1.1",
"change_type": "modify_cell",
"new_text": "New header",
"justification": "Clarified"
}
]
Args:
document_path: Absolute path to the input .docx file.
changes: List of change objects (paragraph or table cell changes).
output_path: Where to save the redlined document. Defaults to
``<stem>_redlined.docx`` beside the input file.
author: Author name for tracked changes and comments. Defaults to
"AI Review".
Returns:
Summary string with change counts, output path, and validation result.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| author | No | AI Review | |
| changes | Yes | ||
| output_path | No | ||
| document_path | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |