{"record":{"id":"ced8fbfb2de990cd","repo":"n8n-io/n8n","slug":"too-many-columns-rawheaders-length-max-max","errorCode":null,"errorMessage":"Too many columns: ${rawHeaders.length} (max ${MAX_COLUMNS})","messagePattern":"Too many columns: (.+?) \\(max (.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/@n8n/instance-ai/src/parsers/structured-file-parser.ts","lineNumber":404,"sourceCode":"\t\tthrow new Error(\n\t\t\t`Unsupported format for \"${attachment.fileName}\" (${attachment.mimeType}). Supported: csv, tsv, json`,\n\t\t);\n\t}\n\n\tconst hasHeader = input.hasHeader ?? true;\n\tconst startRow = input.startRow ?? 0;\n\tconst maxRows = Math.min(input.maxRows ?? DEFAULT_MAX_ROWS, MAX_ROWS_PER_CALL);\n\tconst warnings: string[] = [];\n\n\tlet columns: ColumnMeta[];\n\tlet paginatedRows: Array<Record<string, CellValue>>;\n\tlet totalRows: number;\n\n\tif (format === 'json') {\n\t\tconst { rawHeaders, allRows } = parseJson(content);\n\n\t\tif (rawHeaders.length > MAX_COLUMNS) {\n\t\t\tthrow new Error(`Too many columns: ${rawHeaders.length} (max ${MAX_COLUMNS})`);\n\t\t}\n\n\t\tconst normalizedNames = normalizeColumnNames(rawHeaders);\n\t\ttotalRows = allRows.length;\n\t\tconst sliced = allRows.slice(startRow, startRow + maxRows);\n\n\t\t// Build columns with type inference from sliced sample\n\t\tcolumns = rawHeaders.map((raw, i) => ({\n\t\t\toriginalName: raw,\n\t\t\tname: normalizedNames[i],\n\t\t\tinferredType: inferColumnType(\n\t\t\t\tsliced.map((row) => {\n\t\t\t\t\tconst val = row[raw];\n\t\t\t\t\treturn val === undefined ? null : (val as CellValue);\n\t\t\t\t}),\n\t\t\t),\n\t\t\tindex: i,\n\t\t}));","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/instance-ai/src/parsers/structured-file-parser.ts#L386-L422","documentation":"Thrown on the JSON branch of parseStructuredFile (structured-file-parser.ts:403-404) when the number of unique keys across all objects in the JSON array exceeds MAX_COLUMNS (50). Headers are deduplicated via a Set that preserves first-appearance order, so the count is of distinct keys, not total fields.","triggerScenarios":"A JSON array attachment whose union of keys across all objects is > 50. Each new key seen adds to the count even if most rows leave it null.","commonSituations":"Wide REST responses; column-sparse JSON where different objects carry different optional fields; an export with many metadata columns; unions of heterogeneous record types concatenated into one array.","solutions":["Project the JSON to only the columns the task needs before attaching.","Split heterogeneous record types into separate attachments.","Drop sparse/optional fields that inflate the distinct-key count.","If the data is legitimately wide, summarize or sample it rather than passing it raw."],"exampleFix":"// before: attach JSON with 73 distinct keys\n// after:  attach JSON projected to the 12 relevant keys","handlingStrategy":"validation","validationCode":"import { MAX_COLUMNS } from './structured-file-parser';\nconst keys = new Set<string>();\nfor (const item of parsed) for (const k of Object.keys(item)) keys.add(k);\nif (keys.size > MAX_COLUMNS) throw new Error(`Too many columns: ${keys.size}`);","typeGuard":"function isWithinColumnLimit(parsed: unknown[], limit = MAX_COLUMNS): boolean {\n  const keys = new Set<string>();\n  for (const item of parsed as Record<string, unknown>[]) for (const k of Object.keys(item)) keys.add(k);\n  return keys.size <= limit;\n}","tryCatchPattern":"try { return parseStructuredFile(attachment, idx, input); }\ncatch (e) {\n  if (e instanceof Error && e.message.startsWith('Too many columns')) {\n    // project to fewer keys and retry\n  }\n  throw e;\n}","preventionTips":["Project JSON to only needed keys before attaching.","Split heterogeneous record types into separate attachments.","Measure distinct-key count before upload."],"tags":["limits","columns","json","attachment-parsing"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}