Skip to main content

Mask PII in documents for GDPR-safe AI processing with Postgres and Claude

Workflow preview

Workflow preview
100%
Mask PII in documents for GDPR-safe AI processing with Postgres and Claude preview
Open on n8n.io

1. Workflow Overview

Overview This workflow implements a privacy preserving AI document processing pipeline that detects, masks, and securely manages Personally Identifiable Information (PII) before any AI processing o...

Best for

  • Document Extraction automation workflows
  • AI Summarization automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

n8n-nodes-base.webhook, n8n-nodes-base.set, n8n-nodes-base.extractfromfile, n8n-nodes-base.code, @n8n/n8n-nodes-langchain.agent, @n8n/n8n-nodes-langchain.outputparserstructured, n8n-nodes-base.merge, n8n-nodes-base.postgres

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by ResilNext.

Original n8n.io source

1.1 Workflow description

Title
Mask PII in documents for GDPR-safe AI processing with Postgres and Claude
Workflow name
Mask PII in documents for GDPR-safe AI processing with Postgres and Claude

Overview

This workflow implements a privacy-preserving AI document processing pipeline that detects, masks, and securely manages Personally Identifiable Information (PII) before any AI processing occurs.

Organizations often need to analyze documents such as invoices, forms, contracts, or reports using AI. However, sending documents containing personal data directly to AI models can create serious privacy, compliance, and security risks.

This workflow solves that problem by automatically detecting sensitive information, replacing it with secure tokens, and storing the original values in a protected vault database.

Only the masked version of the document is sent to the AI model for analysis. If required, a controlled PII re-injection mechanism can restore original values after processing.

The workflow also records all operations in an audit log, making it suitable for environments requiring strong compliance such as GDPR, financial services, healthcare, or enterprise document processing systems.


How It Works

1. Document Upload

A webhook receives a document (typically a PDF) and triggers the workflow.

2. OCR Text Extraction

The OCR Extract node extracts the text content from the document so it can be analyzed for sensitive information.

3. PII Detection

Multiple detectors analyze the text to identify different types of sensitive data:

  • Email addresses (regex detection)
  • Phone numbers (multi-pattern detection)
  • Identification numbers such as PAN, SSN, or bank accounts
  • Physical addresses detected using an AI model

Each detection includes:

  • detected value
  • location in the text
  • confidence score

4. Detection Consolidation

All detected PII results are merged into a single dataset. The workflow resolves overlapping detections and removes duplicates to produce a clean list of sensitive values.

5. Tokenization and Secure Vault Storage

Each detected PII value is replaced with a secure token, for example:

<<EMAIL_7F3A>>
<<PHONE_A12B>>

The original values are securely stored in a Postgres vault table.

This ensures sensitive data is never exposed to AI models.

6. Masked AI Processing

The masked document is sent to an AI model for structured analysis.

Possible AI tasks include:

  • Document classification
  • Data extraction
  • Document summarization
  • Entity extraction

Since all sensitive data has been tokenized, the AI processes the document without seeing any real personal data.

7. Controlled PII Re-Injection

After AI processing, the workflow can optionally restore original values from the vault.

The Re-Injection Controller determines which fields are allowed to restore PII based on defined permissions.

8. Compliance Audit Logging

All events are recorded in an audit table, including:

  • PII detection
  • token generation
  • AI processing
  • PII restoration

This provides traceability and compliance reporting.


Setup Instructions

1. Configure Postgres Database

Create two tables in your database.

PII Vault Table

Example structure:

token
original_value
type
document_id
created_at

This table securely stores original PII values mapped to tokens.

Audit Log Table

Example structure:

document_id
pii_types_detected
token_count
ai_access_confirmed
re_injection_events
timestamp
actor

This table records workflow activity for compliance tracking.


2. Configure AI Model Credentials

This workflow supports multiple AI models:

  • Anthropic Claude (used for AI document processing)
  • Ollama local models (used for address detection)

Configure credentials in n8n before running the workflow.


3. Configure Webhook Trigger

The workflow starts when a document is sent to the webhook:

POST /webhook/gdpr-document-upload

Upload a PDF file to this endpoint to trigger processing.


4. Configure Alert Notifications (Optional)

Replace the placeholder alert webhook URL with your monitoring or alerting system.

Example use cases:

  • Slack alert
  • monitoring system
  • incident notification

Alerts are triggered if masking fails.


Use Cases

This workflow is useful for many privacy-sensitive automation scenarios.

GDPR-Compliant Document Processing

Safely process documents containing personal data without exposing PII to AI models.

AI-Powered Document Analysis

Use AI to summarize or extract data from documents while maintaining privacy.

Enterprise Data Redaction Pipelines

Automatically detect and tokenize sensitive data before sending documents to downstream systems.

Financial Document Processing

Process invoices, contracts, and financial reports securely.

Healthcare Document Automation

Analyze patient documents while ensuring sensitive data is protected.


Requirements

To run this workflow you need:

  • n8n
  • Postgres database
  • Anthropic Claude API access
  • Ollama (optional for local AI address detection)
  • Webhook endpoint for document uploads

Optional integrations:

  • Monitoring or alert system
  • Compliance audit database

Key Features

  • Automated PII detection and tokenization
  • AI-safe document processing
  • Secure vault storage for sensitive data
  • Controlled PII restoration
  • Full audit logging
  • Works with multiple AI models
  • Designed for GDPR and enterprise compliance

Summary

This workflow creates a secure bridge between sensitive documents and AI systems.

By automatically detecting, masking, and securely storing personal data, it enables organizations to safely apply AI to document processing tasks without exposing sensitive information.

The combination of tokenization, secure vault storage, controlled re-injection, and audit logging makes this workflow suitable for privacy-sensitive industries and enterprise automation pipelines.

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - Document Upload Webhook

Type / Role
n8n-nodes-base.webhook - webhook
Config choices
Version 2.1

Block 2 - Workflow Configuration

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 3 - OCR Extract Text

Type / Role
n8n-nodes-base.extractFromFile - extractFromFile
Config choices
Version 1.1

Block 4 - Email Detector

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 5 - Phone Detector

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 6 - ID Number Detector

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 7 - Address Detector AI

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 3

Block 8 - Address Output Parser

Type / Role
@n8n/n8n-nodes-langchain.outputParserStructured - outputParserStructured
Config choices
Version 1.3

Block 9 - Merge PII Detections

Type / Role
n8n-nodes-base.merge - merge
Config choices
Version 3.2

Block 10 - PII Consolidation & Conflict Resolver

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 11 - Tokenization & Vault Storage

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 12 - Store Tokens in Vault

Type / Role
n8n-nodes-base.postgres - postgres
Config choices
Version 2.6

Block 13 - Generate Masked Text

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 14 - AI Processing (Masked Data)

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 3

Block 15 - AI Processing Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatAnthropic - lmChatAnthropic
Config choices
Version 1.3

Block 16 - AI Output Parser

Type / Role
@n8n/n8n-nodes-langchain.outputParserStructured - outputParserStructured
Config choices
Version 1.3

Block 17 - Re-Injection Controller

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 18 - Retrieve Original Values

Type / Role
n8n-nodes-base.postgres - postgres
Config choices
Version 2.6

Block 19 - Restore Original PII

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 20 - Store Audit Log

Type / Role
n8n-nodes-base.postgres - postgres
Config choices
Version 2.6

Block 21 - Masking Success Check

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.3

Block 22 - Block AI Processing

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 23 - Send Alert Notification

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.3

Block 24 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Showing the first 24 of 37 workflow blocks. Download the JSON for the full node graph.

3. Summary Table

Workflow Mask PII in documents for GDPR-safe AI processing with Postgres and Claude
Complexity advanced
Nodes 37
Categories Document Extraction, AI Summarization
Author ResilNext
Published 08 Mar 2026

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/13941/13941.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Mask PII in documents for GDPR-safe AI processing with Postgres and Claude do?

Overview This workflow implements a privacy preserving AI document processing pipeline that detects, masks, and securely manages Personally Identifiable Information (PII) before any AI processing o...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Document Extraction, AI Summarization use case.