Data leaks in AI SaaS happen when sensitive content slips into prompts, retrieval indexes, embeddings, logs, tool‑calls, or vendor pipes. Prevent them by constraining what models can see (permissioned retrieval and minimization), what they can do (typed, policy‑gated actions), and where data can go (egress controls and private inference). Make privacy observable with immutable decision logs, tenant‑scoped encrypted caches, and DSR‑aware deletion.
The main leak paths (and how to block them)
- Prompts and context windows
- Risk: Oversharing PII/PHI/PCI or secrets in inputs and augmented context.
- Controls:
- Data minimization: include only fields required; trim long threads; anchor snippets rather than dumping full docs.
- Redaction and masking: detect and mask PII/PHI/PCI and secrets before prompting; tokenize IDs.
- Context budgets and templates: hard limits on context size; allow only whitelisted fields per workflow.
- Retrieval and RAG indexes
- Risk: Cross‑tenant exposure, stale or mis‑scoped documents, poisoned content.
- Controls:
- Permissioned indexing and search: apply tenant/row‑level filters before embedding and again at query time.
- Provenance and freshness: store URI, owner, timestamp, jurisdiction; refuse on low/conflicting evidence and show citations.
- Content sanitization: strip active content (scripts), disallow embedded instructions; maintain source allowlists.
- Jurisdiction tags: prevent cross‑border retrieval when residency requires it.
- Embeddings and caches
- Risk: Sensitive information encoded, shared, or retained too long.
- Controls:
- Tenant‑scoped, encrypted stores with per‑tenant keys; never share vectors across tenants.
- Pre‑embedding redaction of sensitive spans; hashing/tokenizing direct identifiers.
- TTLs and DSR‑aware deletion: erasure propagates to vectors, caches, and indexes.
- Size and access limits: cap nearest‑neighbor results; log access with subject IDs.
- Tool‑calls and integrations
- Risk: Free‑text payloads to production systems causing over‑disclosure or writes to wrong records.
- Controls:
- Typed JSON Schemas for every action; strict validation; fail‑closed on unknown fields.
- Policy‑as‑code: eligibility, scopes, data egress rules, maker‑checker approvals, change windows.
- Simulation and diffs: preview what fields will leave the boundary; block if payload includes sensitive categories without purpose/consent.
- Vendor/model egress
- Risk: Sending data to external LLMs that log or train; cross‑region inference.
- Controls:
- Model gateway enforcing per‑tenant “no‑train” flags, region pinning, and VPC/private endpoints for sensitive flows.
- Egress allowlists and DNS/IP pinning; block wildcards; mutual TLS; payload minimization adapters.
- DPAs with retention and locality terms; periodic vendor audits and test calls to verify headers/flags.
- Logs, traces, and decision records
- Risk: Sensitive content lingering in observability systems or support tools.
- Controls:
- Structured logging with field‑level redaction; prohibit raw prompt/output dumps.
- Immutable decision logs with hashed references to sensitive content; access via break‑glass + audit.
- Short retention and automatic scrubbing of debug traces; environment‑based verbosity controls.
- Prompt‑/data‑injection and exfiltration
- Risk: Untrusted content instructs the model to leak secrets or bypass policies.
- Controls:
- Instruction firewalls: ignore in‑document instructions; system prompts that enforce “cite or refuse.”
- Output filters for secrets/PII; jailbreak and egress detectors; isolate untrusted HTML/links.
- Retrieval‑only constraint: ground responses strictly to permitted sources; refuse when evidence is missing.
Architecture blueprint (privacy‑first)
- Identity and scope
- SSO/OIDC + MFA; RBAC/ABAC and row‑level security; per‑request purpose and consent tags checked at retrieval and action time.
- Permissioned retrieval
- Vector + keyword hybrid with ACL filters; provenance, freshness, and jurisdiction tags; refusal defaults; citations in UI and logs.
- Model gateway and routing
- Central gateway with timeouts, quotas, budgets; small‑first routing; variant caps; region‑aware and private endpoints for sensitive workloads.
- Tool registry with policy‑as‑code
- JSON Schemas for all actions; simulation/preview; idempotency and rollback; egress rules encoded (what fields can leave, to which domains).
- Secure data plane
- Tenant‑scoped, encrypted caches and embeddings; per‑tenant keys (KMS/HSM); TTLs and DSR‑aware delete; content‑addressable storage with access logs.
- Observability and audit
- Decision logs linking input → evidence → action → outcome; masked fields; signer identities; exportable audit packs.
- Monitors for anomalous retrievals, cross‑tenant probes, token/variant spikes, and egress to non‑allowlisted domains.
Operational safeguards
- Privacy contract tests in CI
- Verify ACLs applied pre‑embedding and at query time; ensure redaction before storage; test region pinning and “no‑train” flags to model vendors.
- Golden evals with safety checks
- Grounding/citation coverage; refusal correctness; JSON/action validity; prompt‑injection and egress tests; fairness slices to avoid uneven leakage risk.
- Secrets hygiene
- Scan sources/prompts for secrets; rotate keys; short‑lived credentials; JIT elevation with audit.
- DSR automation
- Index prompts, outputs, embeddings, and logs by subject identifiers; implement erase/export across all stores; maintain suppression lists to prevent re‑ingest.
- Incident playbooks
- Kill switches for tools/models; prompt/model rollback; cache/index purge; key rotation; regulator/customer notification templates.
Implementation checklist (copy‑ready)
- Retrieval and prompts
- ACL filters pre‑embedding and at query time
- Provenance/freshness/jurisdiction tags; citations or refusal
- PII/PHI/secret redaction; context size caps
- Embeddings and caches
- Tenant‑scoped encrypted stores; per‑tenant keys
- TTLs and DSR‑aware deletion; access logging
- Pre‑embedding redaction; no cross‑tenant sharing
- Tools and egress
- JSON Schemas for actions; validation and simulation
- Policy‑as‑code gates (eligibility, approvals, egress rules)
- Egress allowlists; region pinning; no‑train flags; private endpoints
- Observability and logging
- Structured logs with redaction; masked decision logs
- Anomaly alerts (retrieval, tokens, variants, egress)
- Environment‑based debug retention
- Governance and rights
- DSR automation for prompts/outputs/embeddings/logs
- Vendor DPAs (locality, retention, no‑training)
- Secrets rotation cadence; least privilege; JIT access
Quick wins (30–60 days)
- Add tenant‑scoped encryption and TTLs to embeddings/caches; wire DSR deletions end‑to‑end.
- Enforce ACL checks pre‑embedding and at query time; show citations and refusal by default.
- Put all tool‑calls behind JSON Schema validation, simulation, and egress rules; remove any free‑text integrations.
- Centralize model access via a gateway with no‑train flags, region pinning, quotas, and budgets.
- Stand up privacy monitors and alerts: cross‑tenant queries, atypical retrieval breadth, token/variant spikes, non‑allowlisted egress.
Common pitfalls (and fixes)
- Indexing first, permissions later
- Block indexing without tenant/row filters; backfill with re‑embedding under ACLs; add synthetic boundary probes.
- Logging raw prompts/outputs
- Switch to structured, masked logs; shorten retention; gate debug dumps behind break‑glass.
- Free‑text actions to partner APIs
- Replace with typed schemas and policy gates; simulate and approve; audit egress fields.
- Cross‑border surprises
- Region‑pin indexes and inference; enforce routing policies; verify with CI probes and vendor headers.
- Embedding leakage
- Redact before embedding; encrypt and tenant‑scope vectors; TTL and DSR deletions; never share across tenants.
Bottom line: Preventing data leaks in AI SaaS is about strict scoping, minimization, and observability. Permission every retrieval, redact and limit prompts, encrypt and isolate embeddings, route through a policy‑enforcing model gateway, and execute only typed, simulated actions. Make privacy visible with citations, refusal, and decision logs—and verify it continuously with tests, monitors, and drills.