PulseAugur
中
实时 21:45:28
English(EN) Your Zod .refine() Never Reaches the Model: What Survives the Trip to JSON Schema

Zod .refine() 规则在通过 OpenAI/Vercel SDK 传递给 LLM 之前被丢弃

使用 Zod schema 和 OpenAI Node SDK 或 Vercel AI SDK 的开发者可能会遇到问题,即自定义验证规则(特别是使用 `.refine()` 定义的规则)未传递给语言模型。这是因为这些 SDK 使用的 `z.toJSONSchema()` 函数会将 Zod schema 转换为 JSON Schema 格式,但会省略 `.refine()` 检查,将其视为标准 JSON Schema 不支持的自定义规则。因此,模型只接收到基本的 schema 结构,而 `.refine()` 中定义的任何验证逻辑仅在模型响应接收后应用,而不是在生成过程中。 AI

影响 使用 Zod 和 AI SDK 的开发者需要注意,自定义验证规则不会传递给模型,这可能会导致意外行为。

排序理由 该条目讨论了特定 SDK 如何处理 Zod schema 的技术限制,影响了开发者的工作流程。

在 dev.to — LLM tag 阅读 →

AI 生成摘要 · Google Gemini · 来自 1 个来源。 我们如何撰写摘要 →

Zod .refine() 规则在通过 OpenAI/Vercel SDK 传递给 LLM 之前被丢弃

本文如何被排名

Signal score
23 / 100
Composite score across the factors below. Higher = stronger signal that this story matters right now.
Newsworthiness bucket
Tool
该条目讨论了特定 SDK 如何处理 Zod schema 的技术限制,影响了开发者的工作流程。
Source corroboration
Single-source cluster
Only one publisher covered this so far. Single-source stories can still rank when the publisher is high-authority, but they lack cross-source corroboration.
Topics
product, infra
Editorial topic classification. Feeds into how the story surfaces on /topic/<slug> hub pages and into the per-entity coverage mix.
AI-industry relevance
High
Clearly on-topic for AI-industry coverage.
Story freshness
Breaking (< 6h)
Fresh story with cross-source coverage still developing. Ranking may shift as more sources report.

完整方法见我们的编辑标准。

报道来源 [1]

  1. dev.to — LLM tag TIER_1 English(EN) · Gabriel Anhaia ·

    Your Zod .refine() Never Reaches the Model: What Survives the Trip to JSON Schema

    <ul> <li> <strong>Book:</strong> <a href="https://www.amazon.com/dp/B0HBN9XMCY" rel="noopener noreferrer">AI That Answers</a> </li> <li> <strong>The series:</strong> <em>AI in TypeScript</em> — 5 books, from your first LLM call to agents in production — <a href="https://xgabriel.…