Audit Logging System Design for SaaS for AI SaaS
AI SaaS products have a logging problem that traditional SaaS never had to solve. When your product calls a language model, you are generating outputs that can be wrong, biased, harmful, or legally problematic — and you often cannot reproduce them exactly because model behavior changes between versions. When a customer asks why your AI said something, or a regulator asks what inputs were used to generate a decision, you need a complete, tamper-evident record.
This guide covers audit logging architecture specifically for AI SaaS products — what to log, how to structure it, and how to build a system that satisfies both compliance requirements and operational debugging needs.
Why AI SaaS Needs a Different Audit Log Design
Traditional SaaS audit logs capture who did what to which resource: user Alice updated billing plan, user Bob deleted document. The log is a trail of user actions on a deterministic system.
AI SaaS breaks both assumptions. The "action" is often the system generating content on the user's behalf — a prompt sent to a model, a RAG pipeline retrieving documents, an agent taking actions autonomously. And the system is not deterministic: the same prompt sent twice may produce different outputs, making reproduction impossible without having logged the original.
The Three New Categories of AI Audit Events
- Inference events — model calls with inputs, outputs, model version, latency, and token counts
- Retrieval events — documents retrieved from vector stores, search queries, relevance scores, and document sources
- Agentic action events — tool calls made by agents, parameters used, results returned, and any state changes made on external systems
These events do not exist in traditional SaaS. Your audit log schema needs to accommodate them alongside the standard user-action events your platform already captures.
What to Log for Each AI Event Type
Inference Event Log Schema
Every model call should produce an audit log entry containing:
- Event ID — unique, immutable identifier for this inference call
- Timestamp — Unix milliseconds, server-side (not client-side)
- Account ID and User ID — who triggered the inference
- Session or conversation ID — groups related turns in a conversation
- Model identifier — model name and version (e.g.,
gpt-4o-2024-11-20) - Input — the full prompt as sent to the model, after system prompt assembly and variable substitution
- Output — the full model response, before any post-processing
- Token counts — prompt tokens, completion tokens, total tokens
- Latency — time from request to response in milliseconds
- Temperature and sampling parameters — the exact parameters used for this call
- Feature context — which product feature triggered this inference (e.g.,
email-composer,code-review)
Retrieval Event Log Schema
For RAG pipelines, log each retrieval call separately from inference:
- Query — the text or embedding used to retrieve documents
- Retrieved document IDs — references to source documents, not their full content
- Relevance scores — the similarity scores returned by the vector store
- Filter criteria — any metadata filters applied (e.g., restricted to account-owned documents)
- Retrieval latency — time for the vector search to complete
- Linked inference event ID — connects the retrieval to the downstream model call
Agentic Action Log Schema
For agents that take actions on external systems:
- Tool name — which tool was called
- Input parameters — exact parameters passed to the tool (sanitize sensitive values like API keys)
- Output / result — what the tool returned
- External system affected — which system was modified (e.g.,
google-calendar,github-api) - Reversibility — flag whether this action is reversible
- User authorization — was this action explicitly authorized by the user or autonomous?
Immutability and Tamper Evidence
Audit logs are only valuable if they cannot be altered after the fact. For AI SaaS specifically, this matters because: a model might have generated harmful content that you need to investigate, a regulatory inquiry might require proving exactly what inputs were used, and a customer dispute might hinge on what your AI actually said.
Append-Only Storage
Your audit log database should be write-once, never update, never delete. Implement this at the infrastructure level, not just the application level. Options:
- Dedicated append-only tables with no UPDATE or DELETE permissions for application database roles
- Write to object storage (S3/GCS) with Object Lock enabled for compliance-grade immutability
- Purpose-built audit log services like Immudb that provide cryptographic immutability proofs
Event Hashing
Hash each audit event (SHA-256 of the event contents) and store the hash alongside the event. For critical audit events, chain the hashes — include the previous event's hash in the next event's content before hashing. This creates a tamper-evident chain where modifying any event invalidates all subsequent hashes.
This is the same principle used in blockchain systems, but you do not need a blockchain — a simple linked-hash approach implemented in your application layer is sufficient for most compliance requirements.
Retention Architecture for High-Volume Inference Logs
AI inference logs are high-volume. A product processing 100,000 API calls per day, each generating an average 2KB log entry, produces 200MB of audit data daily — 73GB per year. Design a tiered retention architecture from the start.
Hot Tier (0-30 days)
Store in your primary database or a fast OLAP store (ClickHouse, BigQuery). This tier is for operational debugging, customer support queries, and real-time compliance dashboards. Query access must be fast.
Warm Tier (30-365 days)
Move to lower-cost columnar storage (Parquet files in S3/GCS, or a compressed ClickHouse partition). Still queryable, but queries take longer. This tier handles regulatory inquiries that look back 6-12 months.
Cold Tier (1-7 years)
Archive to low-cost object storage with Object Lock. Not queryable directly — requires loading to a query engine. Retained for legal holds, long-term compliance requirements, and historical model performance analysis.
What to Retain and for How Long
Do not retain all inference data at the same tier for the same duration. Full prompt/response pairs: 90 days hot, 1 year warm, then delete or archive cold based on your compliance requirements. Metadata-only (token counts, latency, model version): retain indefinitely for billing reconciliation and model performance trending.
Emerging Compliance Requirements for AI Products
The regulatory landscape for AI products is evolving rapidly. Even at the seed stage, design your audit logging with the likely requirements in mind.
EU AI Act
High-risk AI systems (hiring, credit, education, essential services) must maintain detailed logs of system operation sufficient to trace outputs back to inputs. If your AI product operates in these categories, full inference logging with long retention is not optional.
Data Residency
Audit logs containing user data must comply with the same data residency requirements as the primary user data. If you store EU user data in the EU, their inference logs must also stay in the EU. Design your logging pipeline with regional routing from the start.
Right to Explanation
GDPR's right to explanation means users can ask why an automated decision was made about them. Your audit log is the technical foundation of your explanation capability. Log enough context that you can reconstruct the relevant prompt, retrieved documents, and model output for any decision your system made.