Use this file to discover all available pages before exploring further.
The 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.
from langchain_blindfold import blindfold_protectfrom langchain_core.prompts import ChatPromptTemplatefrom langchain_openai import ChatOpenAItokenize, detokenize = blindfold_protect(policy="basic")prompt = ChatPromptTemplate.from_messages([ ("system", "You are a helpful assistant."), ("user", "{input}"),])llm = ChatOpenAI(model="gpt-4o-mini")chain = tokenize | prompt | llm | (lambda msg: msg.content) | detokenize# PII is tokenized before the LLM sees it, then restored in the responseresult = chain.invoke("Write a follow-up email to John Doe at john@example.com")
The LLM only sees <Person_1> and <Email Address_1> — never the real data.
Convenience function that returns a paired tokenizer and detokenizer for use in chains:
tokenize, detokenize = blindfold_protect( api_key=None, # Falls back to BLINDFOLD_API_KEY env var region=None, # "eu" or "us" for data residency policy="basic", # Detection policy entities=None, # Specific entity types to detect score_threshold=None, # Confidence threshold (0.0-1.0))
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)
from langchain_blindfold import BlindfoldTokenizertokenizer = BlindfoldTokenizer(policy="gdpr_eu", region="eu")safe_text = tokenizer.invoke("Contact Hans at hans@example.de")# → "Contact <Person_1> at <Email Address_1>"