{"record":{"id":"b51a69e7bd498146","repo":"n8n-io/n8n","slug":"cannot-embed-empty-or-undefined-text","errorCode":null,"errorMessage":"Cannot embed empty or undefined text","messagePattern":"Cannot embed empty or undefined text","errorType":"validation","errorClass":"NodeOperationError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/ai-utilities/src/utils/embeddings-input-validation.ts","lineNumber":15,"sourceCode":"import type { INode } from 'n8n-workflow';\nimport { NodeOperationError } from 'n8n-workflow';\n\n/**\n * Validates query input for embedQuery operations.\n * Throws NodeOperationError if query is invalid (undefined, null, or empty string).\n *\n * @param query - The query to validate\n * @param node - The node for error context\n * @returns The validated query string\n * @throws NodeOperationError if query is invalid\n */\nexport function validateEmbedQueryInput(query: unknown, node: INode): string {\n\tif (typeof query !== 'string' || query === '') {\n\t\tthrow new NodeOperationError(node, 'Cannot embed empty or undefined text', {\n\t\t\tdescription:\n\t\t\t\t'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.',\n\t\t});\n\t}\n\treturn query;\n}\n\n/**\n * Validates documents input for embedDocuments operations.\n * Throws NodeOperationError if documents array is invalid or contains invalid entries.\n *\n * @param documents - The documents array to validate\n * @param node - The node for error context\n * @returns The validated documents array\n * @throws NodeOperationError if documents is not an array or contains invalid entries\n */\nexport function validateEmbedDocumentsInput(documents: unknown, node: INode): string[] {\n\tif (!Array.isArray(documents)) {","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/ai-utilities/src/utils/embeddings-input-validation.ts#L1-L33","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nawait embedQuery($json.maybeMissing, ...);\n\n// after\nconst text = typeof $json.text === 'string' ? $json.text.trim() : '';\nif (!text) throw new Error('embedding input empty');\nawait embedQuery(text, ...);","handlingStrategy":"validation","validationCode":"import { validateEmbedQueryInput } from '@n8n/ai-utilities';\n// or inline:\nfunction nonEmptyString(v: unknown): v is string {\n  return typeof v === 'string' && v.length > 0;\n}\nif (!nonEmptyString(query)) {\n  throw new Error('embed query must be a non-empty string');\n}","typeGuard":"function isNonEmptyString(v: unknown): v is string {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["embeddings","validation","user-error","ai-utilities"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}