{"record":{"id":"2b146f8deeffffcf","repo":"vercel/ai","slug":"invalid-argument-for-parameter-schemaname-schema-2b146f","errorCode":null,"errorMessage":"Invalid argument for parameter schemaName: Schema name is not supported for enum output.","messagePattern":"Invalid argument for parameter schemaName: Schema name is not supported for enum output\\.","errorType":"validation","errorClass":"InvalidArgumentError","httpStatus":null,"severity":"error","filePath":"packages/ai/src/generate-object/validate-object-generation-input.ts","lineNumber":119,"sourceCode":"  if (output === 'enum') {\n    if (schema != null) {\n      throw new InvalidArgumentError({\n        parameter: 'schema',\n        value: schema,\n        message: 'Schema is not supported for enum output.',\n      });\n    }\n\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',","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/ai/src/generate-object/validate-object-generation-input.ts#L101-L137","documentation":"generateObject/streamObject in 'enum' output mode takes `enum` values instead of a named JSON schema, so passing a `schemaName` is invalid. validateObjectGenerationInput proactively rejects the combination with InvalidArgumentError before any model call. This prevents users from assuming a schema name is transmitted when it would be ignored or rejected.","triggerScenarios":"Calling generateObject({ output: 'enum', enum: [...], schemaName: 'MyEnum' }) or the same with streamObject. Any non-null schemaName combined with output:'enum' triggers it.","commonSituations":"Refactoring code from a 'object'/'array' output mode (where schemaName is valid) to 'enum' mode and leaving schemaName in place; copy-pasted options objects shared between calls; older code predating the enum output mode.","solutions":["Remove the schemaName property from the generateObject/streamObject call when using output: 'enum'","Keep schemaName only for output: 'object' or 'array' calls where a JSON schema is provided","Conditionally build the options object so schema-dependent fields are only set for schema-based modes"],"exampleFix":"// before\nconst { object } = await generateObject({\n  model, output: 'enum', enum: ['A','B'], schemaName: 'Choice'\n});\n// after\nconst { object } = await generateObject({\n  model, output: 'enum', enum: ['A','B']\n});","handlingStrategy":"validation","validationCode":"if (output === 'enum' && 'schemaName' in args && args.schemaName != null) {\n  throw new Error('schemaName is not allowed with output: enum');\n}","typeGuard":"function isEnumArgs(args: { output?: string; schemaName?: string }): boolean {\n  return args.output !== 'enum' || args.schemaName == null;\n}","tryCatchPattern":"try {\n  await generateObject(args);\n} catch (e) {\n  if (InvalidArgumentError.isInstance(e) && e.parameter === 'schemaName') {\n    delete args.schemaName;\n    return generateObject(args);\n  }\n  throw e;\n}","preventionTips":["Never mix schema/schemaName/schemaDescription with output: 'enum'","Build options objects per output mode instead of sharing one","Rely on TypeScript discriminated unions for the output options"],"tags":["validation","invalid-argument","enum-output"],"backgroundTag":"invalid-function-argument","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}