Structured Outputs example broken (node.js: triggering Zod version discovered)

I was attempting to convert my app to the Response API with structured outputs today and discovered that the Structured Outputs example is broken:

import OpenAI from 'openai';
import { zodTextFormat } from 'openai/helpers/zod';
import { z } from 'zod';

const openai = new OpenAI();

const CalendarEvent = z.object({
  name: z.string(),
  date: z.string(),
  participants: z.array(z.string()),
});

const response = await openai.responses.parse({
  model: 'gpt-5.0',
  input: [
    { role: 'system', content: 'Extract the event information.' },
    {
      role: 'user',
      content: 'Alice and Bob are going to a science fair on Friday.',
    },
  ],
  text: {
    format: zodTextFormat(CalendarEvent, 'event'),
  },
});

console.log('%O', response.output_parsed);

Response:

error: 400 Invalid schema for response_format 'event': schema must be a JSON Schema of 'type: "object"', got 'type: "string"'.

Also, setting verbosity: ‘low’ returns: error: 400 Unknown parameter: ‘verbosity’.

1 Like

Looks like this was because I upgraded to zod@4 and one of the underlying libraries silently fails (possibly zod-to-json-schema which fails silently with zod@4).

Also, you have to wrap your schema in an object like this:

z.object({
  memory: z.array(
    z.string().describe('Memories extracted from the user message'),
  ),
});

vs. this:

z.array(
  z.string().describe('Memories extracted from the user message'),
);

or you will get BadRequestError: 400 Invalid schema for response_format ‘memories’: schema must be a JSON Schema of ‘type: “object”’, got ‘type: “array”’.

2 Likes

I downgraded to the next version and it worked
"zod": "3.25.76"

1 Like

downgraded to 3.25.76 and now get this funny error. does anyone have structured outputs working at all? seems unlikely that it would be completely broken

Did you get this sorted out?

Hey Luke :waving_hand: , could you share your full zod object if it’s not private?

Yes, that was an issue for about two months. But with openai@^6.7.0 (released 6 hours ago), it works quite well now. Try it out the code you shared with this dependencies;

  "dependencies": {
    "openai": "^6.7.0",
    "zod": "^4.1.12"
  }