Audit Logging
Immutable logs of prompts, tool calls, and approvals for forensics and compliance.
In plain words
An audit log is a permanent diary of what the AI and its users did, saved safely so nobody can quietly change it, which helps find out what went wrong later.
Think of it like…
A flight data recorder and cockpit logbook: an independent, tamper-resistant record of what instruments showed and who did what, kept apart from the aircraft's operating systems and examined only under controlled procedures.
Where you’ve seen it
A platform handles 1,000,000 AI requests a day and writes about 6 audit events per request (request, retrieval, each tool call, policy decision, approval, response), 1.5 KB each: 9 GB a day, 3.3 TB a year (9 GB × 365). Events go to an append-only stream, are batched into object storage with object-lock (WORM) retention, and each record contains a SHA-256 hash of the previous record so tampering or deletion breaks the chain and is detected by a nightly verifier. The storage cost for the first year's 3.3 TB at an illustrative $0.023 per GB-month is about $76 a month at year end, falling when older data moves to an archive tier; policy keeps 13 months searchable and 7 years archived for financial actions, with prompts and outputs redacted for PII and secrets. Access is limited to a security group, every read of the log is itself logged and an incident query ("show all refunds approved by user X on 2026-11-10 with the retrieved documents") returns in seconds. During a dispute the team reconstructs a refund from the audit trail: user request hash, retrieved policy chunk ids, the tool arguments, the approval by a named reviewer and the model and prompt versions.
Words you’ll hear
- Immutable / WORM log
- Write-once-read-many storage that prevents alteration or deletion during retention.
- Hash chain
- Each entry includes a hash of the previous one so tampering is detectable.
- Delegation chain
- The recorded path from user to agent to tool for each action.
- Retention policy
- How long different log classes are kept and when they are deleted or archived.
Visual diagram
Theory & deep dive
What to record
Design an event schema with common fields on every record: timestamp, event id, trace id linking events of one request, actor identity (user id, agent id, service account, delegated scopes), tenant, environment and versions (application, model, prompt template, policy). Event types: request received (with a hash or redacted copy of the input, channel, IP or device); retrieval (query, filters, returned document ids and ACL decisions, not necessarily full text); model call (model id, parameters, token counts, finish reason, safety verdicts); tool call (tool name, validated arguments, authorisation decision, result summary or hash, duration, errors); policy and guardrail decisions (rule triggered, action, score); approvals (approver, parameters shown, decision, time); and response delivered (hash or redacted output). Record decisions and their reasons, not only outcomes.
Balance completeness with privacy. Full prompts and completions can contain personal data and secrets, so the default should be hashes, identifiers and redacted excerpts, with full-content capture limited to specific risk tiers or short retention and stricter access. Keep audit logs separate from application debug logs (different retention, access and integrity guarantees) and make clock sources reliable (NTP, monotonic sequence numbers). For agents, log the delegation chain so you can say "Alice asked the HR assistant, which called get_payroll with scope payroll:read:self and was denied".
{"ts": "2026-11-20T09:14:03Z", "trace": "b19f", "actor": {"user": "alice", "agent": "hr-assistant"}, "tool": "get_payroll", "args": {"employee_id": "bob"}, "authz": "deny: scope", "model": "m-5", "prompt_v": "v14", "prev_hash": "9a7c…"}
Integrity, retention, access and use
Integrity: write events to an append-only pipeline and store them in WORM storage (S3 Object Lock, immutable blob policies, ledger databases); add a hash chain or periodic signed checkpoints so tampering is detectable; send a copy to a separate account or system so that an attacker who compromises the application can't erase their trail. Retention: set classes (security and financial actions: years; routine chat telemetry: weeks), align with legal requirements and your privacy policy, and automate deletion or archive tiers when the time expires. Plan capacity: 1,000,000 requests × 6 events × 1.5 KB = 9 GB a day (3.3 TB a year); tiered storage and compression control cost.
Access and use: restrict read access to a small group, require justification for sensitive queries, log all reads of the audit log, and provide self-service queries for investigations (by user, tool, tenant, time, approval). Integrate with alerting (denied authorisations spike, unusual tool use, approvals by the same person at odd hours), incident response runbooks and compliance reporting (access reviews, SOC 2 or ISO evidence). Test the system: can you reconstruct a specific refund end to end? Does the verifier detect a deleted record? Do redaction rules hold? Remember audit logs themselves are personal data in many regimes: apply minimisation, subject-access and deletion rules where required (often via pseudonymous ids).
6 events × 1.5 KB = 9 KB per request; × 1,000,000 = 9 GB a day; × 365 = 3.285 TB a year. At about $0.023 per GB-month, 3,285 GB costs about $75.6 a month at the end of year one; archive tiers cut older data to a fraction of that.
How it works, step by step
Step 1 of 41. Define the event schema
Specify common fields, event types, identities, versions and delegation chain; decide what content to hash or redact.
- Separate
- from debug logs
When to use it & trade-offs
What it is
Audit logging for AI systems is an append-only, tamper-evident record of who did what: which user and agent identity made a request, which model and prompt versions ran, which documents were retrieved, which tools were called with what arguments and results, which policy decisions and approvals were made and what output was returned. It differs from debug logging in purpose (forensics, accountability, compliance, dispute resolution), in integrity (immutable storage, hash chaining, restricted access) and in privacy handling (redacted content, retention limits). Good audit logs let you answer "what happened, to whom, on whose authority and why?" long after an incident.
Why it matters: When an agent sends the wrong email, refunds the wrong order or leaks a document, the first questions are factual: which prompt, which retrieved context, which tool call, who approved it? Without a trustworthy record you can't investigate, notify, fix or prove compliance. Because prompts and outputs contain sensitive data, audit logging must also be designed not to create a new leak: capture enough to reconstruct events while redacting, encrypting and limiting access.
When to reach for it
- Investigating incidents and disputes
- Demonstrating compliance and access reviews
- Monitoring agent actions and approvals
When to avoid or be careful
- Storing full prompts indefinitely with broad access
- Mutable logs that an attacker could edit
- Logging outcomes without the decision and reason
Logging types
Strengths: Immutable, structured, access-controlled.
Watch out: Storage and governance effort.
Strengths: Detailed; flexible.
Watch out: Mutable, short-lived and often too sensitive.
Strengths: Aggregate visibility; low cost.
Watch out: Not a legal record; sampled.
Interview signals & numbers to know
When this topic comes up
- “Who approved that action?”
- Immutable logs
- Hash chaining
- Delegation chain
- Log retention
Benchmarks & rules of thumb
- 9 GB/day · 3.3 TB/year
- volume from 1M requests × 6 events × 1.5 KB
- ~$76/month
- storage cost for 3.3 TB at $0.023 per GB-month
- 13 months / 7 years
- example hot and archive retention
Common mistakes & follow-ups
Common interview mistakes
- Logging raw sensitive prompts to a tool that engineers can freely search.
- Not recording model and prompt versions, making incidents unreproducible.
- Keeping the log in the same account an attacker could compromise.
Likely interviewer follow-ups
- What would you include in an audit log for an agent?
- How do you make logs tamper-evident?
- How do you balance auditability with privacy?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply Audit Logging with generative AI interview Q&A and hands-on practice.