PII Data Removal from CSV Files using AI and Google Drive - n8n Workflow

Automate privacy compliance using this n8n workflow. It monitors Google Drive for CSV files, utilizes the OpenAI n8n node to detect PII columns, sanitizes the data, and securely uploads the cleaned file. Find the best n8n templates here.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Data Engineers and Analysts needing automated compliance checks.
Organizations handling sensitive customer data stored in CSV format.
Users looking for advanced examples of custom Code n8n node integration.
Automation specialists interested in sophisticated n8n templates involving AI analysis and file manipulation.

Overview

This robust n8n workflow provides a powerful solution for automatically complying with data privacy regulations. When a new CSV file is dropped into a monitored Google Drive folder, the Google Drive n8n trigger initiates the entire process. The core value of this n8n workflow lies in leveraging the OpenAI n8n node (specifically the efficient gpt-4o-mini model) to intelligently analyze the file headers and sample rows to identify Personally Identifiable Information (PII) columns. After the PII columns are identified, a custom n8n node sanitizes the data, removing those specific columns entirely and reconstructing a clean CSV file. This fully automated n8n workflow template ensures data safety and efficiency, making it one of the most practical n8n templates for securing data pipelines using low-code automation.

How it Works

The entire process is managed by an automated n8n workflow that begins with a file creation event:


  1. Triggering the n8n workflow: The n8n trigger, configured as the Google Drive Trigger n8n node, constantly monitors a specific Google Drive folder for newly created CSV files.

  2. File Retrieval and Preparation: Upon detection, the workflow uses a Google Drive n8n node to download the file content. Simultaneously, a Split Out n8n node captures the original filename. The Extract from File n8n node then parses the CSV binary data into a stream of structured JSON items (representing each row).

  3. PII Identification via AI: The workflow utilizes the OpenAI n8n node. It passes the CSV headers and a few example rows to the AI model (gpt-4o-mini) along with a restrictive system prompt, instructing it only to return a comma-separated list of columns containing PII.

  4. Data Consolidation: A critical Merge n8n node collects three distinct data streams: the PII column names (from OpenAI), the original filename, and all the parsed data rows (from the Extract n8n node). This prepares the data for the final processing step.

  5. Sanitization Logic Execution: The custom Code n8n node, named 'Remove PII columns', executes JavaScript logic. It uses the identified PII column list to iterate through every single data row, programmatically deleting the corresponding keys (columns). It then rebuilds the data into a clean CSV string and generates a new, descriptive filename.

  6. Final Upload: The last Google Drive n8n node (Upload to Drive) receives the newly created, sanitized CSV content and uploads the file to a designated 'processed' folder, successfully completing the automated n8n workflow.

Installation Guide

To deploy this powerful PII removal n8n workflow template, follow these steps:


  1. Import the n8n workflow: Download the provided JSON data and import it directly into your n8n instance.

  2. Google Drive Setup: You must configure and connect your Google Drive credentials. Ensure the credentials used by the initial Google Drive Trigger n8n node and the subsequent Google Drive n8n nodes have read and write permissions to the monitored and destination folders, respectively.

  3. OpenAI Credentials: Set up your OpenAI API key credentials and link them to the OpenAI n8n node.

  4. Folder Configuration:

In the Google Drive Trigger n8n node, specify the Folder ID where raw CSV files will be uploaded (the monitored folder).
In the final Google Drive n8n node (Upload to Drive), specify the Folder ID of the 'processed' folder where the PII-removed files will be saved.

  1. Activation: Save and activate the n8n workflow. The n8n trigger will now start monitoring the specified folder automatically.

Node Details

Google Drive Trigger n8n node:
Function: Serves as the primary n8n trigger, initiating the automation whenever a new file is uploaded to the specified monitoring folder.
Key Configuration: event: fileCreated, monitors a specificFolder ID.
Google Drive n8n node (Download):
Function: Downloads the content of the CSV file identified by the n8n trigger.
Key Configuration: operation: download, output stored as binary data under the property data.
Extract from File n8n node:
Function: Parses the binary CSV file content into usable JSON objects, where each item represents a row, preparing the data for the OpenAI n8n node.
OpenAI n8n node:
Function: Leverages AI to intelligently analyze the structure and content of the CSV data and determine which columns contain PII.
Key Configuration: modelId: gpt-4o-mini, uses a precise system prompt to enforce comma-separated column name output, and jsonOutput: true.
Merge n8n node:
Function: Consolidates the outputs from three different branches—the PII list, the filename, and the entire dataset—for streamlined processing by the custom n8n node.
Code n8n node (Remove PII columns):
Function: Executes the core PII removal logic, iterating through the rows and deleting columns based on the list provided by the OpenAI n8n node. It then re-encodes the data into a new CSV string and generates a new filename.
Key Configuration: Contains custom JavaScript that handles data slicing, array mapping, property deletion, and CSV formatting.
Google Drive n8n node (Upload to Drive):
Function: The final action of the n8n workflow, uploading the sanitized CSV content back to a designated folder in Google Drive.
* Key Configuration: operation: createFromText, uses expressions to dynamically set the name and content of the new file.

Related n8n Workflows

Free

Nodes: 8 Nodes
Updated: December 26 2025
View all
Created by

Software Engineer

Featured*