Manuscript Offprint

arXiv:2610.33949

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

Amit Verma

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.

Keywords: Large language models, Structured output, Schema validation, Pydantic, Failure taxonomy, Empirical study

1 Introduction

A practitioner building an entity-extraction pipeline needs canonical identifiers and writes an unremarkable constraint: ~[a-z][a-z0-9_]{2,30}$, a 3-31-character lowercase identifier beginning with a letter and containing letters, digits, or underscores. Asked for the identifier of an entity whose name is a street address, a GPT-5.6 model in our study returns 888_7th_avenue. The rendering is faithful to the name and fails the anchor ~[a-z]. A conforming identifier exists (building_888_7th_avenue), but the task does not specify which conforming normalisation to use.

Under the evaluation practice common for structured output, this failure is indistinguishable from a model that emitted no JSON, a model that returned the schema definition instead of an instance, and a model that produced a conformant object inside a markdown fence. All four increment the same counter, although they have different causes and call for different remedies.

Constrained decoding and vendor structured-output modes prevent many syntactic failures, but they do not remove the need to validate and repair. Support for JSON Schema features varies between implementations (Geng et al. 2025), and Pydantic model validators, such as cross-field agreement and membership checks, have no JSON Schema counterpart and cannot be enforced at decoding time. A pipeline that must run across vendors, model generations, or endpoints therefore keeps the schema in the prompt and validates afterwards, and its validate-and-retry loop stays in place even where decoding is constrained. How that loop fails is an engineering question, and a single validity rate cannot answer it.

We treat failure diagnosis as part of pipeline design. A validation log records whether an output passed and the errors Pydantic raised for it. That record does not separate a formatting failure from a schema violation it may hide, does not say whether a pattern violation came from the character class or from a length ceiling written into the pattern, and does not say whether a change to the prompt or schema removed a failure or exposed one that was already present. Each distinction changes what an engineer should fix: the parser, the schema, the retry feedback, or the way the pipeline is evaluated.

We study the prompt-and-validate paradigm: the schema is stated in the prompt, the completion is validated with Pydantic, and failures are retried with the validation error appended. We do not evaluate constrained decoding (Section 2). We ask three questions.

RQ1 Do configurations with similar failure rates fail in the same way?

RQ2 Does a failure profile stay stable when the schema's constraints or the task domain change?

RQ3 What do formatting failures conceal, and how does that change the reading of repairs and prompt ablations?

We define a taxonomy of conformance failures, assign each failing attempt a category with a deterministic classifier, and apply it to 3,997 attempts across 18 configurations of nine models from two vendors, one baseline schema and two targeted variants, and two task domains. A configuration is a model endpoint called through its vendor's

API with the request parameters in Appendix A, so comparisons are between these configurations, not between model capabilities in general.

The answer to all three questions is that the validity rate hides what an engineer needs. Configurations with overlapping failure rates fall into four profiles defined by their dominant category (RQ1). Raising length caps changes which category dominates for the same model, and revalidating the same stored outputs against the relaxed schema shows that the caps alone account for the removed length violations; the same model also shows different profiles on the two domains (RQ2). Only 48.0% of fenced failures validate once the fence is removed. The rest conceal a length or pattern violation that the returned parse error never mentions, and ignoring this makes a prompt ablation appear to move failures from one mode to another (RQ3).

References (21)