Background: LLM Data Leakage Isn’t Just in Model Responses
When enterprises integrate LLMs into customer service, contract review, knowledge base Q&A, development assistants, ticket summarization, and sales operations, the most underestimated risk isn’t “will the model hallucinate,” but how much unnecessary sensitive data is being carried in the request chain.
A user might include their name, phone number, ID number, last four digits of a bank card, home address, medical condition description, contract amount, employee ID, or customer ID in their query. Business systems may also automatically concatenate CRM fields, order fields, original emails, ticket notes, and debug context when constructing prompts. If this content goes directly into the model API, application logs, traces, prompt replay platforms, or manual review queues, it creates multiple leakage paths.
This problem can’t be solved with a single system prompt. A system prompt can ask the model not to leak sensitive information, but it cannot prevent sensitive fields from entering a third-party model, logging system, or observability platform before the request is even sent. A more robust approach is to place a privacy redaction gateway before the LLM call chain, turning “what can be sent, how much, how to substitute, where it can be restored, and what logs retain” into auditable engineering policies.
Core Principles: Data Minimization First, Controlled Substitution Second
1. Identification: Locating PII in Plain Text
PII identification is not a single regex problem. Different categories of sensitive data require different detection methods:
| Detector Type | Use Case | Typical Entities |
|---|---|---|
| Deterministic Detector | Stable format data | Email, phone number, URL, IP, bank card, ID number, key fragments |
| Semantic Detector | Context-sensitive entities | Name, location, organization, job title, medical description, family relationships |
| Business Detector | Internal enterprise fields | Customer ID, policy number, order number, employee ID, contract number, channel code |
The identification phase should not just output “hit/miss.” It should also output entity type, start and end positions, confidence score, detector source, rule version, and whether manual review is needed. This metadata determines whether to delete, mask, pseudonymize, or retain the data.
2. Minimization: Not All Fields Should Enter the Model
The first principle of privacy governance is data minimization. Before calling the model, ask: does this task really need these sensitive fields?
- When asking the model to “summarize the complaint reason,” the customer’s name, phone number, and ID number can usually be deleted
- When asking the model to “determine if a user meets a certain age rule,” you don’t need to pass the full birthdate; an age range will do
- When asking the model to “generate a claim materials checklist,” you might need the policy type, accident type, and material status, but not the bank card number
The gateway should not default to “replace everything after identification.” Instead, it should configure minimization policies based on task type:
task_policy: claim_material_summary
allow_entities:
- POLICY_TYPE
- ACCIDENT_TYPE
- MATERIAL_STATUS
transform_entities:
PERSON: pseudonymize
PHONE_NUMBER: redact
ID_CARD: redact
BANK_CARD: redact
log_level: metadata_only
The value of such configuration is turning prompt privacy governance from an individual developer habit into an auditable, replayable, and grayscale-deployable policy.
3. Substitution: Choosing Between Irreversible Deletion and Reversible Pseudonymization
There are four common ways to handle PII:
| Method | Use Case | Example |
|---|---|---|
| Deletion | Fields that are completely unnecessary | ”Phone: 138xxxx” → remove entirely |
| Masking | Need to recognize the general form but not the full value | 138****5678 |
| Fixed Label Replacement | Model only needs to know the entity category | ”Zhang San” → [PERSON] |
| Reversible Substitution | Model needs to maintain contextual consistency | ”Zhang San” → PERSON_001, “A Company in Guangzhou” → ORG_001 |
The key to reversible substitution is that the mapping table must not reside in the same security domain as the prompt, logs, or traces. If you write the original text, the substituted text, and the mapping table together into logs, you haven’t actually reduced risk—you’ve just changed the format of the leak.
{
"request_id": "req_20260709_0001",
"tenant_id": "tenant_a",
"entity_map_ref": "vault://llm-redaction-map/7f3a...",
"redacted_prompt": "Please summarize PERSON_001's complaint. Contact number has been omitted.",
"entities": [
{"type": "PERSON", "token": "PERSON_001", "confidence": 0.93},
{"type": "PHONE_NUMBER", "token": "[REDACTED]", "confidence": 0.99}
]
}
4. Response Re-injection: Restoring Real Values Only Where Necessary
Some business scenarios require the model to generate text that can be directly sent to users. In these cases, reversible substitution creates a problem: the model output may contain placeholders like PERSON_001 or ORG_002.
Production systems should not allow the frontend to arbitrarily use the mapping table for re-injection. The correct approach is to place re-injection in a post-processing service, where policies determine which fields can be restored, to whom, and through which channel:
- Internal customer service agent workstations can see the real customer name
- External SMS templates cannot contain full ID numbers
- Exported review materials can only show masked phone numbers
This means the redaction gateway must manage not only pre-request processing, but also post-response processing and channel-level restoration policies.
Engineering Implementation: Making the Privacy Redaction Gateway a Data Plane Capability
Architecture Placement
The recommended architecture is: the business service first generates a structured LLM request, then passes it to the privacy redaction gateway. The gateway performs task identification, PII detection, policy decision, text rewriting, and audit logging before calling the model gateway or model provider.
Business Service → LLM Privacy Gateway
→ Task Policy Resolver
→ PII Detector
→ Redaction / Pseudonymization Engine
→ Mapping Vault
→ Minimal Logging Adapter
→ LLM Provider / Model Gateway
→ Response Post-Processor
→ Business Channel
Do not scatter redaction logic across individual business services. Decentralized implementation creates three problems: inconsistent rule versions, inconsistent logging standards, and the inability to prove which requests were processed after an incident.
Request Object Design
The gateway should handle structured requests, not just a single prompt string:
{
"tenant_id": "tenant_a",
"app_id": "support_assistant",
"task_type": "ticket_summary",
"messages": [
{"role": "system", "content": "You are a customer service quality inspection assistant."},
{"role": "user", "content": "Customer Zhang San reported that phone number 13800000000 cannot log in."}
],
"business_context": {
"ticket_id": "T20260709001",
"channel": "internal_console"
},
"privacy_profile": "support_default"
}
Structured requests allow different policies for different sources: strict detection for User Input, no customer data in System Instructions, tool-type-based processing for Tool Results, and cross-tenant or privilege-escalation checks for Retrieved Context.
Policy Versioning and Canary Deployments
PII detection and redaction policies will evolve continuously. New detectors may reduce missed detections but also increase false positives. Production systems should treat policies as deployable configurations, not hardcoded logic.
At a minimum, record: policy_version, detector_version, model_version, replacement_strategy, and decision_trace. When a user reports “the model’s answer is incomplete” or the security team finds “a certain type of ID number was missed,” you can replay the same request and compare the effects of old and new policies.
Log Minimization
Many teams complete request redaction but then log the original prompt, directly negating the redaction benefits. LLM pipeline logs should be divided into three layers:
| Log Level | Content | Purpose |
|---|---|---|
| Metric Logs | Request count, PII hit count, entity type distribution, block count, substitution count, latency, token count | Monitoring and alerting |
| Audit Logs | Request ID, tenant, application, policy version, action type, entity type, re-injection status, operator | Compliance auditing |
| Isolated Sample Logs | Small sample of pre- and post-redaction comparisons, stored only in a secure domain | Detector quality evaluation |
Default application logs, traces, error stacks, and APM breadcrumbs should not contain the original prompt.
Applicable Scenarios
The privacy redaction gateway is suitable for:
- Customer service, tickets, email summaries, and contact centers: User natural language often contains names, phone numbers, addresses, order IDs, and complaint details
- Contracts, policies, claims, financial reviews, and medical Q&A: Documents contain highly sensitive fields; the model only needs partial business facts
- Enterprise internal Copilots: Employees may paste customer data, code keys, database connection strings, and internal links
- Multi-provider model calls: The same request may be routed to different providers; the redaction gateway keeps privacy policies stable on the enterprise side
Common Misconceptions
Misconception 1: If the Provider Promises Not to Train, No Redaction is Needed
A provider’s data usage commitment only reduces one part of the risk; it cannot replace the enterprise’s own minimization obligations. The request may still pass through proxies, logs, debugging platforms, manual troubleshooting, and internal data lakes. As long as unnecessary sensitive fields leave the business system, the exposure surface increases.
Misconception 2: The More Redaction, the Better
Over-redaction can degrade task quality. For example, in contract review, if all entities are replaced with the same [ORG], the model may not be able to determine liability attribution. In customer service conversations, if all times, locations, and order statuses are deleted, the model’s summary becomes vague. The correct goal is not “delete the most,” but expose the least data while meeting task quality requirements.
Misconception 3: Reversible Substitution is Risk-Free
The risk of reversible substitution centers on the mapping table, keys, permissions, and re-injection pipeline. If the mapping table is leaked together with the redacted text, an attacker can recover the original text. Therefore, the mapping table must be stored independently, encrypted, with minimal access rights, short retention periods, and every read must be logged.
Misconception 4: Only Check the Request, Not the Response
The model may repeat user input in its response, combine multiple fields, generate seemingly personal information, or output substitution tokens to someone who shouldn’t see them. The response side also requires detection, re-injection control, and channel filtering.
Go-Live Checklist
| Area | Check Item |
|---|---|
| Detectors | Cover business entities, general PII, and key-like information; have confidence thresholds; support allowlists; output hit explanations |
| Policies | Configure allowed fields, substitution methods, block conditions, log levels, and re-injection permissions per task type; support canary releases and rollbacks |
| Pipeline | Cover request, response, logs, traces, error stacks, prompt replay, manual review samples, and export tasks |
| Security | Mapping table stored independently; keys managed in KMS/HSM; tenant isolation; read audit logging; retention period set |
| Quality | Establish missed-detection sets, false-positive sets, and task quality regression sets; perform manual calibration with real redacted samples; monitor PII hit rate anomalies |
| Incident Response | Ability to query the original policy version by Request ID; ability to locate requests that used a faulty detector; ability to quickly disable a specific type of re-injection |
Should all detectors be turned on? Not recommended. Too many InfoTypes or detectors increase latency, cost, and false positives. A better approach is to configure detection scope per business scenario—login issues need phone numbers, emails, and accounts; contract review needs entities, addresses, and bank accounts; development assistants need keys, tokens, URLs, and internal hostnames.
Can the model itself determine what information is sensitive? The model can assist with interpretation and review, but it should not be the sole privacy boundary. The privacy gateway should use deterministic rules, NER, business dictionaries, policy configurations, and audit systems to build an explainable control plane. Model judgment can be used for low-confidence sample review, but the final action should be determined by the policy engine.