Sub topic 10
Keeping an audit trail
An audit trail is a record of who did what to a content item, and when. This chapter assumes you have read the chapters on content states and approval gates. You should also be comfortable reading simple Python.
Why a trail matters
When a published page is wrong, someone will ask four questions. Who wrote it? Who approved it? What did the approved text say? Did anyone change it afterward? Without a record, you can only guess.
An audit trail also supports provenance. Provenance is the history of where a piece of content came from. For AI-assisted content, that includes which brief and model produced the first draft and which people shaped it afterward.
What to record
Each entry should answer who, what, and when. Record these fields:
| Field | Purpose |
|---|---|
| `at` | UTC timestamp of the event |
| `actor` | Person or system that acted |
| `from` / `to` | The state change, if there was one |
| `note` | The reviewer's reason or comment |
| `edit` | A hash of the new text, if the text changed |
Store a hash of the text instead of a copy in every entry. A hash is a fixed-length fingerprint of the text, so any change to the text produces a different hash. A hash shows that the text changed without bloating the log. Keep the full text of each version in a separate store, keyed by its hash.
The log in the state machine
The Item class from the state-machine chapter already writes entries in two places. _move records every state change. revise records every edit with the hash of the new text.
import hashlib
from datetime import datetime, timezone
def digest(text):
return hashlib.sha256(text.encode("utf-8")).hexdigest()
def entry(actor, **details):
return {"at": datetime.now(timezone.utc).isoformat(), "actor": actor, **details}
log = []
log.append(entry("ben", edit=digest("First draft text")))
log.append(entry("ben", **{"from": "draft", "to": "in_review"}))
log.append(entry("ana", **{"from": "in_review", "to": "changes_requested"}, note="Cite the source for the 40% figure"))
for e in log:
print(e["at"][:19], e["actor"], {k: v for k, v in e.items() if k not in ("at", "actor")})Read the log from top to bottom and you can replay the item's life. The reviewer's note explains why the item went back to its author.
Connecting the log to approval
The approval entry matters most. In the Item class, approve stores approved_digest, the hash of the exact text the reviewer saw. Publishing compares that hash with the current text. The log lets you check this independently. The last edit hash before the approved entry should equal approved_digest. If it doesn't, something changed the text outside the normal path.
Common mistakes
- Logging only state changes. If edits are not logged, you can't tell what changed between review and approval.
- Letting people edit entries. Make the log append-only. Give the application permission to add entries but not to update or delete them.
- Local timestamps. Use UTC so entries from different systems sort correctly.
- Leaving out the AI step. Log the model name, the brief, and the prompt version as an event by the system actor, so reviewers know which draft came from the model.
- Vague notes. "Needs work" tells the next reader nothing. Ask reviewers to name the criterion that failed.
Keeping it usable
Retain the log for as long as the content or your policies require. Make it searchable by item, actor, and date. Entries nobody can find are not much help during an incident.
Exercise
A published article is challenged. The log shows the last edit hash before approval was H1, but the item's approved_digest is H2. What does this tell you, and what should you check next?
Show answer
The text the reviewer approved is not the last version recorded in the log, so either an edit was made without being logged or the approval recorded the wrong text. Check whether the text store holds versions matching H1 and H2, find who last touched the item and when, and review the approval entry's actor and timestamp.
Exercise
Name two reasons to log a hash of the text in each edit entry instead of the full text.
Show answer
The log stays small, and the hash lets anyone verify that a stored version is unchanged. Comparing hashes also shows quickly whether two versions differ.