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

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

Ready for 3.0

by ResilNext ✓ · 140 views · created 2026-03-08 · Document Extraction, AI Summarization

Ready for 3.0. This template uses no nodes that n8n 3.0 removes. No removed nodes, versions or helpers found. Static check, last run 2026-10-19.

Nodes used (12)

AI AgentStructured Output ParserPostgresAnthropic Chat ModelOllama Chat Model

What it does

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: <<EMAIL7F3A>> <<PHONEA12B>> 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 originalvalue type documentid createdat This table securely stores original PII values mapped to tokens. Audit Log Table Example structure: documentid piitypesdetected tokencount aiaccessconfirmed reinjectionevents 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

View the original on n8n.io → Check your own copy

Get the weekly “what broke” email

New templates, newly broken ones, and n8n release changes. One short email a week.

Form not loading? Subscribe here.