vercel/ai · error · InvalidArgumentError
Invalid argument for parameter enumValues: Enum values are r
Error message
Invalid argument for parameter enumValues: Enum values are required for enum output.
What it means
In 'enum' output mode, the `enum` array is the only way to describe the allowed values, so it is mandatory. validateObjectGenerationInput throws InvalidArgumentError when enum output is requested but enumValues is null or undefined. The library cannot build the response schema without it.
Source
Thrown at packages/ai/src/generate-object/validate-object-generation-input.ts:127
if (schemaDescription != null) {
throw new InvalidArgumentError({
parameter: 'schemaDescription',
value: schemaDescription,
message: 'Schema description is not supported for enum output.',
});
}
if (schemaName != null) {
throw new InvalidArgumentError({
parameter: 'schemaName',
value: schemaName,
message: 'Schema name is not supported for enum output.',
});
}
if (enumValues == null) {
throw new InvalidArgumentError({
parameter: 'enumValues',
value: enumValues,
message: 'Enum values are required for enum output.',
});
}
for (const value of enumValues) {
if (typeof value !== 'string') {
throw new InvalidArgumentError({
parameter: 'enumValues',
value,
message: 'Enum values must be strings.',
});
}
}
}
}
View on GitHub (pinned to 69428b1f8b)
Solutions
- Pass a non-empty `enum: string[]` array when using output: 'enum'
- Ensure the variable holding the enum values is populated before the call
- Fall back to output: 'object' with a schema if values are not known statically
Example fix
// before
await generateObject({ model, output: 'enum' });
// after
await generateObject({ model, output: 'enum', enum: ['small','medium','large'] }); Defensive patterns
Strategy: validation
Validate before calling
if (output === 'enum' && (!Array.isArray(enumValues) || enumValues.length === 0)) {
throw new Error('enum output requires a non-empty enum array');
} Type guard
function hasEnumValues(args: { output?: string; enum?: unknown[] }): args is { output: 'enum'; enum: string[] } {
return args.output !== 'enum' || Array.isArray(args.enum) && args.enum.length > 0;
} Try / catch
try {
return await generateObject(args);
} catch (e) {
if (InvalidArgumentError.isInstance(e) && e.parameter === 'enumValues') {
throw new Error('Provide `enum: string[]` when using output: enum');
}
throw e;
} Prevention
- Always supply `enum` when output is 'enum'
- Check the enum source array is loaded before the call
- Type the options with discriminated unions so TS enforces the enum field
When it happens
Trigger: Calling generateObject({ output: 'enum' }) or streamObject({ output: 'enum' }) without an `enum` property, or passing an explicitly undefined/null enum.
Common situations: Dynamically constructed options where the enum array fails to load (empty config, failed fetch) and arrives as undefined; TypeScript types bypassed via `as any`; migration from schema-based output where `enum` was forgotten.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Invalid argument for parameter schemaName: Schema name is no
- Invalid argument for parameter enumValues: Enum values must
- Invalid argument for parameter output: Invalid output type.
- 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/b71320b1de42d6b8.
Report an issue: GitHub.