Zie619/n8n-workflows · error · Error

Input text is empty

Error message

Input text is empty

What it means

Thrown by the runOnceForEachItem 'Code' node (workflow 0725). For each incoming item it reads $input.item.json.text and throws when it is falsy — undefined, null, or empty string. Because the node runs per item, one bad item among many aborts the whole execution at that item.

Solutions

  1. Inspect the upstream item's json keys and read the text from the correct field (see exampleFix).
  2. Trim before checking so whitespace-only input is caught, and skip empty items instead of throwing.
  3. Add a Filter node (text is not empty) before this Code node.
  4. If text can legitimately be empty, return an empty sentences array rather than failing the run.

Example fix

// before
const text = $input.item.json.text;
if (!text) {
  throw new Error('Input text is empty');
}

// after
const text = ($input.item.json.text ?? $input.item.json.content ?? '').trim();
if (!text) {
  return { json: { sentences: [], skipped: 'empty text' } };
}
Defensive patterns

Strategy: validation

Validate before calling

const text = String($input.item.json.text ?? $input.item.json.content ?? '').trim();
if (!text) {
  return { json: { sentences: [], skipped: true } };
}

Type guard

function hasText(item) {
  const t = item?.json?.text;
  return typeof t === 'string' && t.trim().length > 0;
}

Prevention

When it happens

Trigger: An upstream item simply has no text field: the source node puts content under a different key (content, body, description, plain text of an email/PDF), or the document was genuinely empty. Whitespace-only strings (' ') pass the check but then produce zero sentences downstream.

Common situations: Gmail/PDF/RSS trigger renamed output fields between n8n versions; a previous Set node mapping $('text') against a missing field yielding undefined; empty attachments or blank documents in the batch; German-language sentence splitter receiving items from a filter that dropped the text field.

Related errors


AI-assisted analysis of Zie619/n8n-workflows@94007c1445 (2026-08-15). Data as JSON: /api/errors/a6544523741ef69c. Report an issue: GitHub.

Appendix: source

Thrown at workflows/Splitout/0725_Splitout_Code_Update_Triggered.json:25

    "owner": "n8n-user",
    "license": "MIT",
    "category": "automation",
    "status": "active",
    "priority": "high",
    "environment": "production"
  },
  "nodes": [
    {
      "id": "cbc036f7-b0e1-4eb4-94c3-7571c67a1efe",
      "name": "Code",
      "type": "n8n-nodes-base.code",
      "position": [
        -120,
        40
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Get the input text\nconst text = $input.item.json.text;\n\n// Ensure text is not null or undefined\nif (!text) {\n  throw new Error('Input text is empty');\n}\n\n// Function to split text into sentences while preserving dates and list items\nfunction splitIntoSentences(text) {\n  const monthNames = '(?:Januar|Februar|März|April|Mai|Juni|Juli|August|September|Oktober|November|Dezember)';\n  const datePattern = `(?:\\\\d{1,2}\\\\.\\\\s*(?:${monthNames}|\\\\d{1,2}\\\\.)\\\\s*\\\\d{2,4})`;\n  \n  // Split by sentence-ending punctuation, but not within dates or list items\n  const regex = new RegExp(`(?<=[.!?])\\\\s+(?=[A-ZÄÖÜ]|$)(?!${datePattern}|\\\\s*[-•]\\\\s)`, 'g');\n  \n  return text.split(regex)\n    .map(sentence => sentence.trim())\n    .filter(sentence => sentence !== '');\n}\n\n// Split the text into sentences\nconst sentences = splitIntoSentences(text);\n\n// Output a single object with an array of sentences\nreturn { json: { sentences: sentences } };"
      },
      "typeVersion": 2,
      "notes": "This code node performs automated tasks as part of the workflow."
    },
    {
      "id": "faae4740-a529-4275-be0e-b079c3bfde58",
      "name": "Split Out1",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        340,
        -180
      ],
      "parameters": {
        "options": {
          "destinationFieldName": "claim"
        },
        "fieldToSplitOut": "sentences"
      },

View on GitHub (pinned to 94007c1445)