Audit, Detection, and Incident Response › Designing the audit record
Language AI HandbookAll chapters An audit event should identify the observed action and give a responder a way to find supporting evidence. Record an authorization decision separately from the evidence that its operation completed.
For each event, ask which identifiers will still resolve after the original investigation window. Record how to join related events across services and how to find the policy version that applied.
Every event should carry a common envelope plus type-specific fields. The common envelope is what lets you chain, correlate, and trust the records. It contains:
event_id: a unique event identifier (for example, a UUID generated for each event) so records can be cross-referenced.trace_id: a correlation identifier for events recorded under the same request or interaction. Record dependency links separately when the investigation needs them.timestamp: an event timestamp in UTC, plus receipt time or source-clock information when useful.actor: the principal that caused the event. Critically, agents have two principals: the requesting or delegating principal and the authenticated execution identity. Record both when delegation exists, because attribution questions ("did the user ask for this, or did the agent decide it?") are exactly the ones that matter in incidents. We covered this delegation structure in Identity, Authorization, and Least Privilege.action_type: a controlled-vocabulary label (retrieval,tool_call,model_completion,policy_decision,human_approval,credential_use,data_egress).decision: an inert enum label such asallow,deny,escalate. Storing the label rather than prose is what makes the trail machine-queryable.prev_hashandrecord_hash: the chaining fields we define next.
The requester and the executing identity may differ. Their identifiers help a responder retrieve the authorization grant and compare its scope with the observed operation. The policy and execution records provide the evidence for that comparison.
The decision field being an inert enum label rather than a prose string is also deliberate. A prose string ("looks fine to me") is not queryable, not comparable, and not aggregatable. An enum label (allow, deny, escalate) is queryable and aggregatable, which is what lets detection count denials per actor per hour and lets the response layer filter to a single decision class. The vocabulary must be controlled, meaning it lives in a shared schema rather than being composed ad hoc at each call site, so that "deny" means the same thing everywhere and new decisions cannot be smuggled in under near-synonyms.
For a tool_call, record the tool name, approved argument references or scoped digests, and the authority used. For retrieval, record an approved query reference when useful, returned document IDs and available provenance. Capture query content only under the protected retention policy. A policy_decision event records the decision and the policy version that produced it. Dataset Lineage and Provenance covers how to preserve provenance across stages.
Use an allowlist for queryable fields. When equality checks on approved arguments are necessary, use a keyed digest with an explicit key scope and rotation plan. An ordinary digest of a short list of possible values can reveal the original through guessing. OWASP Logging Cheat Sheet
What counts as "consequential"
A common failure is to log everything (trillions of token-level events) and then drown. The audit trail should capture consequential actions: state changes, external effects, permission uses, data egress, and the decision points that led to them. Token-level logging is a debugging concern, not an audit concern. The design principle is: if a competent responder would need to cite this event to reconstruct who did what and why, it belongs in the audit trail; if it is only useful for tuning, it does not.
The trap is that "log everything" feels safer than "log selectively," because logging everything cannot omit something important. But the feeling is deceptive for two reasons. First, volume destroys signal: an audit trail with a million token-level events per user turn is one in which no responder can find the three consequential events that matter, and practical detection becomes impossible. Second, "log everything" silently imports the privacy and storage problems at full severity, because the full context window now dominates the log volume and the sensitive-data store grows without bound. The selective principle is harder to apply than "log everything," because it requires making a judgment about consequence, but it produces a trail that is at once more useful and more defensible.
The judgment "consequential" can be made reliably by asking a single question of each candidate event: could this event change the answer to "what did the agent do and why" in an investigation? A tool call changes the answer. A retrieval changes the answer. A decision to deny changes the answer. A token sampled inside a completion does not change the answer, because the completion's outcome is already recorded by the model_completion event; the token stream is how that outcome was produced, not what it was. When the boundary is ambiguous, the tie goes to including the event, because a slightly verbose trail is recoverable by filtering and a missing event is not recoverable at all.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!