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
Automate PII removal with n8n and OpenAI

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

Learn how to Build this Workflow with AI:

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.


Automate PII removal with n8n and OpenAI

Visit through Desktop to Interact with the Workflow.

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.
Author
Written By
Vikash Kumar
Building AI agents, n8n workflows and end-to-end automation for 30+ Brands across India, the US, Europe, Dubai & Australia. 7+ years of Experience saving founders real hours every week - no code required.

Related Workflows

Automate Twist Channel Creation and Messaging with n8n

This workflow automates creating and updating a channel in Twist and sending a personalized message to specific users. It eliminates manual setup errors and saves time managing Twist communications.

Automate Ideogram Image Generation with Google Sheets & Gmail

This workflow automates graphic design image generation via Ideogram AI, storing image data in Google Sheets and Google Drive, with email alerts via Gmail. It saves designers hours by automating image creation, remixing, review, and record-keeping.

Automate IT Support with Slack and OpenAI in n8n

Streamline IT support by automating Slack message handling using n8n and OpenAI. This workflow handles Slack DMs, filters bots, queries a Confluence knowledge base, and delivers AI-generated responses, improving support efficiency and response time.

Automate Crypto Analysis with CoinMarketCap & n8n AI Agent

Discover how this unique n8n workflow leverages CoinMarketCap’s multi-agent AI to deliver precise, real-time cryptocurrency insights directly via Telegram. Manage crypto data analysis efficiently with automated multi-source API integration.

Automate Gumroad to Beehiiv Subscriber Sync with n8n

Learn how to automatically add new Gumroad sales customers as Beehiiv newsletter subscribers using n8n automation. This workflow saves time by syncing sales data to Google Sheets CRM and notifying your Telegram channel instantly.

Generate On-Brand Blog Articles Using n8n and OpenAI

This workflow automates the creation of on-brand blog articles by analyzing existing company content using n8n and OpenAI. It extracts article structures and brand voice to produce consistent draft articles, saving significant content creation time.
1:1 Free Strategy Session
Your competitors are already automating. Are you still paying for it manually?

Do you want to adopt AI Automation?

Every hour your team does repetitive work, you're burning real money.
While you wait, faster businesses are cutting costs and moving quicker.
AI and automations aren't the future anymore — they're the present.

Book a live 1-on-1 session where we show you exactly which of your daily tasks can be automated — and what it’s costing you not to.