Zie619/n8n-workflows · error · Error
PII column names are missing in the input data.
Error message
PII column names are missing in the input data.
What it means
Thrown by 'Remove PII columns' (workflow 0698) when the first input item has no json.data property. The code expects a specific three-item layout: input[0].json.data = comma-separated PII column names, input[1].json.originalFilename = the file name, input[2..] = data rows. It only checks the first of these, so this message means the header/metadata item is missing or shaped differently.
Source
Thrown at workflows/Splitout/0698_Splitout_Code_Automation_Triggered.json:226
"parameters": {
"options": {
"destinationFieldName": "data"
},
"fieldToSplitOut": "message.content.content"
},
"typeVersion": 1,
"notes": "This splitOut node performs automated tasks as part of the workflow."
},
{
"id": "4207dc71-5b0e-4780-9f23-00f5a7fc3862",
"name": "Remove PII columns",
"type": "n8n-nodes-base.code",
"position": [
580,
260
],
"parameters": {
"jsCode": "// Input: All items from the previous node\nconst input = $input.all();\n\n// Step 1: Extract the PII column names from the first item\nconst firstItem = input[0];\nif (!firstItem.json.data || !firstItem.json.data) {\n throw new Error(\"PII column names are missing in the input data.\");\n}\nconst piiColumns = firstItem.json.data.split(',').map(col => col.trim());\n//console.log(\"PII Columns to Remove:\", piiColumns);\n\n// Step 2: Remove the first two items and process the remaining rows\nlet rows = input.slice(2).map(item => item.json); // Exclude the first item\n//console.log(\"Rows to convert (before skipping last):\", rows);\n\n\n// Ensure there are rows to process\nif (rows.length === 0) {\n throw new Error(\"No rows to convert to CSV.\");\n}\n\n// Step 3: Remove PII columns from each row\nconst sanitizedRows = rows.map(row => {\n const sanitizedRow = { ...row }; // Copy the row\n piiColumns.forEach(column => delete sanitizedRow[column]); // Remove PII columns\n return sanitizedRow;\n});\n//console.log(\"Sanitized Rows:\", sanitizedRows);\n\n// Step 4: Extract headers from sanitized rows\nconst headers = Object.keys(sanitizedRows[0]); // Extract updated headers\n//console.log(\"CSV Headers:\", headers);\n\n// Step 5: Convert rows to CSV format\nconst csvRows = [\n headers.join(','), // Add header row\n ...sanitizedRows.map(row => \n headers.map(header => String(row[header] || '').replace(/,/g, '')).join(',') // Match headers with rows\n )\n];\n\n// Join all rows with a newline character\nconst csvContent = csvRows.join('\\n');\n//console.log(\"CSV Content:\", csvContent);\n\nconst originalFileName = input[1].json.originalFilename;\n\n// Step 7: Generate a new filename\nconst fileExtension = originalFileName.split('.').pop();\nconst baseName = originalFileName.replace(`.${fileExtension}`, '');\nconst newFileName = `${baseName}_PII_removed.${fileExtension}`;\n//console.log(\"New Filename:\", newFileName);\n\n// Step 8: Return the CSV content and filename as JSON\nreturn [\n {\n json: {\n fileName: newFileName, // New file name\n content: csvContent // CSV content as plain text\n }\n }\n];\n"
},
"typeVersion": 2,
"notes": "This code node performs automated tasks as part of the workflow."
},
{
"id": "e9f25ee7-cd00-4496-9062-5d57cab5788d",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
-300,
-220
],
"parameters": {
"height": 260,
"content": "## Remove PII from CSV Files\nThis workflow monitors a Google Drive folder for new CSV files, identifies and removes PII columns using OpenAI, and uploads the sanitized file back to the drive. It requires Google Drive and OpenAI integrations with API access enabled."
},
"typeVersion": 1,
"notes": "This stickyNote node performs automated tasks as part of the workflow."View on GitHub (pinned to 94007c1445)
Solutions
- Execute the node before this one and inspect the item order and first item's json keys.
- Locate the metadata reliably instead of assuming position 0 (see exampleFix).
- Validate typeof firstItem.json.data === 'string' before split, and fail with the actual first-item keys in the message.
- If the uploader sometimes sends no PII columns, treat that as 'nothing to remove' rather than an error.
Example fix
// before
const firstItem = input[0];
if (!firstItem.json.data || !firstItem.json.data) {
throw new Error("PII column names are missing in the input data.");
}
const piiColumns = firstItem.json.data.split(',').map(col => col.trim());
// after
const metaItem = input.find(i => typeof i.json?.data === 'string' && i.json.data.includes(','));
if (!metaItem) {
const keys = input.map(i => Object.keys(i.json || {}).join('|')).slice(0, 3);
throw new Error(`PII column names are missing; first item keys were: ${keys.join(' / ')}`);
}
const piiColumns = metaItem.json.data.split(',').map(c => c.trim()); Defensive patterns
Strategy: validation
Validate before calling
const metaItem = input.find(i => typeof i.json?.data === 'string' && i.json.data.includes(','));
if (!metaItem) {
throw new Error(`PII columns item missing; first items' keys: ${input.slice(0,3).map(i => Object.keys(i.json||{})) .join(' / ')}`);
}
const fileItem = input.find(i => typeof i.json?.originalFilename === 'string');
if (!fileItem) throw new Error('originalFilename item missing'); Type guard
function isPiiColumnsItem(item) {
return typeof item?.json?.data === 'string' && item.json.data.trim().length > 0;
} Prevention
- Never rely on fixed item positions for metadata; find items by their shape.
- Validate string-ness before .split() — the original guard checked the same expression twice and skipped it.
- Define 'no PII columns supplied' as a no-op rather than an error if uploaders can omit it.
When it happens
Trigger: The upstream Split Out / file-processing chain emitted items where the first item is a data row (no .data key), or the metadata landed under a different property (columns, headers, pii). Note the check itself is buggy — if (!firstItem.json.data || !firstItem.json.data) tests the same expression twice, and it does not verify .data is a string before .split(',').
Common situations: Upload form or trigger payload changed so the columns item is absent; Split Out reordering items; previous node failing silently and emitting only row items; a file whose parse produced no header item.
Related errors
- PII column names are missing in the input data.
- ${fileName} → ${baseName} → Unrecognized file name structure
- Invalid JSON in MQTT message
- Initial Vector 'data' is undefined or missing.
- Initial Vector 'data' is in an unsupported format.
AI-assisted analysis of Zie619/n8n-workflows@94007c1445 (2026-08-15).
Data as JSON: /api/errors/7d66e6eed2b6d737.
Report an issue: GitHub.