{"record":{"id":"1607f5d6cd3bf4dc","repo":"n8n-io/n8n","slug":"the-file-content-is-not-in-jsonl-format","errorCode":null,"errorMessage":"The file content is not in JSONL format","messagePattern":"The file content is not in JSONL format","errorType":"validation","errorClass":"NodeOperationError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/v1/actions/file/upload.operation.ts","lineNumber":92,"sourceCode":"\n\ttry {\n\t\tconst response = await apiRequest.call(this, 'POST', '/files', {\n\t\t\toption: { formData },\n\t\t\theaders: formData.getHeaders(),\n\t\t});\n\n\t\treturn [\n\t\t\t{\n\t\t\t\tjson: response,\n\t\t\t\tpairedItem: { item: i },\n\t\t\t},\n\t\t];\n\t} catch (error) {\n\t\tif (\n\t\t\terror.message.includes('Bad request') &&\n\t\t\terror.description?.includes('Expected file to have JSONL format')\n\t\t) {\n\t\t\tthrow new NodeOperationError(this.getNode(), 'The file content is not in JSONL format', {\n\t\t\t\tdescription:\n\t\t\t\t\t'Fine-tuning accepts only files in JSONL format, where every line is a valid JSON dictionary',\n\t\t\t});\n\t\t}\n\t\tthrow error;\n\t}\n}\n","sourceCodeStart":74,"sourceCodeEnd":100,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/v1/actions/file/upload.operation.ts#L74-L100","documentation":"When uploading a fine-tuning file, the OpenAI API returns a 'Bad request' error with description 'Expected file to have JSONL format' if the file is not valid JSONL. The catch block detects this specific error pattern and rethrows as a NodeOperationError with a user-friendly description explaining that fine-tuning requires JSONL format where every line is a valid JSON dictionary. Other errors are rethrown unchanged.","triggerScenarios":"A file uploaded with purpose 'fine-tune' is not in JSONL format. The OpenAI API validates the file server-side and returns a 400 with a description mentioning JSONL format. The catch block pattern-matches on error.message containing 'Bad request' and error.description containing 'Expected file to have JSONL format'.","commonSituations":"Uploading a .json array file instead of .jsonl; uploading a CSV or plain text file for fine-tuning; malformed JSONL with invalid JSON on some lines; wrong file selected in the node.","solutions":["Convert the file to JSONL format — one JSON object per line, no array wrapper, no trailing commas","Validate each line parses as JSON before uploading (e.g. cat file.jsonl | jq -c . > /dev/null)","Ensure the file extension and content type match — use .jsonl with application/jsonl or text/plain","If using a binary file input, confirm the correct binary property name is selected"],"exampleFix":"// before — [{\"text\": \"...\"}, {\"text\": \"...\"}]\\n (JSON array)\n// after  — {\"text\": \"...\"}\\n{\"text\": \"...\"}\\n (JSONL, one object per line)","handlingStrategy":"validation","validationCode":"// Validate JSONL format before uploading\nfunction validateJsonl(content: string): boolean {\n  const lines = content.trim().split('\\n').filter(l => l.trim());\n  return lines.every(line => {\n    try { JSON.parse(line); return true; } catch { return false; }\n  });\n}\nif (!validateJsonl(fileContent)) {\n  throw new UserError('File is not valid JSONL. Each line must be a valid JSON object.');\n}","typeGuard":"function isJsonlContent(content: string): boolean {\n  if (!content.includes('\\n')) return false;\n  return content.trim().split('\\n').every(line => {\n    try { JSON.parse(line); return true; } catch { return false; }\n  });\n}","tryCatchPattern":"try {\n  await uploadFile(this, i);\n} catch (error) {\n  if (error instanceof NodeOperationError && error.message.includes('JSONL')) {\n    // Convert the file to JSONL and retry\n    const converted = convertToJsonl(fileContent);\n    await uploadJsonlString(this, i, converted);\n  }\n  throw error;\n}","preventionTips":["Validate JSONL format before uploading — each line must be a standalone JSON object","Never wrap data in a JSON array; use one object per line","Use jq to convert: cat data.json | jq -c '.[]' > data.jsonl","Test with a small sample file first"],"tags":["openai","file-upload","jsonl","fine-tuning","format-validation","v1"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}