langchain-blindfold package integrates Blindfold with LangChain, letting you tokenize PII before it reaches your LLM and restore originals in the response. Includes chain-composable Runnables and a DocumentTransformer for RAG pipelines.
Installation
Quick Start
Protect a LangChain Chain
<Person_1> and <Email Address_1> — never the real data.
Transform Documents for RAG
Components
blindfold_protect()
Convenience function that returns a paired tokenizer and detokenizer for use in chains:
BlindfoldTokenizer
A LangChain Runnable that tokenizes PII in text and stores the mapping:
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | str | None | Falls back to BLINDFOLD_API_KEY env var |
region | str | None | "eu" or "us" for data residency |
policy | str | "basic" | Detection policy |
entities | list | None | Specific entity types to detect |
score_threshold | float | None | Confidence threshold (0.0–1.0) |
BlindfoldDetokenizer
A LangChain Runnable that restores original PII from tokenized text using the paired tokenizer’s mapping:
BlindfoldPIITransformer
A LangChain DocumentTransformer for protecting PII in documents:
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | str | None | Falls back to BLINDFOLD_API_KEY env var |
region | str | None | "eu" or "us" for data residency |
policy | str | "basic" | Detection policy |
pii_method | str | "tokenize" | How to protect PII |
entities | list | None | Specific entity types to detect |
score_threshold | float | None | Confidence threshold (0.0–1.0) |
pii_method="tokenize", the mapping is stored in doc.metadata["blindfold_mapping"] so you can restore originals later.
Policies
| Policy | Entities | Best For |
|---|---|---|
basic | Names, emails, phones, locations | General PII protection |
gdpr_eu | EU-specific: IBANs, addresses, dates of birth | GDPR compliance |
hipaa_us | PHI: SSNs, MRNs, medical terms | HIPAA compliance |
pci_dss | Card numbers, CVVs, expiry dates | PCI DSS compliance |
strict | All entity types, lower threshold | Maximum detection |
PII Methods
Thepii_method parameter controls how detected PII is protected (applies to BlindfoldPIITransformer):
| Method | Output | Reversible |
|---|---|---|
tokenize | <Person_1>, <Email Address_1> | Yes |
redact | PII removed entirely | No |
mask | J****oe, j****om | No |
hash | HASH_abc123 | No |
synthesize | Jane Smith, jane@example.org | No |
encrypt | AES-256 encrypted value | Yes (with key) |
Usage Examples
GDPR Compliance with EU Region
HIPAA — Redact PHI in Documents
Protect RAG Pipeline
Detect Specific Entity Types
Data Residency
Use theregion parameter to ensure PII is processed in a specific jurisdiction:
| Region | Endpoint | Location |
|---|---|---|
eu | eu-api.blindfold.dev | Frankfurt, Germany |
us | us-api.blindfold.dev | Virginia, US |