vercel/ai · error · InvalidArgumentError

Invalid argument for parameter enumValues: Enum values are n

Error message

Invalid argument for parameter enumValues: Enum values are not supported for object output.

What it means

enumValues are only meaningful with output: 'enum'. When output is 'object', the model generates a structured object from the schema, so supplying enumValues is contradictory and the library throws InvalidArgumentError.

Source

Thrown at packages/ai/src/generate-object/validate-object-generation-input.ts:75

      throw new InvalidArgumentError({
        parameter: 'enumValues',
        value: enumValues,
        message: 'Enum values are not supported for no-schema output.',
      });
    }
  }

  if (output === 'object') {
    if (schema == null) {
      throw new InvalidArgumentError({
        parameter: 'schema',
        value: schema,
        message: 'Schema is required for object output.',
      });
    }

    if (enumValues != null) {
      throw new InvalidArgumentError({
        parameter: 'enumValues',
        value: enumValues,
        message: 'Enum values are not supported for object output.',
      });
    }
  }

  if (output === 'array') {
    if (schema == null) {
      throw new InvalidArgumentError({
        parameter: 'schema',
        value: schema,
        message: 'Element schema is required for array output.',
      });
    }

    if (enumValues != null) {
      throw new InvalidArgumentError({

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Remove enumValues from the object-output call.
  2. If you need the model to pick one value, change to output: 'enum' with enumValues (no schema).
  3. If choices belong inside the object, model them in the schema (e.g. a z.enum field).

Example fix

// before
generateObject({ model, schema, output: 'object', enumValues: ['a','b'], prompt });
// after
generateObject({ model, schema: z.object({ choice: z.enum(['a','b']) }), output: 'object', prompt });
Defensive patterns

Strategy: validation

Validate before calling

if ((opts.output ?? 'object') === 'object' && opts.enumValues != null) {
  throw new Error("enumValues are only valid with output: 'enum'");
}

Type guard

function isObjectOptionsWithoutEnum(opts) {
  return (opts.output ?? 'object') === 'object' && opts.enumValues == null;
}

Try / catch

try {
  return await generateObject(opts);
} catch (error) {
  if (InvalidArgumentError.isInstance(error) && error.parameter === 'enumValues') {
    const { enumValues, ...rest } = opts;
    return generateObject(rest);
  }
  throw error;
}

Prevention

When it happens

Trigger: Calling generateObject({ model, schema, output: 'object', enumValues: [...] }) or streamObject with the same; omitting output explicitly (defaults to 'object') while passing enumValues also triggers it.

Common situations: Generic wrapper that always passes enumValues; refactoring an enum call to object output without removing enumValues; merging option objects where enumValues leaks in from another call.

Related errors


AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30). Data as JSON: /api/errors/3e124b9f930aaf16. Report an issue: GitHub.