Structured Data Extraction with LLMs: Schemas, Validation, and Error Handling
information extractionJSONNLPstructured outputsdocument processing

Structured Data Extraction with LLMs: Schemas, Validation, and Error Handling

DDataWizards Editorial Team
2026-12-02
6 min read

A practical checklist for extracting reliable JSON with LLMs using schemas, validation, missing-value rules, testing, and review paths.

Reliable LLM structured data extraction requires more than asking a model to “return JSON.” This guide provides a reusable workflow for turning unstructured text into validated records: define fields precisely, represent missing information consistently, enforce a schema, validate the result, handle partial outputs, and route uncertain cases for review.

Overview

LLMs are useful for extracting names, dates, identifiers, attributes, events, and relationships from emails, support tickets, forms, reports, and other text. The input may be inconsistent, but your application usually needs predictable data. The practical goal is not merely valid JSON; it is a record that is structurally valid, semantically appropriate, traceable to the source, and safe for downstream systems.

A dependable extraction pipeline separates five responsibilities:

  1. Field design: Decide what the record must contain and what each field means.
  2. Extraction instructions: Tell the model how to find, normalize, and represent information.
  3. Structured generation: Use a provider-supported JSON mode, response schema, or equivalent constraint where available.
  4. Validation: Check syntax, types, allowed values, formats, and business rules in application code.
  5. Review and recovery: Handle missing, conflicting, or low-confidence information without silently inventing values.

Structured-output features differ by model, provider, and SDK. Treat them as an enforcement aid, not a replacement for validation. A schema may ensure that a field exists and has the expected type while leaving open whether the extracted value is correct.

Checklist by scenario

1. Extracting a simple record

For a stable document type, start with the smallest useful schema. Define each field in plain language and specify its type. For example, a customer inquiry might contain customer_name as a string, request_type as an enumerated value, requested_date as an ISO-formatted date or null, and summary as a short string.

  • Use field names that describe the stored meaning, not the wording found in one document.
  • Document whether a field is required, optional, nullable, or conditionally required.
  • List permitted enum values and define an unknown or other option when appropriate.
  • Specify normalization rules for dates, phone numbers, currencies, and identifiers.
  • Require the model to use null when the source does not support a value.

2. Extracting nested or repeated information

Use arrays for repeated entities rather than creating numbered fields such as item_1 and item_2. Define the object inside the array and explain how boundaries are determined. For an invoice, an items array might contain description, quantity, unit price, and line total.

  • State whether duplicate mentions should be merged or preserved.
  • Tell the model how to handle an item with only partial details.
  • Keep source order when order matters.
  • Set application-level limits for array length and text size.

3. Handling missing, ambiguous, or conflicting text

Extraction prompts should distinguish between “not present,” “unclear,” and “conflicting.” These states may require different downstream actions. A missing delivery date can be represented as null; two different delivery dates may require a conflict flag and a source excerpt.

Consider adding fields such as needs_review, review_reasons, and evidence. Evidence should quote or identify the relevant source span where permitted by your data-handling requirements. It makes debugging and human review easier than relying on an unexplained confidence score.

Reusable extraction prompt template

System: You extract structured information from the supplied source text. Follow the schema exactly. Use only information supported by the text. Do not guess. For missing values, return null. For ambiguous or conflicting values, preserve the ambiguity in the designated review fields. Return only the structured response.
User task: Extract the following fields from the source text: [field definitions and allowed values]. Normalize dates as YYYY-MM-DD. Preserve source meaning and do not infer facts that are not stated.

Pair this instruction with a provider-supported response schema when available. Keep the schema in code or version control so prompt changes and field changes can be reviewed together.

What to double-check

Field-design checklist

  • Meaning: Could two developers interpret the field differently?
  • Cardinality: Is the value singular, optional, or a list?
  • Nullability: Is null different from an empty string, zero, or an empty array?
  • Type: Should the value be a string, number, boolean, date, or nested object?
  • Precision: Should the system preserve the original wording or normalize it?
  • Evidence: Can a reviewer identify where the value came from?
  • Escalation: What conditions require human review?

Validation layers

Parse the response before using it. Then apply schema validation for required keys, types, nullability, and permitted values. Add semantic checks for rules the JSON schema cannot express, such as a start date occurring before an end date, a total matching the sum of line items, or an identifier matching the expected pattern.

Validation failures should produce actionable error categories. Separate malformed JSON, schema violations, unsupported enum values, missing evidence, and business-rule conflicts. This makes retry logic safer and helps reveal whether the problem is the prompt, the input, the model, or the validator.

Testing and evaluation

Create a representative test set containing clean examples, abbreviations, typos, long documents, empty fields, contradictory statements, multiple entities, and adversarial instructions embedded in the source. Compare extracted fields with reviewed reference records. Track field-level accuracy, null behavior, enum errors, validation failures, and review rates rather than judging only whether the response parsed.

For production prompt testing, version the model, prompt, schema, preprocessing steps, and parser. A change to any of these can alter extraction behavior. The LLM evaluation frameworks guide provides a broader workflow for testing accuracy, safety, and consistency.

Common mistakes

Failure modeWhy it happensBetter practice
Valid JSON with incorrect valuesSyntax is treated as proof of accuracy.Validate semantics and retain evidence for important fields.
Invented valuesThe prompt implies every field must be filled.Explicitly prohibit guessing and define null behavior.
Inconsistent missing valuesEmpty strings, “N/A,” and null are mixed.Choose one representation and enforce it in the schema.
Overly broad schemasEvery possible detail is included at once.Start with fields that have a clear downstream use.
Silent retriesFailures are retried without classification.Log the failure type, cap retries, and route unresolved records to review.
Untrusted source instructionsDocument text is allowed to influence extraction rules.Keep instructions separate from source content and test for prompt injection. See the prompt injection defense checklist.

Do not assume that adding more examples will fix every failure. Examples help clarify formatting and edge cases, but unclear field definitions, poor document segmentation, and weak validation often require engineering changes instead.

When to revisit

Revisit the extraction workflow before adding a new document type, changing a field, modifying allowed values, or connecting the output to a new downstream system. Also review it when source documents change format, when reviewers report a new ambiguity, or when validation and manual-review rates drift.

Before a seasonal planning cycle or a high-volume period, run the current test set plus fresh samples from the upcoming input. Confirm that token limits, truncation behavior, model capabilities, structured-output restrictions, SDK behavior, and parsing libraries still match your implementation. Provider APIs and schema support can change, so check the documentation for the exact model and version you deploy.

Use this final pre-release checklist:

  1. Freeze and review the schema.
  2. Document null, conflict, and normalization rules.
  3. Test clean, incomplete, contradictory, and malicious inputs.
  4. Validate syntax, schema, semantics, and evidence separately.
  5. Set retry limits and a human-review route.
  6. Log model, prompt, schema, and validator versions.
  7. Sample accepted records after deployment, not only rejected ones.

Reliable unstructured-text-to-JSON systems are built as controlled pipelines. The model performs interpretation, while schemas, validators, tests, and review paths determine whether that interpretation is safe to use.

Related Topics

#information extraction#JSON#NLP#structured outputs#document processing
D

DataWizards Editorial Team

AI Development and NLP Editor

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.