跳到正文
返回论文列表
cs.SE提交于 已译

结构化输出为何失败?跨九种 LLM 的提示词约束 Pydantic Schema 实证研究

Why Does Structured Output Fail? An Empirical Study of Prompt-Enforced Pydantic Schemas Across Nine LLMs

Amit Verma

中文摘要

托管语言模型的结构化输出流水线通常在提示词中指定 Pydantic schema,验证响应,并在验证失败时重试。尽管原生结构化输出模式提供了替代方案,应用侧验证仍是实施自定义约束的重要手段。然而,单一有效率往往掩盖失败原因及可行干预。研究建立细粒度的 schema 一致性失败分类体系,并提出确定性分类器,依据模型响应与 Pydantic 验证错误判定失败类别。该框架应用于九种 OpenAI 和 Anthropic 模型/API 配置下的 3,997 次生成,使用 HotpotQA 与 FinanceBench 问题。结果表明,相近有效率可能对应不同失败模式,主要失败类别随 schema 约束和任务而变化。Markdown 围栏 JSON 最常见:在 681 次围栏失败中,去除围栏后仅 48.0% 通过验证,其余还隐藏着违规,主要是字段长度违规。探索性提示词消融显示,抑制围栏的变体似乎使失败转向长度违规,但这种转变源于暴露原有违规,说明聚合有效率会掩盖失败构成变化。研究进一步提出四项关于验证器、schema、重试和评估设计的工程实践,其中三项得到数据支持,重试反馈一项仅提出但未测试,并公开分类器、补全结果与标注。

关键要点

  1. 01单一有效率会掩盖不同 schema 失败模式及干预效果
  2. 02基于响应与 Pydantic 错误构建确定性细粒度失败分类器
  3. 03在九种 OpenAI 和 Anthropic 配置下完成 3,997 次生成
  4. 04681 次 Markdown 围栏失败中仅 48.0% 在移除围栏后通过
  5. 05抑制围栏主要暴露既有字段长度违规,而非真正消除失败

解读

尚无解读。

原始英文摘要

arXiv:2610.33949v1 Announce Type: cross Abstract: Pipelines that require structured outputs from hosted language models often specify a Pydantic schema in the prompt, validate the response, and retry when validation fails. Although native structured-output modes provide an alternative, application-side validation remains important for enforcing custom constraints. Yet pipeline reliability is often summarized by a single validity rate, which obscures why outputs fail and which interventions may help. We introduce a fine-grained taxonomy of schema-conformance failures and a deterministic classifier that assigns failure categories from model responses and Pydantic validation errors. We apply this framework to 3,997 generation attempts across nine OpenAI and Anthropic model/API configurations, using questions from HotpotQA and FinanceBench. Our results show that similar validity rates can mask different failure patterns, and that dominant failure categories vary with schema constraints and task. Markdown-fenced JSON is the most common failure: among 681 fenced failures, only 48.0% pass validation after fence removal, while the remainder conceal additional violations, predominantly field-length violations. In an exploratory prompt ablation, variants that suppress fences appear to shift failures toward length violations, but the shift is consistent with exposing violations that were already present, illustrating how aggregate validity rates can obscure changes in failure composition. We derive four engineering practices for validator, schema, retry and evaluation design, three supported by our data and one, on retry feedback, proposed but not tested, and release the classifier, completions, and annotations.

同方向论文 · cs.SE

查看全部 →

反向发现 · 这篇论文相关的工具与提示词

去交叉发现 →

关联提示词 · 3

编程github.com/f/awesome-chatgpt-prompts·外部收录·

VFD Fault Code Explainer

I want you to act as an experienced drives technician. A variable frequency drive tripped. Drive: ${Drive make, model and firmware if known}. Fault code and text on the keypad: ${Fault code and text}. Motor: ${Motor nameplate: kW or HP, vol…

编程github.com/f/awesome-chatgpt-prompts·外部收录·

TCRE Framework - AI Prompt Engineer

I want to create a highly effective AI prompt using the TCRE framework (Task, Context, References, Evaluate/Iterate). My goal is to **${insert_objective}. Step 1: Ask me multiple structured, specific questions—one at a time—to gather all e…

编程github.com/f/awesome-chatgpt-prompts·外部收录·

GPT-5 | EXPERT PROMPT ENGINEER MODE (CONDENSED)

You are an **expert AI & Prompt Engineer** with ~20 years of applied experience deploying LLMs in real systems. You reason as a practitioner, not an explainer. ### OPERATING CONTEXT * Fluent in LLM behavior, prompt sensitivity, evaluation…