Automate PII Removal from Google Drive CSVs with n8n & OpenAI

Struggling with manually finding and deleting sensitive PII from CSV files stored in Google Drive? This n8n workflow detects new CSV uploads, uses OpenAI to pinpoint PII columns, removes them, and saves sanitized files back to your drive automatically, saving hours and securing your data.
googleDriveTrigger
openAi
code
+6
Workflow Identifier: 2266
NODES in Use: Google Drive Trigger, Google Drive, Extract from File, OpenAI, Merge, Upload to Drive, Split Out, Code, Sticky Note

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

Visit through Desktop for Best experience

What this workflow does

This workflow watches a Google Drive folder for new CSV files.
When a new file arrives, it automatically finds which columns contain personal information like names or emails.
Then, it removes those columns from the CSV and saves a clean copy in another folder.
This stops sensitive data from leaking and saves hours of manual work every day.


Who should use this workflow

If you get many CSV reports containing personal data, and you must remove private details before sharing, this workflow helps.
It is useful for compliance teams, data handlers, or anyone worried about accidentally sharing sensitive information.


Tools and services used

  • n8n Automation Platform: Runs the workflow steps.
  • Google Drive API: Watches the folder, downloads, and uploads files.
  • OpenAI (using LangChain node): Identifies PII columns by analyzing CSV headers.
  • Code Node: Removes the PII columns and rebuilds the CSV.

Input → Processing → Output

Inputs

  • New CSV file uploaded to a specific Google Drive folder.

Processing steps

  • Trigger: Detect new file in the watched folder.
  • Download: Get the CSV file content.
  • Extract: Parse CSV file and get column headers.
  • Analyze: Use OpenAI to find which columns have PII.
  • Clean: Remove PII columns using a code script.
  • Prepare: Create a new CSV file with clean data and a modified filename.
  • Upload: Save the sanitized file to another Google Drive folder.

Outputs

  • New CSV files without sensitive columns, saved to the designated Google Drive folder.

Beginner step-by-step: How to use this workflow in n8n

1. Import the workflow

  1. Download the workflow file using the Download button on this page.
  2. Inside the n8n editor, click “Import from File” and choose the downloaded file.

2. Add credentials and set folders

  1. Open each Google Drive node and add your Google Drive API credentials.
  2. In the Google Drive Trigger, set the ID of the folder to watch.
  3. In the last Google Drive node, set the destination folder ID where cleaned files will be saved.
  4. In the OpenAI (LangChain) node, add your OpenAI API Key.

3. Test the workflow

  1. Upload a test CSV file to the watched Google Drive folder.
  2. Check the n8n execution panel to see the workflow run.
  3. Look for the new sanitized file appearing in the output folder.

4. Activate the workflow

  1. Once tests pass, toggle the workflow to active.
  2. Make sure n8n is running constantly to handle new files anytime.

If hosting your own n8n instance, see self-host n8n for setup help.


Explanation of main code and prompts

The OpenAI (LangChain) node uses this system message to detect PII columns:

{"role":"system","content":"Analyze the provided tabular data and identify the columns that contain personally identifiable information (PII). Return only the column names that contain PII, separated by commas."}

This message tells the AI to only list column names with PII, separated by commas.

The code node named Remove PII columns receives all data, then:

  • Extracts the PII columns from the AI output.
  • Removes those columns from all CSV rows.
  • Generates a new CSV text without PII columns.
  • Creates a new filename adding “_PII_removed” before the file extension.

This provides a clean CSV ready to upload back to Google Drive.


Customization ideas

  • Change the watched folder by updating the folder ID in the Google Drive Trigger node.
  • Adjust the OpenAI model for cheaper or faster calls in the OpenAI (LangChain) configuration.
  • Filter only CSV files by checking file extensions before processing.
  • Modify the code node to mask PII data instead of deleting, if needed.
  • Add notification nodes like Slack or Email to signal when files are cleaned and uploaded.

Common problems and fixes

  • Issue: “PII column names are missing in input data.”
    Fix: Check if the OpenAI prompt matches the CSV headers and API key is valid.
  • Issue: “No rows to convert to CSV.”
    Fix: Verify the CSV file is not empty and that extraction worked correctly.
  • Issue: Google Drive upload fails.
    Fix: Confirm the destination folder ID and drive API permissions allow writing.

Summary of results

✓ Automates detection and removal of PII in CSVs.
✓ Saves hours by removing manual editing work.
✓ Prevents accidental sharing of sensitive data.
→ Produces clean CSV files automatically stored in Google Drive.


Frequently Asked Questions

The workflow uses an OpenAI (LangChain) node with a prompt that analyzes CSV headers and lists columns containing personally identifiable information separated by commas.
After importing, add Google Drive and OpenAI API credentials, update folder IDs for input and output folders, then test with a sample CSV file before activating the workflow.
The workflow is designed for CSV files. Filtering logic can be added before processing to skip non-CSV files if needed.
Yes, the Code node can be modified to mask or replace PII values instead of removing the columns completely.

Promoted by BULDRR AI

Related Workflows

Automate Viral UGC Video Creation Using n8n + Degaus (Beginner-Friendly Guide)

Learn how to automate viral UGC video creation using n8n, AI prompts, and Degaus. This beginner-friendly guide shows how to import, configure, and run the workflow without technical complexity.
Form Trigger
Google Sheets
Gmail
+37
Free

AI SEO Blog Writer Automation Workflows in n8n

A complete beginner guide to building an AI SEO blog writer automation using n8n.
AI Agent
Google Sheets
httpRequest
+5
Free

Automate CrowdStrike Alerts with VirusTotal, Jira & Slack

This workflow automates processing of CrowdStrike detections by enriching threat data via VirusTotal, creating Jira tickets for incident tracking, and notifying teams on Slack for quick response. Save hours daily by transforming complex threat data into actionable alerts effortlessly.
scheduleTrigger
httpRequest
jira
+5
Free

Automate Telegram Invoices to Notion with AI Summaries & Reports

Save hours on financial tracking by automating invoice extraction from Telegram photos to Notion using Google Gemini AI. This workflow extracts data, records transactions, and generates detailed spending reports with charts sent on schedule via Telegram.
lmChatGoogleGemini
telegramTrigger
notion
+9
Free

Automate Email Replies with n8n and AI-Powered Summarization

Save hours managing your inbox with this n8n workflow that uses IMAP email triggers, AI summarization, and vector search to draft concise replies requiring minimal review. Automate business email processing efficiently with AI guidance and Gmail integration.
emailReadImap
vectorStoreQdrant
emailSend
+12
Free

Automate Email Campaigns Using n8n with Gmail & Google Sheets

This n8n workflow automates personalized email outreach campaigns by integrating Gmail and Google Sheets, saving hours of manual follow-up work and reducing errors in email sequences. It ensures timely follow-ups based on previous email interactions, optimizing communication efficiency.
googleSheets
gmail
code
+5
Free