Prompt
I'm building multi-tenant AI features and need isolation plus audit logs
Latest observation
Oct 9, 2026
OpenAI APIWeb search: off
For multi-tenant AI features, you generally want to design for tenant isolation by default and auditability everywhere. A practical approach looks like this:
1) Tenant isolation
Use the tenant as a first-class security boundary.
- Hard tenant scoping on every request, query, storage write, and retrieval step.
- Prefer separate data partitions per tenant:
- separate database/schema if feasible
- at minimum, a
tenant_idon every record plus row-level access controls
- Ensure AI-specific stores are isolated too:
- prompts
- completions
- embeddings/vector indexes
- uploaded files / documents
- tool outputs
- caches and session state
Key rules
- Never let the model “decide” tenant scope.
- Resolve tenant from authenticated context only.
- Enforce isolation in the app layer and the storage layer.
- If using RAG, filter retrieval by tenant before any similarity search or after as a defense-in-depth measure.
2) Audit logs
Record a tamper-resistant trail for anything relevant to data access or model actions.
Log these events
- user login / token issuance
- prompt submission
- retrieved documents/chunks
- model/provider used
- tool calls and tool outputs
- data exports
- admin actions
- permission changes
- failures/denials
- configuration changes
Include these fields
- timestamp
- tenant_id
- user_id / service principal
- request_id / trace_id
- action type
- resource identifiers
- decision/result
- source IP / device info if appropriate
- model name/version
- prompt/template version
- moderation/safety decision
- latency and cost metadata
3) Protect sensitive content in logs
Audit logs should be useful, but not leak data.
- Avoid logging raw prompts/responses by default.
- If you must, redact or hash sensitive fields.
- Store only references to large payloads, not full content.
- Separate operational logs from security/audit logs.
- Apply retention and access controls to logs too.
4) Access control and least privilege
- Use RBAC/ABAC with tenant-aware policies.
- Separate roles for:
- tenant admin
- end user
- support
- internal operator
- Support staff should need explicit break-glass access with audit trails.
5) Encryption and secrets
- Encrypt data in transit and at rest.
- Consider per-tenant encryption keys or envelope encryption.
- Rotate secrets and API keys.
- Never expose provider keys to tenant-facing clients.
6) Model/data safety
- Don’t train shared models on tenant data unless explicitly allowed.
- If using fine-tuning or memory, isolate by tenant.
- Prevent cross-tenant prompt injection by:
- tenant-filtered retrieval
- tool allowlists
- strict system prompts
- output validation
7) Operational controls
- Rate limit per tenant.
- Quotas for tokens, requests, file sizes, retrieval depth.
- Alert on unusual access patterns.
- Regularly test isolation with cross-tenant negative tests.
8) Suggested architecture pattern
A good baseline architecture is:
- Auth layer identifies user and tenant.
- Policy layer checks permissions.
- Orchestrator receives request with tenant context.
- Data access layer enforces tenant filters.
- AI pipeline uses only tenant-scoped context.
- Audit logger writes immutable event records asynchronously.
- Monitoring/SIEM consumes logs for alerting.
If you want, I can turn this into:
- a reference architecture diagram,
- a security checklist, or
- a sample audit-log schema for your AI platform.