vercel/ai · error

Unsupported output: ${_exhaustiveCheck}

Error message

Unsupported output: ${_exhaustiveCheck}

What it means

`getOutputStrategy` switches on the requested output mode and throws this Error when it encounters a value outside `'object' | 'array' | 'enum' | 'no-schema'`. At runtime this is unreachable through the public API because `validateObjectGenerationInput` rejects bad values first; seeing it means an invalid output value bypassed validation (internal misuse, casts, or version mismatch).

Source

Thrown at packages/ai/src/generate-object/output-strategy.ts:423

  schema,
  enumValues,
}: {
  output: 'object' | 'array' | 'enum' | 'no-schema';
  schema?: FlexibleSchema<SCHEMA>;
  enumValues?: Array<SCHEMA>;
}): OutputStrategy<any, any, any> {
  switch (output) {
    case 'object':
      return objectOutputStrategy(asSchema(schema!));
    case 'array':
      return arrayOutputStrategy(asSchema(schema!));
    case 'enum':
      return enumOutputStrategy(enumValues! as Array<string>);
    case 'no-schema':
      return noSchemaOutputStrategy;
    default: {
      const _exhaustiveCheck: never = output;
      throw new Error(`Unsupported output: ${_exhaustiveCheck}`);
    }
  }
}

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Use one of the literal values: `'object'`, `'array'`, `'enum'`, or `'no-schema'` for `output`.
  2. Remove `as any` casts on the options object so TypeScript validates the `output` literal.
  3. If the value comes from config, validate/normalize it before passing it to generateObject/streamObject.

Example fix

// before
generateObject({ model, schema, output: 'objects' as any });

// after
generateObject({ model, schema, output: 'object' });
Defensive patterns

Strategy: validation

Validate before calling

const OUTPUT_MODES = ['object', 'array', 'enum', 'no-schema'] as const;
type OutputMode = typeof OUTPUT_MODES[number];
function assertOutputMode(v: unknown): asserts v is OutputMode {
  if (!OUTPUT_MODES.includes(v as OutputMode)) throw new Error(`Invalid output mode: ${v}`);
}

Type guard

function isOutputMode(v: unknown): v is 'object' | 'array' | 'enum' | 'no-schema' {
  return v === 'object' || v === 'array' || v === 'enum' || v === 'no-schema';
}

Try / catch

try {
  const result = await generateObject({ model, schema, output: userOutput as any });
} catch (e) {
  if (e instanceof Error && e.message.startsWith('Unsupported output')) {
    // retry with default object mode
    return generateObject({ model, schema });
  }
  throw e;
}

Prevention

When it happens

Trigger: Passing an arbitrary string (e.g. `'objects'`, `'list'`, `''`) as `output` to `generateObject`/`streamObject` through an `as any` cast, from untyped JS, or via an internal caller that skips `validateObjectGenerationInput`.

Common situations: Typos in dynamically constructed options objects; JavaScript callers with no type checking; wrapper libraries forwarding user config straight into `generateObject`.

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/dbc4f1d65c6991f4. Report an issue: GitHub.