论文多源确认

9个LLM结构化输出失败实证研究:Markdown围栏是最大坑

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

精选理由

如果你的 Agent 管线老被 Pydantic 校验卡住,这篇拿 9 个模型、近 4000 次调用跑出来的失败分析值得看看。

研究覆盖 9 个 OpenAI 和 Anthropic 模型/API 配置,共 3,997 次生成尝试,任务来自 HotpotQA 和 FinanceBench。作者提出细粒度的 schema 失败分类法和确定性分类器,发现相同的有效率可能掩盖不同的失败模式。Markdown 围栏包裹的 JSON 是最常见失败:681 个围栏失败中仅 48.0% 在去围栏后能通过校验,其余多隐藏字段长度违规。研究总结了 4 条工程实践,涉及校验器、schema、重试和评估设计,并开源了分类器、补全记录和标注数据。

原文 · arXiv cs.LG

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

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.