How to audit what an AI agent actually did
Why ordinary logs are not enough
Most agent frameworks write logs. A log tells you what the system says happened. It does not tell you whether the log was edited afterwards, whether a step was dropped, or whether the order was rearranged to make a decision look better supported than it was. When an agent refunds the wrong customer or sends an email it should not have, the first question is what it did and why, and the second is whether you can trust the answer.
An audit trail is only useful in a dispute if a party who did not produce it can check it. That rules out anything whose correctness rests on the vendor's word, including the vendor that wrote this article.
What to record for each step
Treat every model call, tool call, tool result, retrieval, guardrail check and human approval as an event. For each one, keep:
- What kind of step it was and its name, for example a
tool_callnamedsend_email. - Which earlier steps it depended on, as a list of parent event ids. A run is a graph, not a list: parallel tool calls branch and later steps join them.
- Hashes of the inputs and outputs, not the raw content. Hashing with a per run salt lets you prove later that a given prompt or result is the one recorded, without storing or sending it.
- Whether it had a side effect, such as writing a file, moving money or sending a message. These are the steps an auditor looks at first.
- A sequence number and a timestamp.
Make edits detectable
Three hash structures together make a run tamper evident:
- A leaf hash per event, computed over the event's canonical JSON. Change one field and that hash changes.
- A hash chain. Each event stores the leaf hash of the event before it (
prev_hash). Removing, inserting or reordering an event breaks every link after it. - A Merkle root over all leaf hashes, written into a small sealed record (the capsule) together with the chain head and the event count. The capsule's own hash is the run's identity.
Leaves and interior nodes are hashed with different prefixes, so an interior node can never be passed off as an event. Canonical JSON (RFC 8785) matters as much as the hash function: two implementations that order keys or format numbers differently will disagree about a correct record.
Verify without trusting the producer
Verification recomputes everything from the events and compares it with the capsule. In MershTrust the verifier reports each check by name, so a failure says what is wrong rather than just failing:
| Check | What it catches |
|---|---|
| Leaf hash integrity | An event's content changed after sealing |
| Append only chain linkage | An event was removed, inserted or reordered |
| Merkle root reconstructs | The event set differs from what was sealed |
| Chain head matches capsule | Events were added after the run was sealed |
| Event count matches capsule | The log was truncated or padded |
| Execution DAG integrity | A step names a parent that does not exist or comes later |
| All events bound to capsule run_id | Events from another run were mixed in |
The verifier exists in Python and, separately, in TypeScript, sharing no code, with a shared set of test vectors that both must agree on. A browser can check a run itself, so the person checking does not have to run the producer's software.
Prove nothing was deleted later
A sealed run proves its own contents. It cannot prove that a whole run was not quietly dropped or replaced. For that, append each sealed run's identity to a public transparency log, a Merkle Mountain Range, and publish its root from time to time. An inclusion proof shows a run is in the log; a consistency proof shows a later log extends an earlier one without rewriting it.
A minimal example
pip install mershtrust
from mershtrust import AgentAuditTrail, verify_agent_capsule
trail = AgentAuditTrail(framework="custom", root_agent="refund-agent")
call = trail.record("tool_call", name="lookup_order", input={"order": "A-1042"})
trail.record("tool_result", name="lookup_order", parent_ids=[call.node_id], output={"total": 412})
trail.close()
result = verify_agent_capsule(trail.attest().to_dict(), events=trail.events_as_dicts())
print(result.ok) # True; change any recorded field and it becomes FalseQuestions
- What is a tamper evident audit trail?
- A record where any later change is detectable by recomputing hashes: each event is hashed, each hash commits to the previous one, and the whole run is sealed with a Merkle root. It does not prevent edits; it makes them impossible to hide.
- Do I have to store prompts and outputs to audit an agent?
- No. Storing salted hashes of inputs and outputs is enough to prove later that the content you hold is the content that was recorded, without keeping or sending it.
- Can the audit vendor fake a verified result?
- Not if you verify yourself. Verification recomputes every hash from the events, so an independent implementation, run by the checker, reaches the same answer without trusting the vendor.
- What is the difference between a log and an audit trail?
- A log is what the system says happened. An audit trail, in this sense, is a log whose integrity a third party can check.