{"record":{"id":"72456be224d95745","repo":"n8n-io/n8n","slug":"text-for-item-itemindex-is-not-defined","errorCode":null,"errorMessage":"Text for item ${itemIndex} is not defined","messagePattern":"Text for item (.+?) is not defined","errorType":"exception","errorClass":"NodeOperationError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/nodes-langchain/nodes/chains/InformationExtractor/processItem.ts","lineNumber":21,"sourceCode":"import { ChatPromptTemplate, SystemMessagePromptTemplate } from '@langchain/core/prompts';\nimport type { OutputFixingParser } from '@langchain/classic/output_parsers';\nimport { NodeOperationError, type IExecuteFunctions } from 'n8n-workflow';\n\nimport { wrapLangChainParserError } from '@utils/output_parsers/langchainParserError';\nimport { toParserInputText } from '@utils/output_parsers/parserInput';\nimport { getTracingConfig } from '@utils/tracing';\n\nimport { SYSTEM_PROMPT_TEMPLATE } from './constants';\n\nexport async function processItem(\n\tctx: IExecuteFunctions,\n\titemIndex: number,\n\tllm: BaseLanguageModel,\n\tparser: OutputFixingParser<object>,\n) {\n\tconst input = ctx.getNodeParameter('text', itemIndex) as string;\n\tif (!input?.trim()) {\n\t\tthrow new NodeOperationError(ctx.getNode(), `Text for item ${itemIndex} is not defined`, {\n\t\t\titemIndex,\n\t\t});\n\t}\n\tconst inputPrompt = new HumanMessage(input);\n\n\tconst options = ctx.getNodeParameter('options', itemIndex, {}) as {\n\t\tsystemPromptTemplate?: string;\n\t};\n\n\tconst escapedTemplate = (options.systemPromptTemplate ?? SYSTEM_PROMPT_TEMPLATE).replace(\n\t\t/[{}]/g,\n\t\t(match) => match + match,\n\t);\n\n\tconst systemPromptTemplate = SystemMessagePromptTemplate.fromTemplate(\n\t\t`${escapedTemplate}\n{format_instructions}`,\n\t);","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/nodes-langchain/nodes/chains/InformationExtractor/processItem.ts#L3-L39","documentation":"Thrown by Information Extractor processItem when the 'text' parameter for the current item is missing or whitespace-only. The node trims the input and refuses empty text because there is nothing for the LLM to extract attributes from.","triggerScenarios":"The 'text' parameter (or its expression) resolves to an empty or whitespace-only string for itemIndex. The guard !input?.trim() catches both undefined and blank.","commonSituations":"Input items where the source text field is empty (e.g. an empty email body, a blank row from a spreadsheet); the expression references a missing key; upstream filtering did not remove empty-text items.","solutions":["Filter items with empty text upstream using an If node on the text field.","Fix the expression so it resolves to the correct non-empty source field.","Default to a placeholder if empty: {{$json.text || 'N/A'}}.","Enable Continue On Fail so empty items are skipped with an error JSON rather than aborting."],"exampleFix":"// before\nconst input = ctx.getNodeParameter('text', itemIndex) as string;\nif (!input?.trim()) {\n  throw new NodeOperationError(ctx.getNode(), `Text for item ${itemIndex} is not defined`, { itemIndex });\n}\n\n// after — same guard, but include a hint about the source field\nif (!input?.trim()) {\n  throw new NodeOperationError(ctx.getNode(), {\n    message: `Text for item ${itemIndex} is empty. Provide non-empty input text for extraction.`,\n    itemIndex,\n  });\n}","handlingStrategy":"validation","validationCode":"const input = ctx.getNodeParameter('text', itemIndex, '') as string;\nif (!input.trim()) {\n  throw new Error(`Item ${itemIndex} has empty text; nothing to extract`);\n}","typeGuard":"function isNonEmptyString(v: unknown): v is string {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":null,"preventionTips":["Filter items with empty text upstream via an If node.","Provide a fallback in the text expression.","Enable Continue On Fail so empty items do not abort the run."],"tags":["configuration","parameter-validation","information-extractor","per-item"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}