Skip to main content
Safe Docx can compare two .docx files and produce a tracked-changes document that shows exactly what changed — at the character level.

Compare two documents

Use compare_documents to diff an original and a revised file:
You can also compare a session’s in-memory edits against the original by passing file_path instead of original_file_path + revised_file_path. This is useful after applying edits with replace_text or insert_paragraph.

The atomizer engine

The default engine ("auto") uses the atomizer, a character-level comparison algorithm with move detection. It produces fine-grained revision marks that show individual word and character changes rather than whole-paragraph replacements. The atomizer is selected automatically for most document shapes. You can force it explicitly by setting engine: "atomizer".
Use fail_on_rebuild_fallback: true in save to return an error instead of a potentially destructive rebuild output if the engine falls back to an incompatible mode for table-heavy documents.

Extract revisions as structured JSON

After generating a tracked-changes document, use extract_revisions to get a structured JSON summary:
The response contains before/after text per paragraph, revision type (insertion, deletion, move), and associated paragraph IDs. Use offset and limit to paginate through documents with many revisions.

Accept tracked changes

To finalize a tracked-changes document and produce a clean version with no revision markup:
Call accept_changes — it returns acceptance stats (number of insertions, deletions, and move records accepted). You can also call has_tracked_changes first to check whether a document contains revision marks before processing.

Full workflow example

1

Compare the two versions

2

Extract the top changed paragraphs

3

Accept changes to produce a clean final document

Golden prompt: compare two documents

This prompt reliably produces a comparison and revision summary:

Editing documents

Make surgical edits to a single document.

Golden prompts

All known-good prompt patterns in one place.