The Illusion of Correctness: Valid JSON, Wrong Data
Large Language Models (LLMs) are increasingly tasked with generating structured data, often in JSON format. Developers leverage constrained decoding and output schemas to ensure the LLM's output conforms to a predefined structure. This provides a vital layer of validation, assuring that the output is syntactically correct JSON. However, this validation is superficial. It guarantees that the data fits the shape, but not that the data itself is accurate, meaningful, or logically sound. This creates a dangerous illusion of correctness. A valid JSON document can still contain fundamentally flawed information that undermines the entire application or analysis. We must look beyond simple schema adherence to uncover deeper failure modes.
Consider an LLM tasked with extracting product details from a description. It might correctly output a JSON object with fields like `"product_name"`, `"price"`, and `"features"`. The JSON is valid. But what if the `"price"` is listed as "free" when it should be $19.99, or `"features"` lists capabilities the product doesn't actually possess? These are not JSON syntax errors; they are factual and semantic errors that a schema validator cannot detect. The problem is not the LLM's ability to follow rules, but its ability to understand and accurately represent factual information, especially when faced with ambiguity or complex contextual requirements.

Five Failure Modes Beyond Schema Validation
Several common failure modes persist even when LLMs generate valid JSON. These issues stem from the LLM's inherent limitations in understanding context, nuance, and factual accuracy. Recognizing these modes is crucial for building robust systems that rely on LLM-generated structured data.
1. Factual Inaccuracies and Hallucinations
This is perhaps the most insidious failure mode. LLMs can confidently assert incorrect facts, misquote figures, or invent details that do not exist. When generating structured data, this translates to fields containing wrong numbers, incorrect dates, or non-existent entities. For example, an LLM asked to extract attendee lists from a meeting transcript might hallucinate attendees who were not present, or assign them incorrect roles.
2. Semantic Misinterpretation
LLMs can misunderstand the meaning of the input text or the intent behind the structured output request. This leads to data that is syntactically correct but semantically misplaced. An LLM might correctly extract a number that looks like a price but is actually a model number, or map a descriptor to the wrong field due to subtle wording differences. If an LLM is asked to extract all "costs" from a document, it might include the cost of a single component when the user intended to extract the total project cost.
3. Incomplete or Missing Data (Subtle Omissions)
While an LLM might be prompted to provide specific fields, it can sometimes omit crucial pieces of information without indicating they are missing. This isn't a failure to adhere to the schema, but a failure to fully capture the requested information. For instance, when asked to list all security vulnerabilities mentioned in a patch note, an LLM might only list the most prominent ones, omitting critical but less severe CVEs. The resulting JSON would be valid, but incomplete, leading to a false sense of security.
4. Logical Inconsistencies
The generated data might be factually correct in isolation but create logical contradictions when viewed as a whole. An LLM could generate a shipping address where the zip code does not match the state, or create a product configuration where a feature is listed as enabled but its prerequisite is listed as disabled. These inconsistencies are often subtle and require deeper logical reasoning to detect, something beyond the scope of typical JSON schema validation.
5. Outdated or Contextually Irrelevant Information
LLMs are trained on vast datasets, but these datasets have a cutoff point. Information that was accurate at the time of training may no longer be current. When generating structured data, an LLM might pull outdated pricing, deprecated API endpoints, or obsolete specifications. Furthermore, without specific temporal context in the prompt, the LLM may not understand the relevance of the data to the current time, leading to the inclusion of stale information.
Strategies for Robust Structured Data Generation
Addressing these failure modes requires a multi-pronged approach that goes beyond simple JSON schema validation. It involves better prompting, post-processing, and potentially human oversight.
Enhanced Prompt Engineering
Crafting prompts that are explicit, provide context, and define desired output characteristics is paramount. Instead of asking for "product details," specify "extract the exact retail price, list all included accessories, and confirm the warranty period from the following text." Providing examples (few-shot learning) can also significantly improve accuracy. You might also instruct the LLM to explicitly state if information is unavailable or ambiguous, rather than leaving it blank or guessing.
Post-Processing and Validation Layers
Implement additional validation layers after the LLM generates the JSON. This could include:
- Rule-based validation: Custom scripts to check for logical consistency (e.g., zip code matches state, feature prerequisites are met).
- External data lookups: Cross-referencing extracted information (like prices, product IDs, or CVE details) with authoritative databases.
- Semantic checks: Using smaller, specialized models or natural language inference techniques to verify the meaning and coherence of the extracted data.
- Range and constraint checks: Verifying numerical values fall within expected bounds (e.g., price is not negative, quantity is realistic).
Human-in-the-Loop
For critical applications, a human review step is often indispensable. This doesn't necessarily mean reviewing every single output, but implementing a sampling strategy or a tiered review process where high-stakes data is always human-verified. This provides a crucial feedback loop for identifying recurring LLM errors and improving automated checks.
By understanding these five failure modes and implementing robust validation strategies, developers can move beyond the superficial correctness of valid JSON to ensure the reliability and accuracy of the structured data generated by LLMs.
