Class ObjectGenerationError

Thrown when structured output generation fails after exhausting all retries.

Captures both the raw LLM output and the Zod validation issues so callers can inspect what went wrong and surface useful diagnostics.

Example

try {
await generateObject({ schema: mySchema, prompt: '...' });
} catch (err) {
if (err instanceof ObjectGenerationError) {
console.error('Raw text:', err.rawText);
console.error('Validation:', err.validationErrors);
}
}

Hierarchy

  • Error
    • ObjectGenerationError

Constructors

Properties

Constructors

  • Parameters

    • message: string

      Human-readable summary of the failure.

    • rawText: string

      The last raw text the LLM produced before we gave up.

    • Optional validationErrors: ZodError<unknown>

      Zod validation issues from the final attempt.

    Returns ObjectGenerationError

Properties

name: "ObjectGenerationError" = 'ObjectGenerationError'

The name of this error class, useful for instanceof checks across realms.

rawText: string

The raw text returned by the LLM on the final attempt.

validationErrors?: ZodError<unknown>

Zod validation error details from the last parse attempt, if available.