vercel/ai · error · InvalidArgumentError

Invalid argument for parameter output: Invalid output type.

Error message

Invalid argument for parameter output: Invalid output type.

What it means

`validateObjectGenerationInput` throws this InvalidArgumentError when the `output` parameter is provided but is not one of the allowed literals `'object' | 'array' | 'enum' | 'no-schema'`. It runs at the entry of `generateObject` and `streamObject`, failing fast before any model call, and names the offending parameter and value.

Source

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

  schema,
  schemaName,
  schemaDescription,
  enumValues,
}: {
  output?: 'object' | 'array' | 'enum' | 'no-schema';
  schema?: FlexibleSchema<unknown>;
  schemaName?: string;
  schemaDescription?: string;
  enumValues?: Array<unknown>;
}) {
  if (
    output != null &&
    output !== 'object' &&
    output !== 'array' &&
    output !== 'enum' &&
    output !== 'no-schema'
  ) {
    throw new InvalidArgumentError({
      parameter: 'output',
      value: output,
      message: 'Invalid output type.',
    });
  }

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

    if (schemaDescription != null) {
      throw new InvalidArgumentError({
        parameter: 'schemaDescription',

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Set `output` to exactly one of `'object'`, `'array'`, `'enum'`, or `'no-schema'` (or omit it for the default object mode).
  2. Remove `as any` casts so TypeScript's literal union catches bad values at compile time.
  3. If `output` comes from external config, validate it against the union before calling generateObject/streamObject.

Example fix

// before
streamObject({ model, schema, output: (config.mode as any) }); // 'list'

// after
const OUTPUT_MODES = ['object', 'array', 'enum', 'no-schema'] as const;
streamObject({ model, schema, output: OUTPUT_MODES.includes(config.mode) ? config.mode : 'object' });
Defensive patterns

Strategy: validation

Validate before calling

const OUTPUT_MODES = ['object', 'array', 'enum', 'no-schema'] as const;
function isValidOutputMode(v: unknown): v is typeof OUTPUT_MODES[number] {
  return typeof v === 'string' && (OUTPUT_MODES as readonly string[]).includes(v);
}
// before calling: if (config.output !== undefined && !isValidOutputMode(config.output)) throw ...

Type guard

function isOutputMode(v: unknown): v is 'object' | 'array' | 'enum' | 'no-schema' {
  return ['object','array','enum','no-schema'].includes(v as string);
}

Try / catch

try {
  return await generateObject({ model, schema, output });
} catch (e) {
  if (InvalidArgumentError.isInstance(e) && e.parameter === 'output') {
    return generateObject({ model, schema }); // default object mode
  }
  throw e;
}

Prevention

When it happens

Trigger: Passing a misspelled or arbitrary string as `output` (e.g. `'objects'`, `'Array'`, `'json'`), a non-string value, or reading `output` from untyped config/env into the options object — especially via `as any` or plain JavaScript.

Common situations: Typos in dynamic configuration; wrapper libraries forwarding user input; migration from older AI SDK versions where option names/values differed; templated code generators emitting wrong literals.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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