The Architecture of a PII-Safe LLM Pipeline
October 2, 2025
Financial institutions deal with PII constantly: client names, account numbers, transaction details, IBAN records. When you introduce LLMs into these workflows — for document processing, client support, compliance review — PII safety becomes a first-order architectural concern.
This is not a theoretical problem. LLMs are next-token predictors trained on broad corpora. They do not inherently distinguish between text you want them to use and text you do not want to leave the system. Without deliberate architectural controls, PII leaks in multiple directions: into third-party model API logs, into vector store indices, into LLM context windows that are logged or cached, and into model fine-tuning datasets.
Here is how we architect PII-safe LLM pipelines in production.
The Three Leak Vectors
1. Upstream: Data Ingestion and Indexing
When you index documents into a vector store for RAG retrieval, you are creating a persistent, queryable representation of your data. If those documents contain PII and your vector store is a shared service — or if your index is ever accessed by non-authorised retrieval queries — you have a persistent PII exposure.
The fix is to apply PII detection and redaction before indexing, not after. We use a combination of rule-based detection (regex patterns for IBANs, account numbers, national ID formats across EU jurisdictions) and model-based detection (NER models fine-tuned on financial documents) to identify and replace PII before any document enters the index.
Replacement strategy matters. Naïve redaction ([REDACTED]) destroys semantic coherence and degrades retrieval quality. We use structured pseudonymisation: replace Hans Müller with PERSON_001, DE89370400440532013000 with IBAN_001, maintaining a reversible mapping in a separately controlled store. The LLM sees coherent text; PII stays out of the pipeline.
2. Transit: The LLM Context Window
Even with clean indices, PII enters the LLM context window through user queries. A support agent pastes a client email into a query. A risk analyst submits a data extract for summarisation. The raw input contains PII that you did not put there.
We apply a pre-LLM scrubbing layer to every query before it reaches the model. This layer:
- Detects PII in the input using the same detection stack as the indexing pipeline
- Pseudonymises in-context, replacing detected entities with structured tokens
- Passes the scrubbed query to the LLM
- Post-processes the LLM response, reversing pseudonymisation for display to the authorised user only
The LLM therefore never processes real PII. Its context window — which may be logged, cached, or used for fine-tuning by third-party providers — contains only pseudonymised tokens.
3. Downstream: Third-Party Model APIs
If you are using a third-party LLM API (any major provider), your query data is transmitted to an external system. Under GDPR Article 4(7), if your queries contain PII, you are transferring personal data to a third-party processor. This requires a Data Processing Agreement and, if the provider is outside the EEA, an appropriate transfer mechanism.
The simplest architectural resolution is to ensure that no PII ever reaches the third-party API — which the scrubbing layer above provides. We also maintain a local, on-premise model as a fallback path for queries that the scrubbing layer cannot adequately clean, ensuring that sensitive data never leaves the institution's infrastructure.
The Pseudonymisation Store
Central to this architecture is the pseudonymisation store: the service that maintains the mapping between real entities and their tokens. This store:
- Must be access-controlled more strictly than the LLM pipeline itself — only the scrubbing and post-processing layers have read/write access
- Must be audited — every pseudonymisation and de-pseudonymisation event is logged
- Must be scoped to sessions, not persistent — a token
PERSON_001in one context should not resolve to the same person in an unrelated context - Must handle entity consistency — multiple mentions of the same entity within a document should map to the same token
We implement this as a lightweight in-process service with Redis-backed session scoping and a separate audit log stream.
Detection Quality
PII detection in financial documents requires domain-specific tuning. Standard NER models miss:
- German-specific formats (Steuer-ID, SEPA mandate references, BIC codes)
- Financial identifiers that are not traditionally classified as PII but are GDPR-relevant in financial context (LEI codes, order references that can be linked to individuals)
- Multi-part identifiers (name + account number combinations where neither alone is sensitive but together is)
We maintain a continuously updated detection library covering EU-jurisdiction PII formats and financial identifiers, with a false-negative rate target of <0.5% on our benchmark dataset. False negatives are more dangerous than false positives in this context — a missed IBAN is worse than an unnecessarily redacted number.
What This Looks Like in Production
A typical request-response cycle in our PII-safe pipeline:
- User submits query (may contain raw PII)
- Scrubbing layer processes input: detect → pseudonymise → return clean query + entity map
- Clean query + retrieved context (already clean from indexing pipeline) → LLM
- LLM response (contains pseudonym tokens) → post-processor
- Post-processor reverses pseudonymisation for authorised display
- Audit log records: session ID, entity count, tokens used, response latency — no raw PII
Total added latency from scrubbing layer: 15–40ms depending on document length. This is acceptable for all use cases we have encountered except sub-second trading applications, which typically should not route through LLMs anyway.
The Compliance Guarantee
This architecture provides:
- GDPR Article 25 compliance (data protection by design and by default) — PII is excluded from the AI pipeline at the point of entry
- Auditability — every entity processed is logged with session and access context
- Third-party safety — no PII reaches external model APIs
- Reversibility — pseudonymisation is reversible for authorised access paths, unlike irreversible anonymisation
The key insight is that PII safety in LLM pipelines is not about configuring your model differently — it is an architectural decision that must be made at the system design stage. Retrofitting PII safety onto a pipeline built without it is possible but expensive and never as reliable as having it built in from day one.
We build PII-safe AI pipelines as standard across all our financial services engagements. If you are designing an LLM system for a regulated environment, let's talk.