{"record":{"id":"779c232cff7df881","repo":"vercel/ai","slug":"invalid-argument-for-parameter-enumvalues-enum-va-779c23","errorCode":null,"errorMessage":"Invalid argument for parameter enumValues: Enum values must be strings.","messagePattern":"Invalid argument for parameter enumValues: Enum values must be strings\\.","errorType":"validation","errorClass":"InvalidArgumentError","httpStatus":null,"severity":"error","filePath":"packages/ai/src/generate-object/validate-object-generation-input.ts","lineNumber":136,"sourceCode":"    if (schemaName != null) {\n      throw new InvalidArgumentError({\n        parameter: 'schemaName',\n        value: schemaName,\n        message: 'Schema name is not supported for enum output.',\n      });\n    }\n\n    if (enumValues == null) {\n      throw new InvalidArgumentError({\n        parameter: 'enumValues',\n        value: enumValues,\n        message: 'Enum values are required for enum output.',\n      });\n    }\n\n    for (const value of enumValues) {\n      if (typeof value !== 'string') {\n        throw new InvalidArgumentError({\n          parameter: 'enumValues',\n          value,\n          message: 'Enum values must be strings.',\n        });\n      }\n    }\n  }\n}\n","sourceCodeStart":118,"sourceCodeEnd":145,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/ai/src/generate-object/validate-object-generation-input.ts#L118-L145","documentation":"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.","triggerScenarios":"generateObject({ output: 'enum', enum: [1, 2, 3] }) or any array containing numbers, booleans, objects, or null mixed with strings, passed to generateObject/streamObject.","commonSituations":"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.","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)"],"exampleFix":"// before\nenum Size { S, M, L }\nawait generateObject({ model, output: 'enum', enum: Object.values(Size) });\n// after\nconst SIZES = ['S','M','L'] as const;\nawait generateObject({ model, output: 'enum', enum: SIZES });","handlingStrategy":"validation","validationCode":"if (output === 'enum' && enumValues?.some(v => typeof v !== 'string')) {\n  throw new Error('All enum values must be strings');\n}","typeGuard":"function isStringEnum(values: unknown): values is string[] {\n  return Array.isArray(values) && values.every(v => typeof v === 'string');\n}","tryCatchPattern":"try {\n  return await generateObject(args);\n} catch (e) {\n  if (InvalidArgumentError.isInstance(e) && e.parameter === 'enumValues') {\n    args.enum = (args.enum ?? []).map(String);\n    return generateObject(args);\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["validation","invalid-argument","enum-output","type-error"],"backgroundTag":"invalid-function-argument","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}