n8n-io/n8n · error · NodeOperationError

The ‘query‘ parameter is empty.

Error message

The ‘query‘ parameter is empty.

What it means

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.

Source

Thrown at packages/@n8n/nodes-langchain/nodes/chains/ChainRetrievalQA/processItem.ts:47

		NodeConnectionTypes.AiRetriever,
		0,
	)) as BaseRetriever;

	let query;

	if (ctx.getNode().typeVersion <= 1.2) {
		query = ctx.getNodeParameter('query', itemIndex) as string;
	} else {
		query = getPromptInputByType({
			ctx,
			i: itemIndex,
			inputKey: 'text',
			promptTypeKey: 'promptType',
		});
	}

	if (query === undefined) {
		throw new NodeOperationError(ctx.getNode(), 'The ‘query‘ parameter is empty.');
	}

	const options = ctx.getNodeParameter('options', itemIndex, {}) as {
		systemPromptTemplate?: string;
	};

	let templateText = options.systemPromptTemplate ?? SYSTEM_PROMPT_TEMPLATE;

	// Replace legacy input template key for versions 1.4 and below
	if (ctx.getNode().typeVersion < 1.5) {
		templateText = templateText.replace(
			`{${LEGACY_INPUT_TEMPLATE_KEY}}`,
			`{${INPUT_TEMPLATE_KEY}}`,
		);
	}

	// Create prompt template based on model type and user configuration
	let promptTemplate;

View on GitHub (pinned to 5ac6606e81)

Solutions

  1. Open the Retrieval QA Chain and verify the query/text expression resolves to a non-empty string for every item.
  2. Provide a fallback in the expression: {{$json.question || 'What is this document about?'}}.
  3. Inspect the failing itemIndex to identify the missing field.
  4. Filter items lacking the query field upstream.

Example fix

// before
if (query === undefined) {
  throw new NodeOperationError(ctx.getNode(), 'The query parameter is empty.');
}

// after — reject empty strings, include itemIndex
if (!query?.trim()) {
  throw new NodeOperationError(ctx.getNode(), {
    message: 'The query parameter is empty.',
    itemIndex,
  });
}
Defensive patterns

Strategy: validation

Validate before calling

let query: string;
if (ctx.getNode().typeVersion <= 1.2) {
  query = ctx.getNodeParameter('query', itemIndex) as string;
} else {
  query = getPromptInputByType({ ctx, i: itemIndex, inputKey: 'text', promptTypeKey: 'promptType' });
}
if (!query?.trim()) {
  throw new Error(`Query is empty for item ${itemIndex}`);
}

Type guard

function isNonEmptyString(v: unknown): v is string {
  return typeof v === 'string' && v.trim().length > 0;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12). Data as JSON: /api/errors/ebdf8a4a2ea73b29. Report an issue: GitHub.