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 array output.
What it means
enumValues apply only to output: 'enum'. With output: 'array' the model produces a JSON array of elements shaped by the element schema, so enumValues is invalid and InvalidArgumentError is thrown.
Source
Thrown at packages/ai/src/generate-object/validate-object-generation-input.ts:93
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({
parameter: 'enumValues',
value: enumValues,
message: 'Enum values are not supported for array output.',
});
}
}
if (output === 'enum') {
if (schema != null) {
throw new InvalidArgumentError({
parameter: 'schema',
value: schema,
message: 'Schema is not supported for enum output.',
});
}
if (schemaDescription != null) {
throw new InvalidArgumentError({View on GitHub (pinned to 69428b1f8b)
Solutions
- Remove enumValues from the array-output call.
- If you need an array of enum values, use output: 'array' with schema: z.enum(['a','b']).
- If you need a single enum pick, use output: 'enum' instead.
Example fix
// before
generateObject({ model, output: 'array', schema, enumValues: ['a','b'], prompt });
// after
generateObject({ model, output: 'array', schema: z.enum(['a','b']), prompt }); Defensive patterns
Strategy: validation
Validate before calling
if (opts.output === 'array' && opts.enumValues != null) {
throw new Error("enumValues are only valid with output: 'enum'");
} Type guard
function isArrayOptionsWithoutEnum(opts) {
return opts.output !== 'array' || 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
- For arrays of enum values use schema: z.enum([...]) with output: 'array'.
- Keep enumValues out of shared option factories.
- Type options per output mode so invalid combinations fail at compile time.
When it happens
Trigger: Calling generateObject({ model, output: 'array', schema, enumValues: [...] }) or streamObject with the same combination.
Common situations: Shared options object reused across enum and array calls; converting an enum-generation call to array output without removing enumValues; abstraction layers that always include enumValues.
Related errors
- Invalid argument for parameter enumValues: Enum values are n
- Invalid argument for parameter enumValues: Enum values are n
- Invalid argument for parameter schema: Element schema is req
- Invalid argument for parameter schema: Schema is not support
- Invalid argument for parameter schemaDescription: Schema des
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/5c827e9cb46efb8b.
Report an issue: GitHub.