Resources · 81

AI extraction: validate JSON before integration

Separate parsing, schema checks, documentary evidence and business rules when turning documents into usable records.

· 4 min

Laptop displaying code on a desk Illustration · fictional scene

What this guide helps achieve

  • Define the result contract
  • Connect values to evidence
  • Validate in an explicit sequence
  • Test difficult documents
  • Plan recovery and correction

Quick check

  • Can valid JSON contain an error?
  • Should a missing field become zero?
  • When is human review needed?

Step-by-step method

  1. 01

    Define the result contract

    List necessary fields, types, units and missing-value states. JSON Schema distinguishes described properties from required fields: declaring a property does not make it mandatory. Decide whether extra fields are allowed. Retain the schema version for each batch and avoid collecting fields without a purpose.

    Deliverable: versioned schema and valid or rejected examples.

  2. 02

    Connect values to evidence

    Require page, passage or cell references for values that trigger an action. Allow an unknown state when information is absent. A correctly typed amount can belong to another document; a plausible date can be the issue date instead of the due date.

    Deliverable: field-to-evidence mapping and interpretation rule.

  3. 03

    Validate in an explicit sequence

    Check JSON parsing, schema conformity and business rules such as allowed currency, existing identifier, line totals and chronology. Schema conformity proves neither factual accuracy nor permission to write into a system. Keep business actions blocked until their conditions are met.

    Deliverable: distinct error classes and acceptance decisions.

  4. 04

    Test difficult documents

    Include split tables, multiple languages, conflicting values, empty documents and hostile instructions inside source text. Test refusals, truncation and retries. Keep evaluation cases separate from tuning and compare errors by field instead of treating an overall rate as a guarantee.

    Deliverable: reference set and critical error list.

  5. 05

    Plan recovery and correction

    Link document, model version, schema and result to a processing identifier. A retry must not create two records. Retain the reason for human corrections and locate downstream outputs. Avoid unnecessarily copying complete documents into logs.

    Deliverable: correction and controlled retry procedure.

From readable output to an authorized action

Passing one check does not replace the next. Stop when a necessary condition is not met.

  1. Parse JSON

    Is the response complete and parseable?

  2. Validate the contract

    Do types, fields, units and missing states match the schema?

  3. Verify values

    Do source evidence and business rules support the values?

  4. Authorize the action

    Are identity, scope and writing conditions satisfied?

Fictional example: parsing and schema checks pass, but two amounts conflict. Writing stays blocked and the record goes to review.

Reusable worksheet

Complete with your authorised observations. These fields are a working template, not observed results.

FieldInformation to record
ContractFields, types, units, missing states and schema version
EvidenceDocument and passage supporting each decisive field
ValidationParsing, schema, business checks and rejection reason
RecoveryProcessing identifier, duplicate prevention and propagated correction

Worked example

Illustrative situation

Fictional example: an extractor finds two invoice totals and selects the pre-tax amount while the connector expects the amount due.

Decision and expected evidence

The schema accepts the number, but reconciliation of lines and currency blocks the write and sends the document for review.

Distinguish the mechanisms

MechanismPurposeCheck or limitation
Parseable JSONAllow parsingDoes not validate required fields or meaning
Schema conformityCheck types and constraintsDoes not establish source fidelity
Business reconciliationCheck fitness and consistencyNeeds explicit rules and references

Management indicators

IndicatorWhat it measuresFirst action
Field accuracyCorrectly extracted values among evaluable fieldsPrioritize errors changing an action
Useful abstentionCases left undecided because evidence is missingReview the queue without encouraging invented values
Retry duplicatesRepeated records for the same processing operationCorrect deduplication

Common pitfalls

  • Does not validate required fields or meaning
  • Does not establish source fidelity
  • Needs explicit rules and references

Frequently asked questions

Can valid JSON contain an error?

Yes. Syntax and schema may be valid while an amount, identity or date is wrong. Check decisive values against their sources.

Should a missing field become zero?

Only when the contract assigns that meaning to zero. Otherwise use the agreed missing state; invented defaults distort calculations.

When is human review needed?

When conflicts, missing evidence or critical errors fall outside the accepted scope. Define these cases before processing batches.

Further reading and tools

Editorial resources to extend the method.

Official references

References consulted: . The method and worksheet propose checks to adapt to your context; they do not constitute certification.