medusajs/medusa · error · MedusaError

Rule value must be a string, bool, number value for the sele

Error message

Rule value must be a string, bool, number value for the selected operator ${rule.operator}

What it means

For operators other than in/nin, the rule value must be a scalar (string, boolean, or number). Passing an array or object throws INVALID_DATA.

Source

Thrown at packages/modules/fulfillment/src/utils/utils.ts:138

  if (!availableOperators.includes(rule.operator as RuleOperator)) {
    throw new MedusaError(
      MedusaError.Types.INVALID_DATA,
      `Rule operator ${
        rule.operator
      } is not supported. Must be one of ${availableOperators.join(", ")}`
    )
  }

  if (rule.operator === RuleOperator.IN || rule.operator === RuleOperator.NIN) {
    if (!Array.isArray(rule.value)) {
      throw new MedusaError(
        MedusaError.Types.INVALID_DATA,
        "Rule value must be an array for in/nin operators"
      )
    }
  } else {
    if (Array.isArray(rule.value) || isObject(rule.value)) {
      throw new MedusaError(
        MedusaError.Types.INVALID_DATA,
        `Rule value must be a string, bool, number value for the selected operator ${rule.operator}`
      )
    }
  }

  return true
}

export function normalizeRulesValue<T extends Partial<Rule>>(rules: T[]): void {
  rules.forEach((rule: any) => {
    /**
     * If a boolean is provided, then we convert to string
     */
    if (rule.value === true || rule.value === false) {
      rule.value = rule.value === true ? "true" : "false"
    }

View on GitHub (pinned to 5e06e544a2)

Solutions

  1. Unwrap scalars: value: 100 not [100]
  2. Switch to in/nin if you genuinely need a list of values

Example fix

// before
rules: [{ attribute: 'cart_total', operator: 'gt', value: [100] }]
// after
rules: [{ attribute: 'cart_total', operator: 'gt', value: 100 }]
Defensive patterns

Strategy: validation

Validate before calling

if (!['in','nin'].includes(rule.operator) && (Array.isArray(rule.value) || typeof rule.value === 'object')) throw new TypeError('Scalar value required')

Type guard

const isScalarValue = (v: unknown): boolean => ['string','boolean','number'].includes(typeof v)

Prevention

When it happens

Trigger: rules: [{ attribute: 'cart_total', operator: 'gt', value: [100] }] or value: { amount: 100 }.

Common situations: Reusing an array value from an 'in' rule on a comparison operator; sending nested JSON from a generic form builder.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27). Data as JSON: /api/errors/8efb7ed1bba84366. Report an issue: GitHub.