{"record":{"id":"ebdf8a4a2ea73b29","repo":"n8n-io/n8n","slug":"the-query-parameter-is-empty","errorCode":null,"errorMessage":"The ‘query‘ parameter is empty.","messagePattern":"The ‘query‘ parameter is empty\\.","errorType":"exception","errorClass":"NodeOperationError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/nodes-langchain/nodes/chains/ChainRetrievalQA/processItem.ts","lineNumber":47,"sourceCode":"\t\tNodeConnectionTypes.AiRetriever,\n\t\t0,\n\t)) as BaseRetriever;\n\n\tlet query;\n\n\tif (ctx.getNode().typeVersion <= 1.2) {\n\t\tquery = ctx.getNodeParameter('query', itemIndex) as string;\n\t} else {\n\t\tquery = getPromptInputByType({\n\t\t\tctx,\n\t\t\ti: itemIndex,\n\t\t\tinputKey: 'text',\n\t\t\tpromptTypeKey: 'promptType',\n\t\t});\n\t}\n\n\tif (query === undefined) {\n\t\tthrow new NodeOperationError(ctx.getNode(), 'The ‘query‘ parameter is empty.');\n\t}\n\n\tconst options = ctx.getNodeParameter('options', itemIndex, {}) as {\n\t\tsystemPromptTemplate?: string;\n\t};\n\n\tlet templateText = options.systemPromptTemplate ?? SYSTEM_PROMPT_TEMPLATE;\n\n\t// Replace legacy input template key for versions 1.4 and below\n\tif (ctx.getNode().typeVersion < 1.5) {\n\t\ttemplateText = templateText.replace(\n\t\t\t`{${LEGACY_INPUT_TEMPLATE_KEY}}`,\n\t\t\t`{${INPUT_TEMPLATE_KEY}}`,\n\t\t);\n\t}\n\n\t// Create prompt template based on model type and user configuration\n\tlet promptTemplate;","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/nodes-langchain/nodes/chains/ChainRetrievalQA/processItem.ts#L29-L65","documentation":"Thrown by ChainRetrievalQA processItem when the resolved 'query' value is undefined. For typeVersion <= 1.2 the query is read directly from the 'query' parameter; for newer versions it is resolved through getPromptInputByType with inputKey 'text'. The Retrieval QA chain needs a query string to ask the retriever+LLM.","triggerScenarios":"The query/text expression evaluates to undefined for the current itemIndex. The chain cannot construct a question to send to the retrieval-augmented LLM call.","commonSituations":"The query expression references a JSON field that does not exist on the input item; the user left the query blank; the prompt source was changed but no value provided; upstream node changed its output schema.","solutions":["Open the Retrieval QA Chain and verify the query/text expression resolves to a non-empty string for every item.","Provide a fallback in the expression: {{$json.question || 'What is this document about?'}}.","Inspect the failing itemIndex to identify the missing field.","Filter items lacking the query field upstream."],"exampleFix":"// before\nif (query === undefined) {\n  throw new NodeOperationError(ctx.getNode(), 'The query parameter is empty.');\n}\n\n// after — reject empty strings, include itemIndex\nif (!query?.trim()) {\n  throw new NodeOperationError(ctx.getNode(), {\n    message: 'The query parameter is empty.',\n    itemIndex,\n  });\n}","handlingStrategy":"validation","validationCode":"let query: string;\nif (ctx.getNode().typeVersion <= 1.2) {\n  query = ctx.getNodeParameter('query', itemIndex) as string;\n} else {\n  query = getPromptInputByType({ ctx, i: itemIndex, inputKey: 'text', promptTypeKey: 'promptType' });\n}\nif (!query?.trim()) {\n  throw new Error(`Query is empty for item ${itemIndex}`);\n}","typeGuard":"function isNonEmptyString(v: unknown): v is string {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":null,"preventionTips":["Provide a fallback in the query expression: {{$json.question || 'What is this?'}}.","Filter items with empty queries upstream.","Verify the upstream output schema before referencing fields."],"tags":["configuration","parameter-validation","retrieval-qa","per-item"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}