Today’s Lesson
Security for Legal SaaS — Episode 39: Redaction Pipelines for Cloud AI
Does the Cloud Need to See Your Client's Name?
In Episode 38, we built the inference gateway that controls access to cloud AI providers. This episode addresses what flows through that gateway: the actual content of your prompts. Before you send a contract, a legal memo, or a case summary to a cloud LLM, you should ask a simple question — does the AI provider actually need to see your client's name, their social security number, the dollar amount of the deal, or the names of the parties in litigation?
Usually, the answer is no. A cloud LLM can summarise a contract, extract obligations, or review clause language without knowing that the parties are Acme Corp and Baker Industries. It just needs the structure and the text. Everything else is a leak waiting to happen.
Why Redaction Matters for Legal AI
When you send a prompt to OpenAI, Anthropic, Google, or any other cloud LLM provider, that data leaves your network and enters the provider's infrastructure. Even with zero-data-retention agreements, the data traverses networks you don't control, is processed on hardware you don't own, and is subject to the provider's security posture — not yours.1
For legal data, this creates specific risks:
| Risk | Description | Legal Consequence |
|---|---|---|
| Privilege waiver | Privileged content shared with a third-party service | Potential waiver of attorney-client privilege (see EP36, Heppner) |
| Confidentiality breach | Client PII or deal terms accessible to the provider | Violation of ABA Model Rule 1.6(c), data protection regulations |
| Cross-contamination | Provider uses your data to improve models (if not contractually prohibited) | Client data influences outputs for other users |
| Subpoena exposure | Provider served with subpoena for data they hold | Your client's data produced in litigation involving the provider, not your client |
ABA Formal Opinion 512 specifically requires lawyers to understand "how GAI uses data" and to implement "adequate safeguards to ensure that data processed by GAI is secure."2 Technical redaction is one of the most direct safeguards available.
Named Entity Recognition: The Core Technology
Named Entity Recognition — NER — is a natural language processing technique that identifies and classifies specific entities in text: person names, organisation names, locations, dates, financial amounts, identification numbers, and other structured data. NER is the engine that powers automated redaction.
Modern NER systems use multiple approaches in combination:3
| Approach | How It Works | Strengths | Weaknesses |
|---|---|---|---|
| Rule-based (regex) | Pattern matching for structured data (SSNs, phone numbers, emails) | High precision on structured formats | Cannot handle unstructured names or context-dependent entities |
| Statistical NER models | Machine learning models trained on labelled text (spaCy, Flair) | Good general-purpose entity detection | May miss domain-specific entities (case numbers, matter IDs) |
| Transformer-based NER | Deep learning models (BERT, GLiNER) fine-tuned for entity recognition | Highest accuracy, context-aware | Computationally expensive; requires GPU for real-time use |
| Hybrid | Combines rules, statistical models, and transformers | Best overall performance | More complex to maintain and tune |
A recent study on financial documents reported that a hybrid NER approach achieved 94.7% precision, 89.4% recall, and an F1 score of 91.1%.4 Legal documents present similar challenges — a mix of structured identifiers (case numbers, statute references) and unstructured entities (party names, judge names) that require both pattern matching and contextual understanding.
Microsoft Presidio: An Open-Source Reference
Microsoft Presidio is the most widely adopted open-source PII redaction framework. It combines NER models (spaCy by default), regular expressions, and checksum validation to detect over 30 entity types including names, addresses, Social Security numbers, financial account numbers, and email addresses.5
Presidio's architecture has two components:
- Analyzer: Detects PII entities in text, returning their type, location, and confidence score
- Anonymizer: Replaces, masks, hashes, or encrypts detected entities based on configurable rules
Important caveat: Presidio's documentation explicitly states: "Because it is using automated detection mechanisms, there is no guarantee that Presidio will find all sensitive information."5 For legal applications, this means Presidio (or any automated tool) should be a first pass, not the only pass. Defence in depth applies to redaction too.
Configurable Redaction Levels
Not all prompts require the same level of redaction. A pipeline should support multiple levels depending on the data sensitivity and the task:
| Level | What's Redacted | Example | Use Case |
|---|---|---|---|
| Full redaction | All PII replaced with type tags | "The agreement between [ORG_1] and [ORG_2] dated [DATE_1]..." | Sending to cloud AI for clause analysis |
| Partial redaction | Names and identifiers redacted; dates and amounts preserved | "The agreement between [ORG_1] and [ORG_2] dated January 15, 2026 for $2.5M..." | Financial analysis where amounts matter |
| Pseudonymised | PII replaced with consistent fake values | "The agreement between Maple Corp and Pine Industries dated March 3, 2025..." | When the AI needs realistic-looking data for better results |
| None | No redaction (local model only) | Original text sent as-is | Self-hosted model within your network perimeter |
Pseudonymisation deserves special attention. Some AI tasks produce better results when the input looks like real data rather than placeholder tags. Replacing "[ORG_1]" with a consistent fake name like "Maple Corp" throughout the document preserves the readability that helps the LLM understand context — while ensuring the actual client name never reaches the cloud.6
Round-Trip Reconstruction: Redact, Send, Re-Hydrate
Redaction is only half the pipeline. When the AI returns its response, you need to map the redacted entities back to their real values — a process called re-hydration or reconstruction.
The Pipeline
1. Original document enters pipeline
2. NER identifies entities → stored in a REDACTION MAP (entity → placeholder)
3. Document redacted using the map
4. Redacted document sent to cloud LLM
5. LLM response received (contains placeholders)
6. Redaction map applied in reverse → real entities restored
7. Reconstructed response delivered to the user
The redaction map is the sensitive artefact. It must be stored securely — encrypted at rest, access-controlled, and never sent to the cloud provider. If the map is compromised, every redacted prompt can be reconstructed.7
Handling Edge Cases
| Edge Case | Problem | Solution |
|---|---|---|
| Entity in AI response not in original | LLM generates new entity references | Map only applies to known entities; new references pass through unchanged |
| Partial entity matches | "John" appears both as a name and in "St. John's Court" | Context-aware NER; maintain an exclusion list for legal terminology |
| Cross-reference consistency | Same entity must get the same placeholder across a multi-document prompt | Use deterministic mapping (e.g., hash-based) with a session-scoped map |
| Nested entities | "John Smith of Baker & McKenzie LLP" contains both a person and an organisation | Redact from longest match first; maintain entity hierarchy |
Contractual Protections vs. Technical Protections
Enterprise agreements with AI providers often include zero-data-retention clauses, prohibitions on using customer data for model training, and SOC 2 / ISO 27001 compliance attestations. These are important but insufficient on their own.8
| Protection Type | What It Covers | What It Doesn't Cover |
|---|---|---|
| Contractual (DPA, BAA) | Provider's obligations regarding data handling, breach notification, liability | Data in transit, provider-side vulnerabilities, subpoena exposure |
| Technical (redaction) | Prevents sensitive data from reaching the provider at all | Entities missed by NER, context that reveals sensitive information without named entities |
The strongest position is both: a contractual agreement that restricts data use, combined with technical redaction that ensures sensitive data never reaches the provider regardless of contract compliance. If the contract is breached, your data wasn't there to be exposed.
Building a Legal-Specific NER Model
Generic NER models miss legal-specific entities. Consider extending your redaction pipeline to detect:
- Matter numbers and case identifiers (e.g., "Case No. 2025-CV-04521")
- Court names and judge names that reveal jurisdiction and strategy
- Law firm names that reveal representation relationships
- Privilege designations ("Attorney-Client Privileged", "Work Product")
- IOLTA account numbers and trust account references
- Bar numbers and attorney registration identifiers
Tools like GLiNER support zero-shot NER — you define entity types without retraining the model — making it practical to add legal-specific entity types without a machine learning team.9
Practical Architecture
For a legal SaaS platform using cloud AI:
- Inference gateway (Episode 38) intercepts every outbound prompt
- NER pipeline scans the prompt, generates a redaction map, and redacts the text
- Redacted prompt is forwarded to the cloud LLM provider
- Response is received and re-hydrated using the redaction map
- Redaction map is stored encrypted, access-controlled, and retained per your data retention policy
- Audit log records what was redacted, when, and which provider received the redacted version
This pipeline adds latency — typically 100-500ms for NER processing depending on document length and model complexity. For most legal workflows (contract review, research, drafting), this latency is imperceptible.
What's Next
Episode 40 addresses Local vs. Cloud AI — Security Boundaries — the decision framework for when to send data to the cloud (with redaction) versus when to keep everything on premises by running the model locally.
Sources & Further Reading
Sources & references
- Prediction Guard, The Complete Guide to PII Detection and Redaction Tools for AI Pipelines in Regulated Industries.
- ABA, Formal Opinion 512: Generative Artificial Intelligence Tools (July 2024).
- Elastic Observability Labs, Using NLP and Pattern Matching to Detect, Assess, and Redact PII in Logs.
- Nature Scientific Reports, A Hybrid Rule-Based NLP and Machine Learning Approach for PII Detection and Anonymization in Financial Documents.
- Microsoft, Presidio: Data Protection and De-Identification SDK.
- Justee, Redact PII from Legal Documents for AI.
- Protecto, Comparing Best NER Models for PII Identification.
- Spellbook, Most Private AI for Lawyers: Why Zero Data Retention Wins in 2026.
- DEV Community, The Next Generation of Privacy: Using Docling & GLiNER's Advanced NER.
- Tonic.ai, Named Entity Recognition for Data Compliance Automation.
- Microsoft Learn, Transparency Note — Named Entity Recognition Feature of Azure AI Language.