Skip to content

generateObject Schema is not working properly at all with Gemini #7322

@jfangzr

Description

@jfangzr

Description

I used Vercel's SDK example:

import { google } from '@ai-sdk/google';
import { NextRequest, NextResponse } from 'next/server';
import { generateObject } from "ai";
import { z } from "zod";

// Initialize the Gemini model
const model = google('gemini-2.5-pro');

export async function POST(request: NextRequest) {
    const { object } = await generateObject({
      model: model,
      schema: z.object({
        recipe: z.object({
          name: z.string(),
          ingredients: z.array(z.string()),
          steps: z.array(z.string()),
        }),
      }),
      prompt: 'Generate a lasagna recipe.',
    });

    console.log(JSON.stringify(object, null, 2));

}

And i was using Google models such as Gemini-2.5-pro. It seems like the generateObject is not performing type validation properly at all.

AI SDK Version

ai 4.3.19

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy