Documentation issue: Structured Outputs example uses outdated GenAI SDK and Zod APIs

Documentation issue: Structured Outputs example uses outdated GenAI SDK and Zod APIs

Hi everyone,

I found a couple of issues in the JavaScript example on the Structured Outputs documentation page:

Execution Environment

  • OS: Ubuntu 24.04.1 LTS
  • Node.js: v24.14.1
  • @google/genai: v2.7.0

Overview

The current Recipe Extractor example appears to use APIs that are no longer compatible with the latest versions of the @google/genai SDK and zod.

Minimal Reproduction

The documentation currently shows code similar to:

import { GoogleGenAI } from "@google/genai";
import { z } from "zod";
import { zodToJsonSchema } from "zod-to-json-schema";

// (Prompt settings)

const response = await ai.models.generateContent({
  model: "gemini-3.5-flash",
  contents: prompt,
  config: {
    responseFormat: {
      text: {
        mimeType: "application/json",
        schema: zodToJsonSchema(recipeSchema),
      },
    },
  },
});

const recipe = recipeSchema.parse(JSON.parse(response.text));
console.log(recipe);

When running this example with current dependencies, I get:

ReferenceError: zodToJsonSchema is not defined

This appears because zodToJsonSchema is no longer the recommended approach, as Zod now provides native JSON Schema generation.

However, this is only a secondary issue.

Main Issue

The larger problem is that the config structure shown in the documentation does not appear to match the current @google/genai SDK API.

Based on the current GenerateContentConfig type definitions, the example should be closer to:

import { GoogleGenAI } from "@google/genai";
import { z } from "zod";

// (Prompt settings)

const response = await ai.models.generateContent({
  model: "gemini-3.5-flash",
  contents: prompt,
  config: {
    responseMimeType: "application/json",
    responseJsonSchema: z.toJSONSchema(recipeSchema),
  },
});

const recipe = recipeSchema.parse(JSON.parse(response.text));
console.log(recipe);

Suggested Documentation Updates

  1. Replace zodToJsonSchema(...) with Zod’s native JSON Schema support:

    z.toJSONSchema(...)
    
  2. Update the config section to use:

    responseMimeType;
    responseJsonSchema;
    

    instead of:

    responseFormat: {
      text: {
        (mimeType, schema);
      }
    }
    

Could someone confirm whether the documentation is outdated, or if I am missing a compatibility requirement for an older SDK version?

As I could only add two citation URLs in the main topic, I added the references in the reply section.

References