{"record":{"id":"7d66e6eed2b6d737","repo":"Zie619/n8n-workflows","slug":"pii-column-names-are-missing-in-the-input-data","errorCode":null,"errorMessage":"PII column names are missing in the input data.","messagePattern":"PII column names are missing in the input data\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"workflows/Splitout/0698_Splitout_Code_Automation_Triggered.json","lineNumber":226,"sourceCode":"      \"parameters\": {\n        \"options\": {\n          \"destinationFieldName\": \"data\"\n        },\n        \"fieldToSplitOut\": \"message.content.content\"\n      },\n      \"typeVersion\": 1,\n      \"notes\": \"This splitOut node performs automated tasks as part of the workflow.\"\n    },\n    {\n      \"id\": \"4207dc71-5b0e-4780-9f23-00f5a7fc3862\",\n      \"name\": \"Remove PII columns\",\n      \"type\": \"n8n-nodes-base.code\",\n      \"position\": [\n        580,\n        260\n      ],\n      \"parameters\": {\n        \"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\"\n      },\n      \"typeVersion\": 2,\n      \"notes\": \"This code node performs automated tasks as part of the workflow.\"\n    },\n    {\n      \"id\": \"e9f25ee7-cd00-4496-9062-5d57cab5788d\",\n      \"name\": \"Sticky Note\",\n      \"type\": \"n8n-nodes-base.stickyNote\",\n      \"position\": [\n        -300,\n        -220\n      ],\n      \"parameters\": {\n        \"height\": 260,\n        \"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.\"\n      },\n      \"typeVersion\": 1,\n      \"notes\": \"This stickyNote node performs automated tasks as part of the workflow.\"","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/workflows/Splitout/0698_Splitout_Code_Automation_Triggered.json#L208-L244","documentation":"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.","triggerScenarios":"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(',').","commonSituations":"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.","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."],"exampleFix":"// before\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\n// after\nconst metaItem = input.find(i => typeof i.json?.data === 'string' && i.json.data.includes(','));\nif (!metaItem) {\n  const keys = input.map(i => Object.keys(i.json || {}).join('|')).slice(0, 3);\n  throw new Error(`PII column names are missing; first item keys were: ${keys.join(' / ')}`);\n}\nconst piiColumns = metaItem.json.data.split(',').map(c => c.trim());","handlingStrategy":"validation","validationCode":"const metaItem = input.find(i => typeof i.json?.data === 'string' && i.json.data.includes(','));\nif (!metaItem) {\n  throw new Error(`PII columns item missing; first items' keys: ${input.slice(0,3).map(i => Object.keys(i.json||{})) .join(' / ')}`);\n}\nconst fileItem = input.find(i => typeof i.json?.originalFilename === 'string');\nif (!fileItem) throw new Error('originalFilename item missing');","typeGuard":"function isPiiColumnsItem(item) {\n  return typeof item?.json?.data === 'string' && item.json.data.trim().length > 0;\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["n8n","csv","pii","file-processing","payload-shape"],"backgroundTag":null,"analyzedSha":"94007c1445d9258a7da116646b79473e7c7c3282","analyzedAt":"2026-08-15T04:10:37.591Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}