Automated contract drafting
HR fills in a form and the system produces a clean addendum from the current template. No more details from a previous employee left in the contract.
Starting point
Contract changes were made by copying an old contract.
Changed employment terms need an addendum that is precise and consistent. In practice, HR copied a previous employee’s contract and overwrote it. That usually works, until it doesn’t, and with legal documents that is exactly the problem.
The problem
Copy-and-overwrite produced predictable errors.
The copy method kept producing the same kinds of mistakes:
- clauses left over from someone else’s contract;
- the wrong organisation name or logo;
- empty gaps where an optional term didn’t apply;
- outdated templates circulating in personal folders.
With a changing set of templates, the risk of a faulty document kept growing, while all of it was avoidable.
The approach
A form as the only input, the rest is automatic.
HR fills in a form with only the changed details and the right category. A script then takes the current master template for that category, makes a copy, fills in the fields, and removes every optional clause that doesn’t apply.
- HR fills in the formonly what changes, plus the category
- Response in the response sheet
- Pick the current templateone master template per category
- Copy it and fill in the fields
- Is each optional clause filled in?Yes
- Clause stayswith the values filled in
No- Remove the whole clausenot just empty the field
- Clean up stray blank lines
- Clean addendum, ready to sign
The key detail is that last step. A standard mail-merge tool replaces an empty field with nothing, leaving half a sentence or a gap in the document. This script removes the entire clause and then cleans up the leftover blank lines.
Key decisions
Four choices that made the difference.
- The form is the only place to enter anything. HR doesn’t edit the document during generation. The errors didn’t disappear because of better templates, but because the opportunity to adapt an old contract was removed.
- One master template per category. The script always picks the current version. Template owners update it once and every later document uses the new version. No more stale copies in personal folders.
- Truly removing clauses. Instead of find-and-replace, the script walks the document’s structure and removes the right element. Options that weren’t chosen become invisible instead of ugly.
- The response sheet as a log. Every request is kept as a row: who asked for which change, when, and for which organisation. An audit trail with no extra work.
What made it hard
Deleting safely without touching legal text.
“Remove the element containing this field” sounds simple but can go badly wrong. If the field sits in a table cell or a paragraph with several terms, a crude approach deletes text that must stay. The script had to pick the right level for each type of field, and the blank-line cleanup had to tell intentional empty lines from leftovers. That’s why the template conventions and the code were designed together.
The result
Clean documents, drafted faster.
- Another employee’s details ending up in a contract has become much rarer, because every addendum starts from a clean, current template.
- Documents look tidy whatever options apply: no gaps, no orphaned clauses, no double blank lines.
- Drafting an addendum is faster, because filling in a form replaces most of the work.
- Template management is central: update once and everyone uses the new version.
- The generated document goes straight into e-signing, with no manual handover.
Built at organisations in finance, operations and business services. Client names and confidential details are left out.