The string 2026-02-30 can satisfy a field that expects text. Before importing a generated row, check that its values follow the rules for that record and match the original document.
Suppose the import takes invoice ID, issue date, currency, net, tax, gross, and a source reference. Your schema can require the fields and restrict their types. A typed number can still have the wrong decimal placement or sign. Gemini’s structured-output guide explains JSON Schema support and calls for application validation of values. JSON Schema’s type documentation describes what type checks establish. Gemini structured outputs · JSON Schema type-specific keywords
Validate the row before committing it
Keep schema errors separate from rows that pass the schema and need further checks. Look up dates, reconcile amounts, and flag duplicates before comparing the record with its source. Treat IDs as text so leading zeros survive. Parse issue dates with a date library using the accepted format. Calculate totals with decimal arithmetic or appropriately scaled integer units and apply the rounding rule you use for that document type. Store the original extracted values alongside the normalized ones in your review file.
| Example failure | Rule to apply | Action |
|---|---|---|
The issue date is 2026-02-30. |
The date must exist in the calendar. | Hold for correction. |
| Net is 100.00, tax is 20.00, and gross is 102.00. | For this invoice type, net plus tax must match gross within the recorded rounding rule. | Check the amounts against the source. |
Two rows use invoice ID 004812 for the same sender. |
Sender and ID together must be unique for a new import. | Compare both originals before posting. |
| A source page shows a refund, but the generated row treats the amount as a charge. | The sign needs to match the document type and source. | Send to a reviewer to resolve. |
Check what the spreadsheet does next
Import an approved fixture to a disposable sheet first. Explicitly tell the import routine which columns contain identifiers, dates, and money. Reopen the saved sheet and check that 004812 still has both zeros, the date stays on the same day, and the currency column is separate from the numeric amount. A correctly validated row can still change type in a spreadsheet that guesses column formats.
Test what a syntactically good row can get wrong
Give the import a small fixture before connecting it to a real sheet. Put in a valid invoice, a row with an impossible calendar date, one duplicate and a refund. Add a case where all the amounts add up but the model chose the line labelled “amount paid” instead of “amount due.” A correct arithmetic relationship can still use the wrong financial field. Save the source page with each expected output and avoid passing the answer key to the model.
Use separate checks for required fields, acceptable values and evidence. The schema can say that a currency comes from an enumerated set. A business rule can compare it with the payment currency supported by this supplier. The source review can compare it with the document's currency marker. These checks answer different questions. A record might need help at any one stage, even if every other test passes.
An apparent duplicate also needs a rule grounded in your import. In this example, identify new invoices by sender plus invoice ID only if that matches the real documents. Some suppliers reset their numbering or reuse it in separate business units. Write down the scope in your worksheet. If two originals differ and both match the key, send both to review before changing a stored record. Add a separate test for a replay of the same source so rerunning the import can be checked independently.
Keep the untrusted result away from committed rows
Let the import stage hold rows until the fields can be inspected. Give each pending row a status and a reason to appear there. A record with a bad date can say which entry failed and link to the invoice. Preserve its raw value so a human can compare it with the revised one. Keep the approved copy separate once it has passed the checks to avoid accidental edits to source values in the final sheet.
Test text as it will appear in the spreadsheet. A supplier note or identifier can start with a character the spreadsheet treats specially. A field meant to be text should be imported as data without being interpreted as a formula, and its visible content should be checked after saving. This matters even with a JSON schema that restricts the field to a string. Also check that exported rows can be reopened later in the program that will consume them, since CSV does not carry type settings in the same way as an editable workbook.
Check the destination once a row has been written. In a disposable sheet, verify the type and value of one invoice ID with leading zeros, one date near the end of a month, and one negative amount. Recompute the amount according to the rules you actually use for the sample. If you need additional fees or per-line rounding, record those conditions before assuming net plus tax should always equal gross. Do not silently coerce the model's number into a value that fits.
Review both the result and the reason it stopped
For a straightforward correction, have a reviewer change the date or amount in the staged copy and rerun validation under the original key. If they cannot tell which source field established the value, hold the record until the evidence is available. A signed review can say what changed and whose decision it was. In a batch, compare the failed, approved and committed IDs so no row is silently lost between the stages.
Try the fixture again after changing the spreadsheet import or the model. If the invoice that looked right now goes in twice, inspect how the commit uses the source identifier. If the amounts change only in tables that span pages, follow the messy PDF table test to see where the values were moved before JSON validation.
At the handoff, keep normalised amounts in their own fields and preserve the source page reference on the committed row. This lets a downstream reviewer reconcile a value without depending on the prompt or the raw chat.


