PresidioDocumentCleaner
Remove personally identifiable information (PII) from Haystack Document objects using Microsoft Presidio, replacing detected entities with type placeholders such as <PERSON> or <EMAIL_ADDRESS>.
Key Features
- Detects and anonymizes PII in document text content using Presidio's analyzer and anonymizer engines.
- Replaces detected entities with labeled placeholders, for example
<PERSON>and<PHONE_NUMBER>, preserving document structure. - Runs locally — no external API call or API key required.
- Supports multiple languages; automatically selects the appropriate spaCy model for built-in languages such as English, German, French, and Spanish.
- Documents without text content pass through unchanged.
- Configurable confidence threshold and entity type allowlist for fine-grained control over what gets anonymized.
Configuration
- Drag the
PresidioDocumentCleanercomponent onto the canvas from the Component Library. - Click on the component to open the configuration panel.
- On the General tab:
- Set
languageto the ISO 639-1 code of your document language (for example,enfor English). - Optionally, set
entitiesto restrict anonymization to specific PII types.
- Set
- Go to the Advanced tab to adjust
score_thresholdor specify custommodelsfor unsupported languages.
PresidioDocumentCleaner requires a spaCy language model. For English, install en_core_web_lg with python -m spacy download en_core_web_lg. For other built-in languages, install the corresponding model listed in the spaCy model documentation. The component loads the model automatically on the first run() call.
Connections
PresidioDocumentCleaner receives a list of documents, typically from a document converter or document store retriever. It outputs a new list of documents with PII removed. Connect its documents output to downstream components such as PromptBuilder or a document writer.
Source Code
To check this component's source code, open presidio_document_cleaner.py in the Haystack Core Integrations repository.
Usage Examples
Basic Configuration
PresidioDocumentCleaner:
type: haystack_integrations.components.preprocessors.presidio.presidio_document_cleaner.PresidioDocumentCleaner
init_parameters:
language: en
entities:
score_threshold: 0.35
models:
Using the Component in a Pipeline
# haystack-pipeline
components:
PresidioDocumentCleaner:
type: haystack_integrations.components.preprocessors.presidio.presidio_document_cleaner.PresidioDocumentCleaner
init_parameters:
language: en
entities:
- PERSON
- EMAIL_ADDRESS
- PHONE_NUMBER
score_threshold: 0.35
models:
connections: []
max_runs_per_component: 100
metadata: {}
inputs:
documents:
- PresidioDocumentCleaner.documents
outputs:
documents: PresidioDocumentCleaner.documents
Parameters
Inputs
| Parameter | Type | Description |
|---|---|---|
documents | List[Document] | Documents whose text content will be anonymized. |
Outputs
| Parameter | Type | Description |
|---|---|---|
documents | List[Document] | Cleaned documents with PII replaced by entity type placeholders. Documents without text content are passed through unchanged. |
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
language | str | "en" | ISO 639-1 language code for PII detection. For built-in languages such as "de", "fr", and "es", the appropriate spaCy model is loaded automatically. For unsupported languages, use models to specify a custom model. See Presidio supported languages. |
entities | Optional[List[str]] | None | List of PII entity types to detect and anonymize, for example ["PERSON", "EMAIL_ADDRESS"]. If None, all supported entity types are used. See Presidio supported entities. |
score_threshold | float | 0.35 | Minimum confidence score (0–1) for a detected entity to be anonymized. |
models | Optional[List[Dict[str, str]]] | None | Advanced override: list of spaCy model configurations. Each entry must contain "lang_code" and "model_name" keys, for example [{"lang_code": "fr", "model_name": "fr_core_news_md"}]. Use this only when you need a specific model variant or a language not covered by the built-in mapping. |
Related Information
Was this page helpful?