{"record":{"id":"edc4f103e92a6bab","repo":"vercel/ai","slug":"invalid-argument-for-parameter-schema-schema-is-r","errorCode":null,"errorMessage":"Invalid argument for parameter schema: Schema is required for object output.","messagePattern":"Invalid argument for parameter schema: Schema is required for object output\\.","errorType":"validation","errorClass":"InvalidArgumentError","httpStatus":null,"severity":"error","filePath":"packages/ai/src/generate-object/validate-object-generation-input.ts","lineNumber":67,"sourceCode":"      throw new InvalidArgumentError({\n        parameter: 'schemaName',\n        value: schemaName,\n        message: 'Schema name is not supported for no-schema output.',\n      });\n    }\n\n    if (enumValues != null) {\n      throw new InvalidArgumentError({\n        parameter: 'enumValues',\n        value: enumValues,\n        message: 'Enum values are not supported for no-schema output.',\n      });\n    }\n  }\n\n  if (output === 'object') {\n    if (schema == null) {\n      throw new InvalidArgumentError({\n        parameter: 'schema',\n        value: schema,\n        message: 'Schema is required for object output.',\n      });\n    }\n\n    if (enumValues != null) {\n      throw new InvalidArgumentError({\n        parameter: 'enumValues',\n        value: enumValues,\n        message: 'Enum values are not supported for object output.',\n      });\n    }\n  }\n\n  if (output === 'array') {\n    if (schema == null) {\n      throw new InvalidArgumentError({","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/ai/src/generate-object/validate-object-generation-input.ts#L49-L85","documentation":"output: 'object' (the default for generateObject/streamObject) requires a schema describing the structure the model must produce. Without it the library cannot build the structured-output request, so validateObjectGenerationInput throws InvalidArgumentError for the missing schema parameter.","triggerScenarios":"Calling generateObject({ model, prompt }) with no schema and no output option (defaults to 'object'), or explicitly output: 'object' with schema undefined/null, in generateObject or streamObject.","commonSituations":"Building options dynamically and the schema variable ends up undefined; deleting the schema line while keeping structured output; TypeScript types bypassed via `as any` or plain JS usage; passing schema under a wrong property name.","solutions":["Add a schema (e.g. z.object({...}) wrapped or passed directly) to the generateObject/streamObject call.","If no structure is needed, switch to output: 'no-schema' (and omit schema) or use generateText/streamText.","Verify the schema variable is actually defined and not undefined at the call site."],"exampleFix":"// before\ngenerateObject({ model, prompt });\n// after\ngenerateObject({ model, schema: z.object({ name: z.string() }), prompt });","handlingStrategy":"validation","validationCode":"if ((opts.output ?? 'object') === 'object' && opts.schema == null) {\n  throw new Error(\"schema is required when output is 'object'\");\n}","typeGuard":"function hasValidSchema(opts) {\n  return opts.schema != null && typeof opts.schema === 'object';\n}","tryCatchPattern":"try {\n  return await generateObject(opts);\n} catch (error) {\n  if (InvalidArgumentError.isInstance(error) && error.parameter === 'schema') {\n    throw new Error('generateObject requires a schema for object output');\n  }\n  throw error;\n}","preventionTips":["Always pass a schema (e.g. z.object) in plain-JS or dynamically-built calls.","Remember output defaults to 'object' in generateObject/streamObject.","Check for undefined schema variables when options are assembled conditionally."],"tags":["invalid-argument","missing-schema","object-output","input-validation"],"backgroundTag":"missing-required-argument","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}