{"id":"9f9196f7bc65316c","repo":"sequelize/sequelize","slug":"could-not-guess-type-of-value-logger-inspect-val-9f9196","errorCode":null,"errorMessage":"Could not guess type of value ${logger.inspect(val)}","messagePattern":"Could not guess type of value (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/core/src/sql-string.ts","lineNumber":71,"sourceCode":"\n      if (Buffer.isBuffer(val)) {\n        // TODO: remove dialect-specific hack\n        if (dialect.name === 'ibmi') {\n          return new DataTypes.STRING().toDialectDataType(dialect);\n        }\n\n        return new DataTypes.BLOB().toDialectDataType(dialect);\n      }\n\n      break;\n\n    case 'string':\n      return getTextDataTypeForDialect(dialect);\n\n    default:\n  }\n\n  throw new TypeError(`Could not guess type of value ${logger.inspect(val)}`);\n}\n","sourceCodeStart":53,"sourceCodeEnd":73,"githubUrl":"https://github.com/sequelize/sequelize/blob/7e1deec499d5afbb8d1877c2f4d545cead1214ec/packages/core/src/sql-string.ts#L53-L73","documentation":"Sequelize throws this when it must serialize a value to SQL but no data type was declared for it, so it falls back to bestGuessDataTypeOfVal to infer one from the JS value. The function handles bigint, number, boolean, string, Date, Buffer, and arrays, but rejects anything else. Hitting the catch-all throw means the value is null/undefined/symbol/function or a plain object the dialect cannot map to a column type.","triggerScenarios":"Called from AbstractQueryGenerator#escape value path (query-generator-typescript.ts:867) when `type` is null/undefined or a raw string. Produces it for: a WHERE literal of `undefined`/`null` reaching the inferrer instead of being short-circuited, a `Symbol`, a `function`, a class instance, or a plain object (not Date/Buffer/Array) used as a query value or bind param without an explicit DataType.","commonSituations":"Passing `undefined` instead of `null` in a where value (e.g. `{ where: { id: someVar } }` where someVar is undefined); storing a custom class instance or Map/Set without declaring its DataType; raw queries with `QueryTypes` values sequelize can't introspect; upgrading from v6 where some values were stringified silently.","solutions":["Ensure the value is defined before querying; convert `undefined` to `null` explicitly so sequelize emits NULL.","Provide an explicit DataType on the column or in the query options so sequelize does not have to guess.","Serialize custom objects (class instances, Map/Set) to a primitive (string/number) or Buffer/Date before passing them.","If you genuinely need to store structured data, use a JSON column and pass a serializable plain object via the model's DataType, not a raw value through the inferrer."],"exampleFix":"// before\nawait User.findAll({ where: { email: maybeUndefined } }); // maybeUndefined is undefined\n\n// after\nawait User.findAll({ where: { email: maybeUndefined ?? null } });","handlingStrategy":"validation","validationCode":"function isValidQueryableValue(v) {\n  if (v === undefined) return false;\n  const t = typeof v;\n  if (t === 'symbol' || t === 'function') return false;\n  if (v === null) return true; // handled as NULL\n  if (t === 'bigint' || t === 'number' || t === 'boolean' || t === 'string') return true;\n  if (v instanceof Date || Buffer.isBuffer(v)) return true;\n  if (Array.isArray(v)) return v.length > 0 && isValidQueryableValue(v[0]);\n  return false; // plain object, Map, Set, class instance\n}\n// before querying:\nconst value = maybeUndef ?? null;\nif (!isValidQueryableValue(value)) throw new TypeError(`Unsupported query value: ${value}`);","typeGuard":"function isInferrableValue(v: unknown): v is string | number | bigint | boolean | Date | Buffer | Array<unknown> {\n  if (v == null || typeof v === 'symbol' || typeof v === 'function') return false;\n  if (v instanceof Date || Buffer.isBuffer(v)) return true;\n  if (Array.isArray(v)) return v.length > 0 && isInferrableValue(v[0]);\n  return ['string','number','bigint','boolean'].includes(typeof v);\n}","tryCatchPattern":null,"preventionTips":["Always coerce undefined to null at the boundary where query values enter your code.","Declare explicit DataTypes on columns so sequelize never has to infer.","Serialize class instances/Map/Set to primitives or use JSON columns.","Add a runtime assertion in dev/test that asserts every where-value is inferrable."],"tags":["sql","data-type","query","validation"],"analyzedSha":"7e1deec499d5afbb8d1877c2f4d545cead1214ec","analyzedAt":"2026-08-03T18:58:44.549Z","schemaVersion":2}