Guide / AI engineering Fundamentals
AI safety, privacy and compliance engineering
PII handling in LLM pipelines, data residency, audit logging, access control for retrieval, retention and deletion, regulated-domain controls and a practical review checklist.
Enterprise AI is judged on trust. Interviewers for regulated companies (banking, health, HR) expect concrete controls, not “we follow best practices”.
Fundamentals#
P.1 Data flow map#
Start every answer by tracing where data goes: user input → app → (redaction) → LLM provider/self-hosted model → logs/traces → vector store → caches → analytics → backups. Each hop is a place PII, secrets or confidential documents can leak or be retained. Classify data (public, internal, confidential, regulated) and decide what may reach which hop.
P.2 PII and sensitive data#
- Detect and redact before sending to a third-party model or logging: NER/regex/classifier tools (Microsoft Presidio, cloud DLP). Replace with reversible placeholders (
<PERSON_1>), keep the mapping in a secured vault, and restore in the response if needed. - Minimise: send only fields the task needs; truncate documents; avoid whole-record dumps.
- Provider terms: zero-data-retention and no-training agreements, regional endpoints, business associate agreements (HIPAA) or DPAs (GDPR); confirm sub-processors.
- Logs and traces: mask PII, restrict access, short retention; observability tools often become the biggest leak.
- Embeddings are not anonymous: vectors can leak information about the text; protect the vector store like the source data.
- Fine-tuning data: scrub PII and secrets first; models can memorise and regurgitate.
P.3 Access control in retrieval and tools#
The model must never see data the current user may not see: apply ACL filters in the retrieval query (tenant, group, document-level permissions synced from the source system), not after generation; propagate end-user identity to tools (on-behalf-of tokens), enforce least privilege per tool, and test with cross-tenant probes. Cached answers and semantic caches must be keyed by permission scope or they leak across users (RAG, LLMOps).
P.4 Data residency and sovereignty#
Keep data in required regions: region-pinned model endpoints or self-hosted models in-region, region-specific vector stores and logs, no cross-region replication of regulated data, and a routing layer that picks the region by tenant policy. Document the data path for auditors.
P.5 Audit, retention and deletion#
- Audit log: who asked what, which documents/tools were used, which model and prompt version answered, what was returned, approvals, with tamper-evident storage and strict access.
- Retention policies per data class; automatic expiry of conversations, caches, traces.
- Right to erasure: delete or crypto-shred user data across the primary DB, vector index (delete by metadata filter), caches, search indexes, logs, analytics copies, and training/fine-tuning sets; backups per policy (Senior questions).
- Consent and purpose limitation: use data only for the purposes consented to; no silent training on customer data.
P.6 Safety controls#
Input guardrails (prompt injection detection, PII, jailbreak patterns, size limits), output guardrails (policy classifiers, groundedness checks, PII leak checks, format validation), refusal behaviour tests, human-in-the-loop for high-impact decisions, rate limiting and abuse detection, content moderation for user-generated inputs. Defence in depth: guardrail models are probabilistic; hard controls (permissions, allowlists, approvals) must not depend on the model’s compliance (Prompt injection).
P.7 Regulation cheat sheet#
| Regime | Core points for AI systems |
|---|---|
| GDPR / UK GDPR / India DPDP | Lawful basis and consent, data minimisation, purpose limitation, access/erasure rights, DPIAs for high-risk processing, cross-border transfer rules, breach notification |
| HIPAA (US health) | PHI safeguards, BAAs with vendors, audit controls, minimum necessary |
| PCI-DSS | Never send card data to LLMs or logs; tokenise |
| SOC 2 / ISO 27001 | Access control, change management, logging, vendor management evidence |
| EU AI Act | Risk tiers (prohibited, high-risk, limited, minimal), transparency duties (disclose AI interaction/generated content), documentation and human oversight for high-risk uses |
| Sector rules (finance model risk management, hiring fairness laws) | Explainability, bias testing, audit trails, human review for consequential decisions |
State obligations generally and say you would confirm with legal/compliance; do not present this as legal advice.
P.8 Responsible AI engineering#
Bias and fairness testing across groups on your eval set; transparency (tell users they talk to AI, show sources and confidence); human escalation paths; model/system cards and data documentation; incident response for harmful outputs (kill switch, rollback, disclosure); monitoring for misuse; copyright and licensing review of training and retrieval corpora.
P.9 Review checklist#
- Data map and classification done? 2. PII redacted before external calls and from logs? 3. Provider contracts (retention, residency, sub-processors) verified? 4. ACLs enforced inside retrieval and tools? 5. Cache and memory scoped by tenant/permission? 6. Prompt-injection and tool-abuse tests in CI? 7. Human approval on irreversible actions? 8. Audit logging and retention/deletion pipelines? 9. Eval coverage for safety and fairness? 10. Incident runbook and kill switch?
Most asked questions#
1. How do you handle PII with third-party LLMs? Detect and redact or tokenise before the call, use zero-retention terms and regional endpoints, minimise fields, mask logs, and restore placeholders after.
2. How do you enforce document permissions in RAG? Store ACL metadata with chunks, filter in the retrieval query using the caller’s identity, never post-filter after generation, and sync permission changes quickly.
3. How do you meet data residency requirements? Region-pinned endpoints/self-hosting, region-local stores and logs, tenant-based routing, no cross-region replication of regulated data.
4. How do you support deletion requests? Track data lineage across stores, delete by user/tenant keys from DB, vector index, caches, logs and datasets, and verify.
5. What goes in an AI audit log? Identity, inputs and outputs (redacted), retrieved sources, tool calls, model and prompt versions, approvals, timestamps.
Senior-level questions#
1. “The semantic cache served one customer’s answer to another.” Cache keys missed tenant/permission scope. Scope by tenant and ACL hash, avoid caching personalised answers, add leak tests, and purge affected entries with incident disclosure.
2. “Legal asks: can you prove no customer data trained a model?” Provider no-training commitments and contracts, technical controls (separate fine-tuning data pipelines with consent flags), lineage records, and audits; for self-hosted, access controls on training storage.
3. “How do you balance debugging with privacy in LLM traces?” Redact at the SDK, store traces in a restricted system with short retention, sample, role-based access with justification, and use synthetic or scrubbed replays for debugging.
4. “Design AI for loan decisions.” Human-in-the-loop for decisions, explainable features and reasons, fairness testing and monitoring, immutable audit, model risk management documentation, and avoid free-form LLM output as the decision itself (LLM assists, rules/models decide).
5. “A jailbreak exposes the system prompt.” Assume system prompts are not secret; keep no credentials or sensitive logic in them; enforce authorisation outside the model.
Quiz#
1. Where must ACL filtering for RAG happen?
In the retrieval query, before any content reaches the model.
2. Are embeddings safe to treat as anonymised?
No. They can leak information; protect them like the source data.
3. What is crypto-shredding?
Encrypting data with per-user keys and deleting the key to make the data unrecoverable.
4. Why reversible placeholders for PII?
The model can still reason about entities without seeing real values, and the application can restore them in the final output.
5. Why not rely on guardrail models alone?
They are probabilistic and bypassable; hard controls like permissions, allowlists and approvals must enforce safety.