FG
🤖 AI & LLMsOpenAI

zodTextFormat breaks with Zod 4

Fresh5 months ago
Mar 14, 20260 views
Confidence Score80%
80%

Problem

Confirm this is a Node library issue and not an underlying OpenAI API issue - [x] This is an issue with the Node library Describe the bug As per this issue, `zod-to-json` library, which I believe OpenAI SDK uses under the hood, is not compatible with Zod v4. So e.g. this official tutorial won't work. Also the error is not very descriptive, as we only get: [code block] To Reproduce Install latest zod (4.x.x) and openai [code block] Then this snippet will fail. [code block] then rerun the same code with zod 3 and it should work [code block] [code block]JavaScript ``` OS macOS Node version 22.14.0 Library version openai@5.11.0

Error Output

error is not very descriptive, as we only get:

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
High Confidence Fix
77% confidence100% success rate5 verificationsLast verified Mar 14, 2026

Solution: zodTextFormat breaks with Zod 4

Low Risk

For anyone hitting this, you can work around like this: [code block] And then use your own `zodTextForrmat` instead of the broken one. TypeScript inference will work the same way.

77

Trust Score

5 verifications

100% success
  1. 1

    For anyone hitting this, you can work around like this:

    For anyone hitting this, you can work around like this:

    ts
    import { z } from "zod";
    import type { zodTextFormat as openAIBrokenZodTextFormatButWhichHasCorrectTypeScriptTypes } from "openai/helpers/zod";
    
    export const zodTextFormat: typeof openAIBrokenZodTextFormatButWhichHasCorrectTypeScriptTypes = (
      zodSchema,
      name,
    ) => {
      return {
        type: "json_schema",
        schema: z.toJSONSchema(zodSchema),
        name,
      } as ReturnType<typeof openAIBrokenZodTextFormatButWhichHasCorrectTypeScriptTypes> as never;
    };
  2. 2

    And then use your own `zodTextForrmat` instead of the broken one. TypeScript inf

    And then use your own `zodTextForrmat` instead of the broken one. TypeScript inference will work the same way.

Validation

Resolved in openai/openai-node GitHub issue #1602. Community reactions: 9 upvotes.

Verification Summary

Worked: 5
Partial: 1
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

openaigptllmapibug