Developers using Zod schemas with the OpenAI Node SDK or Vercel AI SDK may encounter issues where custom validation rules, specifically those defined using `.refine()`, are not passed to the language model. This occurs because the `z.toJSONSchema()` function, used by these SDKs, converts Zod schemas to JSON Schema format but omits `.refine()` checks, treating them as custom rules not supported by standard JSON Schema. Consequently, the model only receives the basic schema structure, and any validation logic defined in `.refine()` is only applied after the model's response is received, not during generation. AI
IMPACT Developers using Zod with AI SDKs need to be aware that custom validation rules are not passed to models, potentially leading to unexpected behavior.
RANK_REASON This item discusses a technical limitation in how specific SDKs handle Zod schemas, impacting developer workflows.
- AI in TypeScript
- AI That Answers
- Claude Code
- Hermes IDE
- JSON Schema
- OpenAI Node SDK
- Vercel AI SDK
- Zod
- z.toJSONSchema
AI-generated summary · Google Gemini · from 1 sources. How we write summaries →