Structured Outputs That Don't Work: Five Scenarios Where the Schema Is Present but Guarantees Are Not

Introduction

In 2025 and 2026, the hype around structured outputs from large language models (LLMs) has reached a fever pitch. Tools like OpenAI's Structured Outputs, Anthropic's JSON mode, and various open-source libraries promise to turn free-form AI text into predictable, machine-readable schemas. The promise is seductive: feed a prompt, get back a perfectly formatted JSON object that can be dropped directly into a database, API, or business logic. However, as recent industry analysis reveals, this promise often fails in practice. A detailed article on Habr (published by OTUS) examines five critical situations where structured output schemas exist, yet guarantees of correctness, completeness, or safety are absent. This article summarizes those findings, adding practical context and recommendations for developers and architects who rely on LLM-generated structured data in production.

Why Structured Outputs Are Not a Silver Bullet

Structured outputs work by constraining the LLM's token generation to a predefined grammar, typically JSON Schema. Under the hood, methods like constrained decoding (e.g., using libraries such as Outlines or Guidance) force the model to only produce tokens that fit the schema. In theory, this eliminates syntax errors and ensures the output can be parsed. But as the original article points out, syntactic validity does not equal semantic correctness or reliability. The schema is just a box; what goes inside can still be wrong, harmful, or missing.

The Five Scenarios Where Structured Outputs Fail

The Habr article identifies five distinct failure modes. Below is a summary table, followed by detailed explanations.

Scenario Core Problem Real-World Example Mitigation Strategy
1. Schema hallucination LLM fills fields with plausible but false data A customer support bot generates a fake order ID that matches the schema but doesn't exist Add validation rules that cross-reference with actual databases
2. Ambiguous or underdefined schemas Schema lacks constraints (e.g., min/max length, enum values), so LLM produces garbage A schema for 'age' accepts -5 or 999 because no minimum/maximum is defined Use strict enums, pattern constraints, and explicit ranges
3. Semantic drift over time Model behavior changes after an update, breaking previously valid outputs After a model version upgrade, the LLM starts using different phrasing for enum values, violating the schema Implement regression tests for every model update
4. Multi-step and nested inconsistencies Output is valid per step but contradictory when combined A travel booking flow: step 1 outputs 'departure: Paris', step 2 outputs 'arrival: Paris' — both valid, but illogical Use context-aware validation across steps
5. Safety and bias leakage Structured output does not filter toxic or biased content; schema only ensures format A hiring tool outputs a valid JSON with a 'reject_reason' field containing racist stereotypes Add content safety classifiers and human-in-the-loop review

1. Schema Hallucination

When an LLM is forced to produce a structured object, it may invent data that looks real. For example, a medical diagnosis app might output a structured JSON with a diagnosis_code field that matches the schema (e.g., a string of 3-5 alphanumeric characters) but corresponds to a nonexistent ICD-10 code. The schema cannot prevent this because it only checks format, not factual accuracy. The original article emphasizes that validation must go beyond syntax — every field should be checked against authoritative sources.

2. Ambiguous or Underdefined Schemas

A schema that is too permissive invites trouble. If a field like temperature is defined only as "type": "number", the model might output 1000°C for a weather forecast. The solution is to use minimum, maximum, enum, and pattern constraints liberally. The article notes that many developers treat JSON Schema as a lightweight formatter, but it should be treated as a rigorous contract.

3. Semantic Drift After Model Updates

LLMs are not static. When OpenAI or Anthropic release a new version, the way the model interprets a prompt can change. A prompt that reliably produced "status": "active" might start producing "status": "enabled" after an update, even though both are semantically similar. If the schema only accepts "active", the output breaks. The article recommends pinning model versions and running a suite of integration tests before upgrading.

4. Multi-Step and Nested Inconsistencies

Many real-world applications use chains of LLM calls. For instance, a system that first extracts a list of items, then generates a summary for each item. Each step may produce valid structured output, but the combination may be contradictory — e.g., the list says there are 5 items, but the summaries contain only 3. The schema for each step is correct, but there is no cross-step validation. The original piece suggests using a global state machine or dependency graph to enforce consistency.

5. Safety and Bias Leakage

Perhaps the most insidious failure: a structured output can be perfectly formatted yet contain harmful content. A moderation tool that outputs "action": "block", "reason": "user is a [racial slur]" is syntactically valid. The schema does not inspect the string content. The article stresses that safety filters must be applied at the content level, not just the schema level.

Practical Recommendations from the Industry

Based on the analysis in the source article and broader industry practices, here are actionable steps to increase the reliability of structured outputs:

  • Always combine schema validation with semantic validation. Use tools like Pydantic or Zod to define not just types but also business rules (e.g., age > 0 and age < 150).
  • Implement regression test suites. For every model version update, run a set of prompts and check that outputs still conform to expected values, not just format.
  • Use constrained decoding libraries. Libraries like Outlines, Guidance, or LMQL force the model to generate tokens that match the schema during generation, reducing hallucination. However, they do not eliminate semantic errors.
  • Add human-in-the-loop for high-stakes decisions. Structured outputs are great for automating low-risk tasks, but for medical, financial, or legal applications, a human should review the output before action is taken.
  • Monitor output distributions over time. If the distribution of values in a field shifts (e.g., "sentiment": "positive" appears 90% of the time instead of 50%), it may indicate semantic drift or bias.

The Role of External Integrations

Many structured output pipelines feed data into external systems — CRMs, databases, APIs. For example, a system that extracts contact information from emails and writes it to Salesforce must ensure that the extracted fields (name, email, phone) not only match the schema but also exist in reality. This is where validation against live data becomes critical. ASI Biont supports connecting to services like Salesforce through its API, enabling automated cross-referencing of structured outputs against real records. Learn more at asibiont.com/courses.

Conclusion

Structured outputs are a powerful tool for integrating LLMs into software systems, but they are not a cure-all. The five scenarios described in the OTUS article — schema hallucination, underdefined schemas, semantic drift, multi-step inconsistencies, and safety leakage — show that a valid schema is just the beginning. Developers must invest in rigorous validation, monitoring, and human oversight to ensure that structured outputs are not only well-formed but also correct, consistent, and safe. As the field matures, we can expect better tools for semantic validation, but for now, trust but verify remains the golden rule.


This article is based on a detailed analysis published on Habr. Read the original for deeper technical insights: Source.

← All posts

Comments