sequelize/sequelize · error · TypeError

Invalid validator function

Error message

Invalid validator function: ${validatorType}

What it means

In `_invokeBuiltinValidator` (instance-validator.js:348), Sequelize resolves each attribute validator by name against the validator.js `Validator` object. If `typeof Validator[validatorType] !== 'function'` (instance-validator.js:352), the declared key is neither a recognized built-in validator nor a custom function (custom functions are handled earlier in `_singleAttrValidate`), so it throws a TypeError. This catches misspelled validator names and non-function values placed under an attribute's `validate` object.

Solutions

  1. Check the validator name spelling against the validator.js method list (isEmail, isUrl, notEmpty, isInt, len, etc.).
  2. If the validator is custom, make its value a function: `validate: { myRule(value) { ... } }`.
  3. Confirm the validator.js version bundled with your Sequelize release still exposes that method.

Example fix

// before
email: { type: DataTypes.STRING, validate: { isEmial: true } }

// after
email: { type: DataTypes.STRING, validate: { isEmail: true } }
Defensive patterns

Strategy: type-guard

Validate before calling

import validator from 'validator';

function assertValidAttributeValidators(validateObj) {
  for (const [name, spec] of Object.entries(validateObj || {})) {
    if (typeof spec === 'function') continue; // custom validator ok
    if (typeof validator[name] !== 'function') {
      throw new Error(`Unknown built-in validator '${name}'. Fix the name or make it a function.`);
    }
  }
}

// run before Model.init
assertValidAttributeValidators(attrDef.validate);

Type guard

function isKnownValidator(key, val) {
  return typeof val === 'function' || typeof validator[key] === 'function';
}

Prevention

When it happens

Trigger: Defining an attribute with `validate: { isEmial: true }` (typo), `validate: { myRule: 'yes' }` (string value with a key that is not a validator.js method), or any non-function value whose key does not exist on validator.js's Validator.

Common situations: Typos in built-in validator names (isEmial vs isEmail, notEmpty vs notempty); copy-pasting a custom validator name but forgetting to make the value a function; mismatched validator.js version that renamed/removed a method.

Related errors


AI-assisted analysis of sequelize/sequelize@7e1deec499 (2026-08-03). Data as JSON: /api/errors/07e0717b38b5f659. Report an issue: GitHub.

Appendix: source

Thrown at packages/core/src/instance-validator.js:353

  /**
   * Prepare and invoke a build-in validator.
   *
   * @private
   *
   * @param {*} value Anything.
   * @param {*} test The test case.
   * @param {string} validatorType One of known to Sequelize validators.
   * @param {string} field The field that is being validated
   *
   * @returns {object} An object with specific keys to invoke the validator.
   */
  async _invokeBuiltinValidator(value, test, validatorType, field) {
    // Cast value as string to pass new Validator.js string requirement
    const valueString = String(value);
    // check if Validator knows that kind of validation test
    if (typeof Validator[validatorType] !== 'function') {
      throw new TypeError(`Invalid validator function: ${validatorType}`);
    }

    const validatorArgs = this._extractValidatorArgs(test, validatorType, field);

    if (!Validator[validatorType](valueString, ...validatorArgs)) {
      throw Object.assign(new Error(test.msg || `Validation ${validatorType} on ${field} failed`), {
        validatorName: validatorType,
        validatorArgs,
      });
    }
  }

  /**
   * Will extract arguments for the validator.
   *
   * @param {*} test The test case.
   * @param {string} validatorType One of known to Sequelize validators.
   * @param {string} field The field that is being validated.

View on GitHub (pinned to 7e1deec499)