{"record":{"id":"27cadf89c1d9fbbe","repo":"vercel/ai","slug":"invalid-argument-for-parameter-schema-element-sch","errorCode":null,"errorMessage":"Invalid argument for parameter schema: Element schema is required for array output.","messagePattern":"Invalid argument for parameter schema: Element schema is required for array output\\.","errorType":"validation","errorClass":"InvalidArgumentError","httpStatus":null,"severity":"error","filePath":"packages/ai/src/generate-object/validate-object-generation-input.ts","lineNumber":85,"sourceCode":"      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({\n        parameter: 'schema',\n        value: schema,\n        message: 'Element schema is required for array 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 array output.',\n      });\n    }\n  }\n\n  if (output === 'enum') {\n    if (schema != null) {\n      throw new InvalidArgumentError({","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/ai/src/generate-object/validate-object-generation-input.ts#L67-L103","documentation":"With output: 'array', generateObject/streamObject generate an array of elements, and a schema describing the ELEMENT type is required. The library throws InvalidArgumentError when schema is missing because it cannot construct the array-of-schema request.","triggerScenarios":"Calling generateObject({ model, output: 'array', prompt }) or streamObject with output: 'array' but schema undefined/null; the schema must describe the element, not the array itself.","commonSituations":"Forgetting to switch the schema when converting a single-object call to array output; dynamically built options where the schema lookup failed; plain JS callers without type checking.","solutions":["Provide a schema for the array element type, e.g. schema: z.object({ name: z.string() }) with output: 'array'.","Do not pass an array schema (z.array(...)); the library wraps the element schema itself.","If a structured array is not what you want, change output mode accordingly."],"exampleFix":"// before\ngenerateObject({ model, output: 'array', prompt });\n// after\ngenerateObject({ model, output: 'array', schema: z.object({ name: z.string() }), prompt });","handlingStrategy":"validation","validationCode":"if (opts.output === 'array' && opts.schema == null) {\n  throw new Error(\"an element schema is required when output is 'array'\");\n}","typeGuard":"function hasElementSchema(opts) {\n  return opts.output !== 'array' || opts.schema != null;\n}","tryCatchPattern":"try {\n  return await generateObject(opts);\n} catch (error) {\n  if (InvalidArgumentError.isInstance(error) && error.parameter === 'schema' && opts.output === 'array') {\n    throw new Error('array output needs an element schema');\n  }\n  throw error;\n}","preventionTips":["With output: 'array', pass the element schema, not z.array(...).","Update schemas when converting single-object calls to array output.","Add unit tests that call validate-style checks for each output mode."],"tags":["invalid-argument","missing-schema","array-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"}