{"record":{"id":"b71320b1de42d6b8","repo":"vercel/ai","slug":"invalid-argument-for-parameter-enumvalues-enum-va-b71320","errorCode":null,"errorMessage":"Invalid argument for parameter enumValues: Enum values are required for enum output.","messagePattern":"Invalid argument for parameter enumValues: Enum values are required for enum output\\.","errorType":"validation","errorClass":"InvalidArgumentError","httpStatus":null,"severity":"error","filePath":"packages/ai/src/generate-object/validate-object-generation-input.ts","lineNumber":127,"sourceCode":"\n    if (schemaDescription != null) {\n      throw new InvalidArgumentError({\n        parameter: 'schemaDescription',\n        value: schemaDescription,\n        message: 'Schema description is not supported for enum output.',\n      });\n    }\n\n    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":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/ai/src/generate-object/validate-object-generation-input.ts#L109-L145","documentation":"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.","triggerScenarios":"Calling generateObject({ output: 'enum' }) or streamObject({ output: 'enum' }) without an `enum` property, or passing an explicitly undefined/null enum.","commonSituations":"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.","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"],"exampleFix":"// before\nawait generateObject({ model, output: 'enum' });\n// after\nawait generateObject({ model, output: 'enum', enum: ['small','medium','large'] });","handlingStrategy":"validation","validationCode":"if (output === 'enum' && (!Array.isArray(enumValues) || enumValues.length === 0)) {\n  throw new Error('enum output requires a non-empty enum array');\n}","typeGuard":"function hasEnumValues(args: { output?: string; enum?: unknown[] }): args is { output: 'enum'; enum: string[] } {\n  return args.output !== 'enum' || Array.isArray(args.enum) && args.enum.length > 0;\n}","tryCatchPattern":"try {\n  return await generateObject(args);\n} catch (e) {\n  if (InvalidArgumentError.isInstance(e) && e.parameter === 'enumValues') {\n    throw new Error('Provide `enum: string[]` when using output: enum');\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["validation","invalid-argument","enum-output","missing-parameter"],"backgroundTag":"missing-required-argument","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}