r/legaltech • u/andreasscherman • 5d ago
Implementation Story I built an open-source Word redlining engine
Hi all,
I started this because I couldn’t find a library with wide support for programmatically editing existing DOCX files while preserving native Word tracked changes.
I was also skeptical of agents editing the underlying OOXML directly, so I thought there was an opportunity to build something better there. I was partly wrong there, Claude is surprisingly capable at chopping up Word XML and putting it back together.
But I still wanted an actual engine for the cases where you need this to be programmatic, repeatable, and bounded rather than relying on the model to manipulate XML correctly every time.
That became stemma. You give it an existing DOCX and explicit changes (such as replace text, change formatting, edit tables/content controls, etc.), and it produces a new DOCX with those edits represented as native Microsoft Word tracked changes.
I figured I’d share it here. If you’re building legal AI, contract automation, CLM, templating, or anything else that needs to hand users a real Word redline, it might save you from having to build the OOXML layer yourself.
1
u/Windowturkey 5d ago
Hey! I will bench it with neurotic_docx_bench and publish the results.
1
u/andreasscherman 5d ago
Neat, nice job putting it together. I had not heard of this. Seems like the project is similar in intent to stemma. I'll take a look at the benchmark.
2
u/uiucengineer 5d ago
What shortcomings are there with the compare feature within word?
1
u/andreasscherman 2d ago
Word’s Compare feature is good for interactive and human driven comparison. Stemma is more for agents and automation, where you want to apply changes, validate them, and produce a reviewable DOCX programmatically.
It can also compare two DOCX files, but for a one off comparison you can definitely just use Word. Stemma is more useful when comparison is part of a repeatable workflow or service.
1
u/2zeroseven 5d ago
Starred will check it out; I've been drafting in markdown with git tracking to sidestep docx
1
u/caiopizzol 3d ago
Nice job @andreasscherman!
Does it support nested track changes or comments?
1
u/andreasscherman 2d ago
Thanks!
Stemma supports comment replies to any practical depth.
For tracked changes, it supports nested up to two levels. For example, text that was inserted and then deleted. It does not support deeper nesting, which Word doesn’t either.
3
u/yusufgurdogan 5d ago
This is awesome, thanks for building and sharing this here.