FlowiseAI/Flowise · error · Error

enum requires array of values

Error message

enum requires array of values

What it means

Thrown in buildZodSchema's `enum` case when the parsed type info does not carry an array as its first base argument. `z.enum(...)` in Zod requires a non-empty tuple of string literals, so the secure parser refuses to construct it without one.

Source

Thrown at packages/components/src/secureZodParser.ts:616

        switch (typeInfo.base) {
            case 'string':
                zodType = z.string()
                break
            case 'number':
                zodType = z.number()
                break
            case 'boolean':
                zodType = z.boolean()
                break
            case 'date':
                zodType = z.date()
                break
            case 'enum':
                if (typeInfo.baseArgs && typeInfo.baseArgs[0] && Array.isArray(typeInfo.baseArgs[0])) {
                    const enumValues = typeInfo.baseArgs[0] as [string, ...string[]]
                    zodType = z.enum(enumValues)
                } else {
                    throw new Error('enum requires array of values')
                }
                break
            default:
                throw new Error(`Unsupported base type: ${typeInfo.base}`)
        }

        // Apply modifiers
        zodType = this.applyModifiers(zodType, typeInfo.modifiers || [])

        return zodType
    }

    private static applyModifiers(zodType: z.ZodTypeAny, modifiers: any[]): z.ZodTypeAny {
        for (const modifier of modifiers) {
            switch (modifier.name) {
                case 'int':
                    if (zodType._def?.typeName === 'ZodNumber') {
                        zodType = (zodType as z.ZodNumber).int()

View on GitHub (pinned to abe4a8601a)

Solutions

  1. Write the enum values as an array literal, e.g. `z.enum(["red","green","blue"])`.
  2. Ensure at least one value is present — an empty array is not a valid Zod enum.
  3. If the schema is generated, confirm the generator emits the array form expected by the parser.

Example fix

// before
const schema = "z.object({ color: z.enum() })"
// after
const schema = "z.object({ color: z.enum([\"red\",\"green\",\"blue\"]) })"
Defensive patterns

Strategy: validation

Validate before calling

function validateEnumSchema(schemaStr: string): string[] {
  const issues: string[] = []
  for (const m of schemaStr.matchAll(/z\.enum\s*\(([^)]*)\)/g)) {
    const args = m[1].trim()
    if (!args.startsWith('[') || !/\[[^\]]*\]/.test(args)) issues.push('enum must be given an array literal')
  }
  return issues
}

Type guard

function hasEnumValues(baseArgs: unknown): baseArgs is [string, ...string[]] {
  return Array.isArray(baseArgs) && Array.isArray(baseArgs[0]) && (baseArgs[0] as unknown[]).length > 0 &&
    (baseArgs[0] as unknown[]).every(v => typeof v === 'string')
}

Try / catch

try {
  const schema = SecureZodSchemaParser.parseZodSchema(schemaStr)
} catch (e) {
  if (/enum requires array of values/.test(e.message)) {
    // rewrite enum as z.enum(["a","b"]) and retry
  }
  throw e
}

Prevention

When it happens

Trigger: A schema string like `z.enum()` with no values, or `z.enum('a')`/`z.enum("a","b")` where the argument parser failed to surface the values as an array in typeInfo.baseArgs[0]. The guard is `typeInfo.baseArgs && typeInfo.baseArgs[0] && Array.isArray(typeInfo.baseArgs[0])` at secureZodParser.ts:612.

Common situations: Forgetting the array brackets in an enum schema; a malformed schema string where the argument extractor did not recognize the literal array syntax.

Related errors


AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12). Data as JSON: /api/errors/13b31cd4fc8aca58. Report an issue: GitHub.