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:
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:
When
pii_method="tokenize", the mapping is stored in doc.metadata["blindfold_mapping"] so you can restore originals later.
Policies
See Policies for details.
PII Methods
Thepii_method parameter controls how detected PII is protected (applies to BlindfoldPIITransformer):
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:
See Regions for details.
Links
PyPI Package
Install from PyPI
GitHub
Source code and issues
LangChain Docs
LangChain documentation
Cookbook Examples
Working integration examples