{"record":{"id":"c64908eecba9a73a","repo":"n8n-io/n8n","slug":"filter-operator-operator-on-key-key-requ-c64908","errorCode":null,"errorMessage":"Filter operator \"${operator}\" on key \"${key}\" requires a string, number, or boolean value.","messagePattern":"Filter operator \"(.+?)\" on key \"(.+?)\" requires a string, number, or boolean value\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/agents/src/sdk/vector-store-filter.ts","lineNumber":64,"sourceCode":"\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}\n\nfunction isNonEmptyArray(arr: string[]): arr is [string, ...string[]] {\n\treturn arr.length > 0;\n}\n\n/** Builds the zod schema for the model-facing `filter` tool input, scoped to `keys` (key -> description). */\nexport function buildFilterInputSchema(keys: Record<string, string>) {\n\tconst keyNames = Object.keys(keys);\n\tif (!isNonEmptyArray(keyNames)) {\n\t\tthrow new Error('filterableKeys must contain at least one key');\n\t}\n\n\tconst keyDescriptions = keyNames.map((key) => `- ${key}: ${keys[key]}`).join('\\n');\n","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/agents/src/sdk/vector-store-filter.ts#L46-L82","documentation":"For the scalar operators 'eq' and 'ne', assertValidCondition requires the value to be a string, number, or boolean. Arrays, objects, null, and undefined are rejected because scalar equality against non-scalars has no consistent meaning across vector store backends. This is the final fallthrough check after the in/nin branch returns.","triggerScenarios":"Calling search with filter: { conditions: [{ key: 'tag', operator: 'eq', value: ['x'] }] } (array for scalar op), value: { id: 1 } (object), or value: null. Also hit by value: undefined when a field is missing.","commonSituations":"Wrapping a single value in an array by mistake; passing an object that should be reduced to one of its scalar fields; null leaking from optional form fields; using 'eq' where 'in' was intended for a set.","solutions":["Pass a single primitive: value: 'x', value: 42, or value: true for 'eq'/'ne'.","If you have an array, switch the operator to 'in'/'nin' instead of 'eq' with an array value.","Reduce objects to their scalar key before building the condition: value: obj.id."],"exampleFix":"// before\nstore.search('q', {\n  filter: { conditions: [{ key: 'tag', operator: 'eq', value: ['x'] }], combineWith: 'and' },\n}); // throws\n\n// after — single scalar\nstore.search('q', {\n  filter: { conditions: [{ key: 'tag', operator: 'eq', value: 'x' }], combineWith: 'and' },\n});","handlingStrategy":"type-guard","validationCode":"function eqCondition(key: string, value: unknown) {\n  if (typeof value !== 'string' && typeof value !== 'number' && typeof value !== 'boolean') {\n    throw new Error(`'eq' filter on ${key} requires a string, number, or boolean`);\n  }\n  return { key, operator: 'eq' as const, value };\n}","typeGuard":"function isScalarValue(v: unknown): v is string | number | boolean {\n  return typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean';\n}","tryCatchPattern":null,"preventionTips":["Use 'eq'/'ne' only with single primitive values; switch to 'in' for sets.","Reduce objects to their scalar key before building a scalar condition.","Guard optional/null fields before constructing eq conditions."],"tags":["vector-store","filter","validation","type-mismatch"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}