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
- Remove enumValues from the object-output call.
- If you need the model to pick one value, change to output: 'enum' with enumValues (no schema).
- 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
- Express allowed values inside the schema with z.enum fields.
- Never merge enum-call options into object-call options.
- Add an options validator at the boundary of any abstraction layer.
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
- Invalid argument for parameter enumValues: Enum values are n
- Invalid argument for parameter schema: Schema is required fo
- Invalid argument for parameter enumValues: Enum values are n
- 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/3e124b9f930aaf16.
Report an issue: GitHub.