{"record":{"id":"4fbeb2db5e90daa5","repo":"n8n-io/n8n","slug":"filter-operator-operator-on-key-key-requ","errorCode":null,"errorMessage":"Filter operator \"${operator}\" on key \"${key}\" requires a non-empty array value.","messagePattern":"Filter operator \"(.+?)\" on key \"(.+?)\" requires a non-empty array value\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/agents/src/sdk/vector-store-filter.ts","lineNumber":50,"sourceCode":"/** Validates operator/value pairing per condition; throws rather than silently ignoring a bad filter. */\nexport function assertValidFilter(filter: VectorFilter): void {\n\tfor (const condition of filter.conditions) {\n\t\tassertValidCondition(condition);\n\t}\n}\n\nfunction assertValidCondition(condition: FilterCondition): void {\n\tconst { key, operator, value } = condition;\n\n\tif (!(FILTER_OPERATORS as readonly string[]).includes(operator)) {\n\t\tthrow new Error(\n\t\t\t`Invalid filter operator \"${operator}\" for key \"${key}\". Supported operators: ${FILTER_OPERATORS.join(', ')}`,\n\t\t);\n\t}\n\n\tif (operator === 'in' || operator === 'nin') {\n\t\tif (!Array.isArray(value) || value.length === 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`Filter operator \"${operator}\" on key \"${key}\" requires a non-empty array value.`,\n\t\t\t);\n\t\t}\n\t\tif (value.some((v) => typeof v !== 'string' && typeof v !== 'number')) {\n\t\t\tthrow new Error(\n\t\t\t\t`Filter operator \"${operator}\" on key \"${key}\" requires array elements to be strings or numbers.`,\n\t\t\t);\n\t\t}\n\t\treturn;\n\t}\n\n\t// eq, ne\n\tif (typeof value !== 'string' && typeof value !== 'number' && typeof value !== 'boolean') {\n\t\tthrow new Error(\n\t\t\t`Filter operator \"${operator}\" on key \"${key}\" requires a string, number, or boolean value.`,\n\t\t);\n\t}\n}","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/agents/src/sdk/vector-store-filter.ts#L32-L68","documentation":"For the 'in' and 'nin' set-membership operators, assertValidCondition requires the value to be a non-empty array. An empty array would make the filter a no-op or match nothing depending on backend semantics; a non-array value is a type mismatch. The validator rejects both cases rather than coercing, so silent no-ops never reach the vector store.","triggerScenarios":"Calling search with filter: { conditions: [{ key: 'tag', operator: 'in', value: [] }] } (empty array) or { ... operator: 'in', value: 'x' } (scalar instead of array). Also triggered by arrays that exist but have length 0 due to upstream filtering producing no candidates.","commonSituations":"Passing a dynamically-built array that ended up empty after filtering; confusing 'in' (set) with 'eq' (scalar); copying a value from an eq condition into an in condition without wrapping in an array.","solutions":["Ensure the value is an array with at least one element: value: ['x', 'y'] for 'in'.","If the candidate array may be empty (e.g. user selected nothing), short-circuit and skip the search or omit that condition rather than passing value: [].","Use 'eq' with a scalar value instead of 'in' when you only have a single value."],"exampleFix":"// before\nstore.search('q', {\n  filter: { conditions: [{ key: 'tag', operator: 'in', value: [] }], combineWith: 'and' },\n}); // throws\n\n// after — guard the empty case\nconst tags = selectedTags.length\n  ? [{ key: 'tag', operator: 'in', value: selectedTags }]\n  : [];\nstore.search('q', { filter: { conditions: tags, combineWith: 'and' } });","handlingStrategy":"validation","validationCode":"function inCondition(key: string, values: unknown[]) {\n  if (!Array.isArray(values) || values.length === 0) {\n    throw new Error(`'in' filter on ${key} requires a non-empty array`);\n  }\n  return { key, operator: 'in' as const, value: values };\n}","typeGuard":"function isNonEmptyArray<T>(v: unknown): v is [T, ...T[]] {\n  return Array.isArray(v) && v.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Omit 'in'/'nin' conditions entirely when the candidate array is empty rather than passing value: [].","Validate array length at the form/API layer before constructing the filter.","Prefer 'eq' for single values to avoid the array-shape requirement."],"tags":["vector-store","filter","validation","array"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}