AI Audit Logs
In this article
- Design an audit event for an agent's action from ids, hashes and decisions, with no prompt text, personal data or credentials.
- Answer who authorized an exact write from the log alone, by matching the intent hash in the approval with the one in the tool receipt.
- Explain how a hash chain and a head hash kept outside the log expose an edited or missing event.
- Say which check catches a missing approver, a write with no principal and a card number inside an event.
- Terms defined here: audit log, tamper-evident log.
Overview
A made-up online shop runs a support agent that can issue refunds. It refunded 250.00 EUR on order O-1077 for customer c-77, and now the customer says they never asked for it. Someone has to answer two questions fast: who allowed that money to move, and was what they allowed exactly what happened?
You will design the record that answers both without opening the agent's private conversation with the customer, and then make that record hard to change quietly. By the end you can say which fields an audit event needs, read a dispute off a short log, and predict which check catches an edited event, a missing one, a missing approver or a card number that should never have been written down.
Why the transcript is the wrong answer
The first instinct is to open the conversation: the prompts, the model's replies, the tool calls. That breaks in two ways. The transcript is full of things you should not keep for years, such as the customer's name, email and order notes, and OWASP lists personal data and credentials that slip into agent logs as a risk of its own. [1] And a transcript records what was said, which is not the same as what was written to the payments system.
What you need is a narrower record: the decisions and actions themselves, with ids that point to everything else. OWASP's advice for high-risk actions is to log structured decision metadata, such as the authorization outcome, the approval identifier, the execution result and the policy version. [1] That kind of record is an audit log. Each entry in it is an audit record, here called an audit event.
One audit event
The approval gate in front of the tool writes two records. The action intent is stored before the write: the exact write the agent is about to make, this tool, this order, this amount. The tool receipt comes back after it, as the tool's confirmation of the write. Hash the intent and you get one short value that names that exact action, which is why OWASP asks that an approval be bound to the exact action rather than to a kind of action. [1]
Here is the field set of the shop's audit event, with the made-up values from run r-91:
| field | value in run r-91 | what it answers |
|---|---|---|
event_id | e1 to e4 | which step of the run |
run_id | r-91 | which run |
principal | sub c-77, act support-agent | for whom, and by whom |
policy_decision | refund policy v3: require_approval | which rule applied |
approver | s-12 (refund supervisor) | who allowed it |
action_intent_hash | sha256:4be1… | exactly what was allowed |
tool_receipt | rcpt-552, with the same action_intent_hash | what was written |
release_id | 7 | which build of the agent ran |
retention_class | audit | how long to keep it |
prev_hash | hash of the previous event | link in the chain |
The principal field names who is involved. A principal is the identity a system checks before it lets someone act. Here sub c-77 is the customer the action is for, and act support-agent is the agent doing it.
Two fields are pointers, not content. release_id 7 points to a release manifest that says what that build of the agent contained, and none of that is copied into the event. retention_class is only a label; the schedule that decides what "audit" means lives elsewhere.
Look at what the table lacks: no prompt text, no customer name or email, no card number, no API key. Every value is an id, a hash or a decision. That is the design rule, and it has a reason: in the shop's design the audit store outlives any debugging trace, so anything private inside it stays exposed for just as long.
Answering the dispute
The run produced four events: e1 starts the run for c-77, e2 records the policy decision, e3 records the approval and e4 records the refund write. Here are the two that matter, without the chain fields:
{"event_id": "e3", "type": "approval", "approver": "s-12",
"action_intent_hash": "sha256:4be1..."}
{"event_id": "e4", "type": "write",
"principal": {"sub": "c-77", "act": "support-agent"},
"tool_receipt": {"id": "rcpt-552", "action_intent_hash": "sha256:4be1..."}}Who authorized the refund? e3 names approver s-12. Did s-12 approve this refund, or some refund? The action_intent_hash in e3 is sha256:4be1…, and the receipt rcpt-552 in e4 carries the same hash, so the write that happened is the action s-12 saw. No prompt was opened, and no token or card data was needed.
Be clear about what that proves. The log shows what was authorized and what was written. It does not show that the refund was a good decision; s-12 may have been wrong. It also says nothing yet about whether someone edited the log after the fact.
Making edits visible
A log anyone can edit is a diary, not evidence. The Microsoft Agent Governance Toolkit keeps its audit logs append-only with Merkle chains, and its docs advise adding an external append-only sink, such as Azure Monitor or write-once storage, for tamper-evidence. [2] We call that pairing a tamper-evident log.
The simplest version of that linking is a plain hash chain. A hash is a short fingerprint computed from the content: change one character of an event and its SHA-256 hash comes out completely different. Each event stores the hash of the one before it in prev_hash, so an edited event no longer matches the prev_hash of the event after it, as the program below shows.
Here are the events, the chain and its verifier in standard-library Python. events builds e1 to e4 and lets you seed one flaw at a time; build appends them and returns the hash of the last one, the head, which goes to a separate store:
import hashlib, json, re
INTENT = 'sha256:4be1...' # from the approval gate, shortened here
CARD = re.compile(r'\b(?:\d[ -]?){12,18}\d\b')
WHO = {'sub': 'c-77', 'act': 'support-agent'}
def events(approver='s-12', principal=WHO, note=None):
e2 = {'event_id': 'e2', 'type': 'policy', 'action_intent_hash': INTENT,
'policy_decision': 'refund-policy-v3: require_approval'}
if note:
e2['note'] = note
return [{'event_id': 'e1', 'type': 'run_start', 'principal': WHO}, e2,
{'event_id': 'e3', 'type': 'approval', 'approver': approver,
'action_intent_hash': INTENT},
{'event_id': 'e4', 'type': 'write', 'principal': principal,
'tool_receipt': {'id': 'rcpt-552', 'action_intent_hash': INTENT}}]
def h(event):
return hashlib.sha256(json.dumps(event, sort_keys=True).encode()).hexdigest()
def build(events):
log = []
for e in events:
e.update(run_id='r-91', release_id=7, retention_class='audit',
prev_hash=h(log[-1]) if log else '0' * 64)
log.append(e)
return log, h(log[-1]) # the head goes to a separate store
def verify(log, stored_head):
found = [f'chain breaks at {b["event_id"]}' for a, b in zip(log, log[1:])
if b['prev_hash'] != h(a)]
if h(log[-1]) != stored_head:
found.append('head hash differs from stored head')
for e in log:
if e['type'] == 'approval' and not e.get('approver'):
found.append(f'{e["event_id"]}: approval with no approver')
if e['type'] == 'write' and not e.get('principal'):
found.append(f'{e["event_id"]}: write with no principal')
if CARD.search(json.dumps(e)):
found.append(f'{e["event_id"]}: card number pattern')
return found or ['ok']
log, head = build(events())
for e in log:
print(e['event_id'], e['type'], 'prev', e['prev_hash'][:8], 'hash', h(e)[:8])
print('stored head:', head[:8])
e3, e4 = log[2], log[3]
print('authorized by:', e3['approver'], '| same intent in receipt:',
e3['action_intent_hash'] == e4['tool_receipt']['action_intent_hash'])The last two lines answer the dispute from the log alone. Run on the clean log, the program prints this:
e1 run_start prev 00000000 hash 5721f673
e2 policy prev 5721f673 hash f0510c0a
e3 approval prev f0510c0a hash 5adb10b4
e4 write prev 5adb10b4 hash 2ceed0da
stored head: 2ceed0da
authorized by: s-12 | same intent in receipt: TrueFive flaws, four checks
Now break the log in five ways, one flaw each, and predict before you read on which check catches it. Someone edits e2 after the fact to say allow. e3 is written with no approver. e4 is deleted, leaving e1 to e3. An admin console writes the refund with no principal. A note in e2 holds a card number (the well-known test number 4111 1111 1111 1111).
The log is edited after the head is stored. A small driver builds the log, applies one flaw and verifies it; the edit and the removal happen after build, the other three are seeded through events:
def run(label, mutate=None, **flaw):
log, head = build(events(**flaw))
if mutate:
log = mutate(log)
print(f'{label:<19} {verify(log, head)[0]}')
def edit_e2(log):
log[1]['policy_decision'] = 'allow'
return log
run('clean')
run('edited e2', edit_e2)
run('e3 no approver', approver=None)
run('e4 removed', lambda log: log[:3])
run('write no principal', principal=None)
run('card in e2', note='card 4111 1111 1111 1111')Here is the verifier's real output:
clean ok
edited e2 chain breaks at e3
e3 no approver e3: approval with no approver
e4 removed head hash differs from stored head
write no principal e4: write with no principal
card in e2 e2: card number patternThe removed e4 is the surprising one. e1 to e3 still link perfectly, because nothing points forward to e4: a chain only checks backwards. What catches it is the head hash 2ceed0da stored outside the log, since the last event left is e3 and its hash is 5adb10b4. A count of events kept outside the log would work too.
The other three flaws are not tampering at all. The chain is intact; the events were bad when written. A required-field check catches an approval without an approver and a write without a principal, and a pattern scan catches raw card data.
One weakness remains. An attacker who can rewrite the log could rebuild every hash after an edit, and if the head sits next to the log, rewrite that too. So the head must live where the log's writers cannot reach it, such as write-once storage that the agent's service account cannot overwrite, and even then the chain detects changes; it does not prevent them. That is why the toolkit docs recommend an external sink.
Common mistakes
- Logging the prompt to be safe. Symptom: the audit store becomes the largest store of customer data you have, kept the longest. Fix: ids, hashes and decisions only; OWASP warns against plain-text personal data and credentials in logs. [1]
- Trusting the chain alone. Symptom: a log with its last events cut off verifies as clean. Fix: compare the head hash or event count with a value stored outside the log.
- An approval with no intent hash. Symptom: you can show that s-12 approved a refund, but not that it was this refund. Fix: bind the approval to the exact action [1], and carry the same
action_intent_hashinto the tool receipt. - Keeping the head next to the log. Symptom: whoever rewrites the events rewrites the head too, and verification passes. Fix: send the head to a store the log's writers cannot change. [2]
In production
- Fail closed. If the audit write fails, the refund should not go through; OWASP lists audit logging among the failures that must stop a high-impact action. [1]
- Watch the log, not only keep it. OWASP suggests alerts on repeated approval bypass attempts and sudden rises in high-risk actions. [1]
- Know who holds the events. In Anthropic's Managed Agents, session history is kept until you delete the session; before deleting, use the events API to export what you must keep into a store you own. [4]
- Expect identity rules to tighten. A NIST NCCoE initial public draft concept paper (comment period closed April 2026) asks how identification, authorization, auditing and non-repudiation should work for AI agents. [5] Non-repudiation means an actor cannot credibly deny an action the record ties to them, which is what the approver and intent hash give you.
Sources
- AI Agent Security Cheat Sheet (OWASP). OWASP Foundation. Checked 25 Oct 2026.
- Architecture (Microsoft Agent Governance Toolkit). Microsoft. Checked 25 Oct 2026.
- Microsoft Purview for Agent 365. Microsoft. Checked 21 Nov 2026.
- Review and monitor agent sessions. Anthropic. Checked 24 Oct 2026.
- Accelerating the Adoption of Software and AI Agent Identity and Authorization (NIST NCCoE concept paper). NIST. Checked 25 Oct 2026.
Check yourself
Check yourself
Question 1 of 13
You design the audit event for an agent's write. Which field set fits?
Your first check counts towards your result.