Investigate a wrong structured answer through four checks: valid syntax, expected shape, valid domain values, and agreement with the source. Passing an earlier check does not establish the later ones.
An invoice can be parseable and incorrect
The example returns the expected keys with a numeric total and a date-shaped string. The date is February 30, and the total differs from the source record. A parser accepts the JSON. A simple shape check accepts the field types. Both values still need review.
Find the first failed check
- Save a synthetic or appropriately protected source reference with the extraction output.
- Check required fields and types using the schema mechanism supported by your stack.
- Check business rules such as valid calendar dates, currencies, and line-item totals.
- Compare the extracted values with the source, including handwritten corrections and page locations.
Be precise about format validation
JSON Schema’s format behavior depends on the dialect and validator configuration. Do not assume that a date annotation is always enforced. The example uses a narrow explicit calendar check and source comparison; it is not a complete JSON Schema validator or a general document extraction engine.
Retain useful failure categories
Classify invalid syntax, missing fields, invalid domain values, and unsupported source values separately. Fixing a schema mismatch will not necessarily improve OCR or field selection. Route uncertain critical fields to the intended reviewer and verify that downstream actions wait for that decision.
Run the worked example
Save the synthetic Node.js example and run node investigate-valid-json-with-wrong-values.mjs with Node.js 22 or newer. The assertions check the illustrated records and calculations; they do not test a deployed provider, SDK, or access control. No credentials or network connection are needed.
// Synthetic teaching fixture. No credentials, network calls, or production verification.
import assert from 'node:assert/strict';
const source = { invoiceDate: '2026-02-28', total: 120 };
const parsed = JSON.parse('{"invoiceDate":"2026-02-30","total":125}');
assert.equal(typeof parsed.invoiceDate, 'string');
assert.equal(typeof parsed.total, 'number');
const date = new Date(parsed.invoiceDate + 'T00:00:00Z');
const validDate = !Number.isNaN(date.valueOf()) && date.toISOString().slice(0, 10) === parsed.invoiceDate;
assert.equal(validDate, false);
assert.notEqual(parsed.total, source.total);
console.log('JSON parsed; shape passed; calendar and source checks failed.');
References and further reading
Maintained by DriftRail. AI assisted the October 2026 content and template revision. Examples are illustrative; they are not measured product benchmarks. Suggest a correction.