n8n-io/n8n · error · NodeOperationError
Cannot embed empty or undefined text
Error message
Cannot embed empty or undefined text
What it means
validateEmbedQueryInput() guards embedQuery(): the query must be a non-empty string. If it is undefined, null, or '' the embedding call would send nothing meaningful to the provider, so it throws a NodeOperationError with a description explaining the common causes (expression evaluated to undefined, the agent called a tool without proper arguments, a required field is missing).
Source
Thrown at packages/@n8n/ai-utilities/src/utils/embeddings-input-validation.ts:15
import type { INode } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
/**
* Validates query input for embedQuery operations.
* Throws NodeOperationError if query is invalid (undefined, null, or empty string).
*
* @param query - The query to validate
* @param node - The node for error context
* @returns The validated query string
* @throws NodeOperationError if query is invalid
*/
export function validateEmbedQueryInput(query: unknown, node: INode): string {
if (typeof query !== 'string' || query === '') {
throw new NodeOperationError(node, 'Cannot embed empty or undefined text', {
description:
'The text provided for embedding is empty or undefined. This can happen when: the input expression evaluates to undefined, the AI agent calls a tool without proper arguments, or a required field is missing.',
});
}
return query;
}
/**
* Validates documents input for embedDocuments operations.
* Throws NodeOperationError if documents array is invalid or contains invalid entries.
*
* @param documents - The documents array to validate
* @param node - The node for error context
* @returns The validated documents array
* @throws NodeOperationError if documents is not an array or contains invalid entries
*/
export function validateEmbedDocumentsInput(documents: unknown, node: INode): string[] {
if (!Array.isArray(documents)) {View on GitHub (pinned to 5ac6606e81)
Solutions
- Ensure the field feeding the embedding input actually contains a non-empty string (use Set/Edit nodes to default it).
- Guard upstream: skip the embedding node when the input is empty (`if ($json.text)`).
- If the agent omitted the argument, fix the tool's parameter schema/description so the model supplies it.
Example fix
// before
await embedQuery($json.maybeMissing, ...);
// after
const text = typeof $json.text === 'string' ? $json.text.trim() : '';
if (!text) throw new Error('embedding input empty');
await embedQuery(text, ...); Defensive patterns
Strategy: validation
Validate before calling
import { validateEmbedQueryInput } from '@n8n/ai-utilities';
// or inline:
function nonEmptyString(v: unknown): v is string {
return typeof v === 'string' && v.length > 0;
}
if (!nonEmptyString(query)) {
throw new Error('embed query must be a non-empty string');
} Type guard
function isNonEmptyString(v: unknown): v is string {
return typeof v === 'string' && v.trim().length > 0;
} Prevention
- Default the embedding input field with a Set/Edit node so it's never undefined.
- Skip the embedding node when the input is empty (conditional branch).
- Make the tool's text parameter required in the schema so the LLM supplies it.
When it happens
Trigger: An embedding node/agent receives an undefined input because the source expression resolved to nothing; the AI agent invoked an embedding tool with no query argument; a previous node emitted an empty item field that is mapped to the embedding input.
Common situations: An expression like `{{ $json.missingField }}` returns undefined; a tool-calling LLM omitted the required text argument; a filter/transform step produced an empty string; first-run item with no payload.
Related errors
- Documents must be an array
- Unknown model discovery provider: "${provider}"
- Unsupported provider
- Invalid categor${invalidCategories.length > 1 ? 'ies' : 'y'}
- Provider connection data cannot be empty
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/b51a69e7bd498146.
Report an issue: GitHub.