vercel/ai · error · InvalidArgumentError
Invalid argument for parameter enumValues: Enum values must
Error message
Invalid argument for parameter enumValues: Enum values must be strings.
What it means
Enum output values are serialized into a string enum schema for the model, so every entry must be a string. validateObjectGenerationInput iterates the enum array and throws InvalidArgumentError on the first non-string element. This is a deliberate eager check rather than letting the provider fail later.
Source
Thrown at packages/ai/src/generate-object/validate-object-generation-input.ts:136
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
- Convert entries to strings, e.g. enum: Object.values(MyEnum).map(String)
- Use `as const` string literal arrays instead of TS numeric enums
- Validate array elements are strings before the call (see validationCode)
Example fix
// before
enum Size { S, M, L }
await generateObject({ model, output: 'enum', enum: Object.values(Size) });
// after
const SIZES = ['S','M','L'] as const;
await generateObject({ model, output: 'enum', enum: SIZES }); Defensive patterns
Strategy: validation
Validate before calling
if (output === 'enum' && enumValues?.some(v => typeof v !== 'string')) {
throw new Error('All enum values must be strings');
} Type guard
function isStringEnum(values: unknown): values is string[] {
return Array.isArray(values) && values.every(v => typeof v === 'string');
} Try / catch
try {
return await generateObject(args);
} catch (e) {
if (InvalidArgumentError.isInstance(e) && e.parameter === 'enumValues') {
args.enum = (args.enum ?? []).map(String);
return generateObject(args);
}
throw e;
} Prevention
- Use `as const` string literal arrays for enums
- Avoid passing TS numeric enums directly; convert with Object.values(...).map(String)
- Validate element types before calling
When it happens
Trigger: generateObject({ output: 'enum', enum: [1, 2, 3] }) or any array containing numbers, booleans, objects, or null mixed with strings, passed to generateObject/streamObject.
Common situations: Numeric TypeScript enums (`enum Color {Red}` yields numeric values) passed directly; enum arrays derived from Object.values() of non-string maps; untyped JSON config used as the enum source.
Related errors
- Invalid argument for parameter schemaName: Schema name is no
- Invalid argument for parameter enumValues: Enum values are r
- 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/779c232cff7df881.
Report an issue: GitHub.