Document comparison
Goal
Tell the reader what actually changed between two documents so they can review the changes, not the whole text. A good result groups changes by section, separates content from formatting, and states clearly which file is the base.
When to use
- Two drafts, two contract-free business documents, two reports or two exports of the same text.
- The user received a revised file with no tracked changes and wants a change list.
- For code diffs, use
git_difforuse_skillwithcode-review. - For checking two data tables rather than text, use
run_commandwith a keyed comparison.
Steps
- Identify the pair. Use
lsif names are ambiguous andask_userto confirm which is the older base and which is the newer. Check modified dates as a hint, not a proof. - Convert both to comparable plain text. For docx or pdf, extract with
run_command, keeping headings, list items and table cells on separate lines. Save both texts so the comparison can be rerun. - Normalise noise that is not content: whitespace runs, smart versus straight quotes, soft hyphens, page numbers, repeated headers, and automatic date or field values. Tell the user what you normalised.
- Align by structure first. Split on headings and compare section by section, matching sections by title, so that an inserted chapter does not shift everything after it.
- Diff inside each matched section at sentence level with
run_command(a sequence matcher gives insert, delete and replace blocks). Then look for moved text: a deleted block that appears elsewhere almost unchanged is a move. - Classify each change: wording, number or date, added content, removed content, moved, structure, formatting only. Rank changes that touch numbers, names, dates, amounts and obligations first, because they carry the most risk.
- Read ten of the reported changes back in the source files to make sure the diff is right.
- Write the report with
create_fileif it is long: summary on top, then changes by section with the old text and new text in short quotes. - Offer the reader what they most likely need next.
- A clean merged view of the new text with the changes marked, saved as its own file.
- A list of questions for the author about changes that look unintended, such as a deleted caveat.
- A check that numbers in the summary still agree with numbers in the body of the new version.
- If there are three or more versions, a chain of pairwise comparisons rather than one comparison of first and last.
- State clearly which version was treated as the base, in the first line of the report.
Gotchas
- Comparing exports of the same content from different tools yields thousands of fake changes from spacing and quotes. Normalise before judging.
- Word-level diffs of heavily reworded paragraphs are unreadable. Show replaced paragraphs side by side instead.
- A changed number inside a table cell is easy to miss in a long diff. Run a separate numeric pass that lists every digit sequence that appears in one version only.
- Tracked changes already in a docx are part of the text. Decide whether to compare with them accepted, and say which.
- Do not describe the intent behind a change. Report what differs, and let the author explain why.
- Images, charts and embedded objects do not appear in a text diff. Say that they were not compared, and list how many each file has.
Output
- A line on what was not compared: images, comments, metadata.
- A three-line summary: how many sections changed, the biggest change, and the changes in numbers or dates.
- Changes by section with old and new text, ranked by risk.
- What was normalised or ignored, and the path of the full report if saved.
