vercel/ai · error · InvalidArgumentError

Invalid argument for parameter schema: Schema is required fo

Error message

Invalid argument for parameter schema: Schema is required for object output.

What it means

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.

Source

Thrown at packages/ai/src/generate-object/validate-object-generation-input.ts:67

      throw new InvalidArgumentError({
        parameter: 'schemaName',
        value: schemaName,
        message: 'Schema name is not supported for no-schema output.',
      });
    }

    if (enumValues != null) {
      throw new InvalidArgumentError({
        parameter: 'enumValues',
        value: enumValues,
        message: 'Enum values are not supported for no-schema output.',
      });
    }
  }

  if (output === 'object') {
    if (schema == null) {
      throw new InvalidArgumentError({
        parameter: 'schema',
        value: schema,
        message: 'Schema is required for object output.',
      });
    }

    if (enumValues != null) {
      throw new InvalidArgumentError({
        parameter: 'enumValues',
        value: enumValues,
        message: 'Enum values are not supported for object output.',
      });
    }
  }

  if (output === 'array') {
    if (schema == null) {
      throw new InvalidArgumentError({

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Add a schema (e.g. z.object({...}) wrapped or passed directly) to the generateObject/streamObject call.
  2. If no structure is needed, switch to output: 'no-schema' (and omit schema) or use generateText/streamText.
  3. Verify the schema variable is actually defined and not undefined at the call site.

Example fix

// before
generateObject({ model, prompt });
// after
generateObject({ model, schema: z.object({ name: z.string() }), prompt });
Defensive patterns

Strategy: validation

Validate before calling

if ((opts.output ?? 'object') === 'object' && opts.schema == null) {
  throw new Error("schema is required when output is 'object'");
}

Type guard

function hasValidSchema(opts) {
  return opts.schema != null && typeof opts.schema === 'object';
}

Try / catch

try {
  return await generateObject(opts);
} catch (error) {
  if (InvalidArgumentError.isInstance(error) && error.parameter === 'schema') {
    throw new Error('generateObject requires a schema for object output');
  }
  throw error;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30). Data as JSON: /api/errors/edc4f103e92a6bab. Report an issue: GitHub.