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 no-schema output.

What it means

enumValues powers enum-style output (output: 'enum'), where the model must pick one of the given values. Passing enumValues together with output: 'no-schema' is contradictory because no-schema output has no constrained value set, so InvalidArgumentError is thrown.

Source

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

    if (schemaDescription != null) {
      throw new InvalidArgumentError({
        parameter: 'schemaDescription',
        value: schemaDescription,
        message: 'Schema description is not supported for no-schema output.',
      });
    }

    if (schemaName != null) {
      throw new InvalidArgumentError({
        parameter: 'schemaName',
        value: schemaName,
        message: 'Schema name is not supported for no-schema output.',
      });
    }

    if (enumValues != null) {
      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({

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Remove enumValues when using output: 'no-schema'.
  2. If the model should choose from fixed values, set output: 'enum' and keep enumValues.
  3. Constrain choices via prompt wording if you truly need free-form output.

Example fix

// before
generateObject({ model, output: 'no-schema', enumValues: ['small','large'], prompt });
// after
generateObject({ model, output: 'enum', enumValues: ['small','large'], prompt });
Defensive patterns

Strategy: validation

Validate before calling

if (opts.output === 'no-schema' && opts.enumValues != null) {
  throw new Error("enumValues require output: 'enum'");
}

Type guard

function isEnumOnlyOptions(opts) {
  return opts.enumValues != null ? opts.output === 'enum' : true;
}

Try / catch

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

Prevention

When it happens

Trigger: Calling generateObject({ model, output: 'no-schema', enumValues: ['a','b'], prompt }) or streamObject with the same; any non-null enumValues with no-schema output triggers it.

Common situations: Dynamic code that switches output mode but always includes enumValues; copy-pasted enum-generation call whose output field was changed to no-schema; generic wrapper building options for multiple output types.

Related errors


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