A Python data integrator described receiving several delimited files a day. Two requirements stood out: one field can depend on another, and the client’s rules change more often than the importer. A field-by-field schema can confirm that both dates are dates while still accepting a late delivery.
I made a small handover for a fictional scanning studio. Its client wants three questions answered before accepting a batch:
| Rule | When | Compare |
|---|---|---|
| Collection prefix | Every batch | First three characters of the delivery ID and the source code |
| Arrival window | Ready for review | Received date minus promised date, in calendar days |
| Complete count | Ready for review | Received file count and expected file count |
The policy lives in a sheet. These are its actual exported rows:
rule_id,when_state,operation,left_field,right_field,argument collection_prefix,any,same_prefix,delivery_id,source_code,3 arrival_window,ready,within_days_after,received_date,promised_date,0 complete_count,ready,equal_counts,received_files,expected_files, Change one cell and predict which decision will move
HIS-002 had three files promised for May 4 and three received on May 5. ART-003 arrived May 4 with two files against a promise of three. Under the original policy each needs review, for a different reason.
I changed the arrival allowance from 0 to 2 in the workbook, exported the data and rules through LibreOffice Calc, and ran the same Python script on those CSVs:
Batch Strict policy Two calendar days HIS-002 REVIEW: arrival_window PASS ART-003 REVIEW: complete_count REVIEW: complete_count MET-004 PASS: 0 expected, 0 received PASS BOX-005 HOLD: still waiting HOLD ART-006 REVIEW: collection_prefix REVIEW: collection_prefix LOG-007 REVIEW: missing count REVIEW: missing count MAP-001 PASS PASS Only HIS-002 moved. The remaining examples catch two spreadsheet traps. The optional note on MAP-001 stayed blank, and its package name "Maps, east pier" remained one cell. A ready row with a blank received count stayed on review, whereas a legitimate zero count survived the round trip and matched a zero expectation.
The client can inspect the calculation without learning a new expression language. For the date rule, the comparison is effectively:
from datetime import date promised = date.fromisoformat("2026-05-04") received = date.fromisoformat("2026-05-05") days_late = (received - promised).days assert days_late > 0 assert days_late <= 2 The full checker tests the two named columns for each applicable rule and reports its ID with the reason. It accepts three documented operations. If a client needs a fourth kind of check, the handover makes that boundary visible.
The editable client workbook and checker include the seven deliveries and expected strict results. Extract the ZIP and run python3 check_delivery.py deliveries.csv rules.csv locally. The example deliberately returns exit status 1 because four batches need review. The original kit is CC0, so an integrator can put their own name on the handover and adapt it for a client.