Flag late shipments and draft customer notices.
Done by an agent. Checked twice.
Every open order marked late, at risk or on track, with a notice drafted for each customer whose order has a problem.
Real files in
- carriers.csv
The three carriers and how many days each takes to deliver. 4 lines, 74 bytes. - export_info.txt
The date the export was taken. 3 lines, 137 bytes. - orders.csv
One week of order export from an order desk: 41 rows for 40 orders, with one row exported twice, one missing promised date, one missing email and one date typed by hand. 42 lines, 5 KB.
Sample data written by Atris. Not a real company.
Three steps
- 1.Read the export and the carriers
- 2.Give every order one status
- 3.Write the status list and notices
Claude Sonnet 5.5, 1 min 4 s. No web. It never saw the check.
Checked twice
- Passed: 40 of 40 orders appear once in shipment_status.csv
- Passed: 40 of 40 statuses equal the status recomputed from the order export
- Passed: 40 of 40 orders have the right signal and the right days late
- Passed: 18 of 18 late or at risk orders have one notice and 0 notices went to other orders
- Passed: 18 of 18 notices name the customer, the promised date, the carrier date when there is one and the right contact
- Passed: 35 of 35 dates written in the notices appear in that order's own row
- Passed: summary.md gives the right count for 6 of 6 statuses
- Passed: 185 of 185 order numbers, dates and day counts in the reasons and notices come from that order's own row and the export date
- Passed: 84 of 84 dates and counts in summary.md match the export: order rows for the orders a line names, recomputed counts for the rest
Second review by Claude Opus 5.5: pass.
Then we broke a copy of the output 6 ways on purpose. The check caught 6.
## ORD-5008 To: office@callowayschool.example Subject: Order ORD-5008 is late Dear Calloway Middle School, Order ORD-5008 was promised for 2026-11-12 and is now 6 days late. The carrier's new delivery date is 2026-11-20. We are sorry for the inconvenience.
How this was run
An AI agent on Claude Sonnet 5.5 was given a folder with the files below and a three-step flow, and nothing else. It had no web access and never saw the check. The check was written before the run and made stricter after it. It works the answer out again from the input files. Then Claude Opus 5.5 reviewed the result against the inputs. The input files are sample data written by Atris, with the problems a real week has planted in them.
Run 3 of 3 on 1 December 2026. The agent took 1 min 4 s. Run 1 passed both checks and the job was run again later. Run 2 passed both checks and the job was run again later. Each run starts clean. Between runs the written flow was made clearer, or a check was corrected or made stricter. Nobody edits the output.
What the second review verified
- Recomputed every status against the export date 2026-11-18. Counts are 8 late, 10 at_risk, 11 on_track, 8 delivered, 2 cancelled and 1 needs_review, for 40 orders from 41 rows. ORD-5009 was exported twice and is counted once.
- Checked the edge cases where a date equals the promised date. ORD-5027's ETA of 2026-11-20 matches its promise, so it is on_track. ORD-5028 (2026-11-18 + 5 days = 2026-11-23) and ORD-5032 (+2 days = 2026-11-20) also land exactly on their promised dates, so both are on_track. ORD-5026's last scan was 3 days before the export date, so it is stalled_scan. ORD-5011 is past its promise and has an exception, and late correctly comes first: 4 days late.
- Checked days_late and grammar: ORD-5014 is 8 days, ORD-5013 is 7 days, ORD-5012 and ORD-5038 are '1 day'. ORD-5020's promised date 11/20/2026 was read as 2026-11-20, which correctly makes ORD-5023 ('summit freight', 7 days of transit) not_shipped_in_time.
- Notices: there are exactly 18, one for each late or at_risk order. ORD-5010 has 'To: no email on file'. ORD-5013 uses the name as written on its row, 'Halvorsen Dental Grp'. Every new delivery date comes from that order's own carrier_eta, and no notice gives a cause. The summary lists all 6 data problems: missing promised date, missing email, duplicate row, MM/DD/YYYY date, customer name typed two ways, carrier name in lowercase.
What the second review found wrong
- Minor wording issue in notices.md for ORD-5017: after the delivery exception it adds 'so it may not arrive by that date' and then gives a new delivery date of 2026-11-20, which is the same as the promised date. That reads a little contradictory, but it does not break any rule.
- Minor judgment call in notices.md for ORD-5011: the order is late and also has an exception, and the notice does not mention the exception. The summary says this was done on purpose.
What this run does not show
- This took three runs because the second review found wording faults in notices that had already passed the check.
- The final run still carries two small wording notes from the second review, since the check reads dates and counts but not tone.
- A date in a notice swapped for another date from the same order's row would still pass the check.
Would the check catch a wrong answer?
A check that cannot fail proves nothing. After the run we took a copy of the output, broke it one small way at a time and ran the check again. It caught 6 of 6. The check was made stricter after the first try at this, and the same untouched output was graded again.
Open every file
flow.md · the three steps the agent followed
# Flag late shipments and draft customer notices function: operations for: the person who runs the order desk goal: Every open order is marked late, at risk or on track. Each customer with a problem order has a notice ready to send. ## 1. Read the export and the carriers Read input/orders.csv, input/carriers.csv and input/export_info.txt. The export date in export_info.txt is "today" for every rule below. Most dates are written YYYY-MM-DD but some rows use MM/DD/YYYY. Read both. Match carrier names without regard to capital letters. If the same order_id appears twice with the same data, count it once. ## 2. Give every order one status Check in this order and use the first status that applies: - `cancelled` when the export status is cancelled. - `delivered` when delivered_date is filled. - `needs_review` when promised_date is blank. - `late` when promised_date is before the export date. - `at_risk` when any signal below applies. - `on_track` in every other case. A `late` order has the signal `past_promise`. An `at_risk` order has the first of these signals that applies: - `exception` when the export status is exception. - `eta_after_promise` when carrier_eta is filled and is after promised_date. - `not_shipped_in_time` when ship_date is blank and the export date plus the carrier's transit_days is after promised_date. - `stalled_scan` when ship_date is filled and last_scan_date is 3 or more days before the export date. A date equal to promised_date is not after it. ## 3. Write the status list and notices Write output/shipment_status.csv with columns order_id,status,signal,days_late,reason. One row per order. signal is blank unless the status is late or at_risk. days_late is the number of days from promised_date to the export date for late orders and 0 for every other order. reason is one plain sentence with the dates that decided it. Check the grammar of every sentence you write, such as `1 day` but `2 days`. Write output/notices.md with one notice for each late or at_risk order and for no other order. Each notice starts with a heading line `## <order_id>`, then a line `To: <contact_email>`, then a `Subject:` line, then a short message to the customer. When contact_email is blank write `To: no email on file`. The message names the customer as written on that row, gives the order id and the promised date. It says plainly what is known: how many days late it is, or why it may slip. Give the carrier's new delivery date when carrier_eta is filled. When it is blank say a new date is not yet confirmed. Never promise a date or give a cause that is not in that order's row. For an exception order say only that the shipment has a delivery exception on record. Do not say who raised it or why. Write every date as YYYY-MM-DD. Write output/summary.md with the count of orders in each status and a list of anything the order desk must fix in the data, such as a missing promised date, a missing email, a row exported twice, a date typed in another format or a customer or carrier name typed two ways. ## Done looks like - Every order appears once in shipment_status.csv with one status. - Every late or at risk order has a notice and no other order has one. - No notice states a date that is not in that order's row, other than the export date.
input/carriers.csv · 4 lines, 74 bytes
carrier,transit_days Northline Express,2 Harbor Ground,5 Summit Freight,7
input/export_info.txt · 3 lines, 137 bytes
Order export from the order desk. Export date: 2026-11-18 One row per order. Dates are year-month-day unless a clerk typed them by hand.
input/orders.csv · 42 lines, 5 KB
order_id,customer,contact_email,order_date,promised_date,status,carrier,ship_date,last_scan_date,carrier_eta,delivered_date ORD-5001,Halvorsen Dental Group,orders@halvorsendental.example,2026-11-02,2026-11-09,delivered,Harbor Ground,2026-11-03,2026-11-07,,2026-11-07 ORD-5002,Pine Hollow Bakery,ops@pinehollowbakery.example,2026-11-02,2026-11-06,delivered,Northline Express,2026-11-03,2026-11-05,,2026-11-05 ORD-5003,Tamsin Veterinary Clinic,frontdesk@tamsinvet.example,2026-11-03,2026-11-10,delivered,Harbor Ground,2026-11-04,2026-11-12,,2026-11-12 ORD-5004,Quarry Road Auto Body,parts@quarryroadauto.example,2026-11-03,2026-11-12,delivered,Summit Freight,2026-11-04,2026-11-11,,2026-11-11 ORD-5005,Lark and Finch Florists,hello@larkandfinch.example,2026-11-04,2026-11-11,delivered,Harbor Ground,2026-11-05,2026-11-10,,2026-11-10 ORD-5006,Brindle Street Pharmacy,purchasing@brindlepharmacy.example,2026-11-04,2026-11-13,delivered,Summit Freight,2026-11-05,2026-11-13,,2026-11-13 ORD-5007,Osterhaut Print Shop,jobs@osterhautprint.example,2026-11-05,2026-11-12,delivered,Harbor Ground,2026-11-06,2026-11-16,,2026-11-16 ORD-5008,Calloway Middle School,office@callowayschool.example,2026-11-05,2026-11-12,shipped,Harbor Ground,2026-11-07,2026-11-13,2026-11-20, ORD-5009,Pine Hollow Bakery,ops@pinehollowbakery.example,2026-11-05,2026-11-13,shipped,Summit Freight,2026-11-08,2026-11-17,2026-11-19, ORD-5010,Wexcombe Fitness Studio,,2026-11-06,2026-11-16,shipped,Harbor Ground,2026-11-10,2026-11-12,, ORD-5011,Marlow Creek Brewing,cellar@marlowcreek.example,2026-11-06,2026-11-14,exception,Summit Freight,2026-11-08,2026-11-11,, ORD-5012,Dunmere Law Office,admin@dunmerelaw.example,2026-11-06,2026-11-17,processing,Northline Express,,,, ORD-5013,Halvorsen Dental Grp,orders@halvorsendental.example,2026-11-07,2026-11-11,shipped,Northline Express,2026-11-09,2026-11-16,2026-11-18, ORD-5014,Sable Point Marina,dock@sablepointmarina.example,2026-11-07,2026-11-10,shipped,Harbor Ground,2026-11-08,2026-11-09,, ORD-5015,Quarry Road Auto Body,parts@quarryroadauto.example,2026-11-07,2026-11-14,cancelled,Harbor Ground,,,, ORD-5016,Thistledown Yarn Co,shop@thistledownyarn.example,2026-11-09,2026-11-23,cancelled,Summit Freight,,,, ORD-5017,Kettering Optical,lab@ketteringoptical.example,2026-11-09,2026-11-20,exception,Harbor Ground,2026-11-12,2026-11-17,2026-11-20, ORD-5018,Brindle Street Pharmacy,purchasing@brindlepharmacy.example,2026-11-10,2026-11-24,exception,Summit Freight,2026-11-13,2026-11-15,, ORD-5019,Lark and Finch Florists,hello@larkandfinch.example,2026-11-10,2026-11-19,shipped,Harbor Ground,2026-11-14,2026-11-17,2026-11-21, ORD-5020,Ferncliff Hardware,counter@ferncliffhardware.example,2026-11-10,11/20/2026,shipped,Summit Freight,2026-11-13,2026-11-14,2026-11-23, ORD-5021,Osterhaut Print Shop,jobs@osterhautprint.example,2026-11-11,2026-11-18,shipped,Northline Express,2026-11-16,2026-11-17,2026-11-19, ORD-5022,Tamsin Veterinary Clinic,frontdesk@tamsinvet.example,2026-11-11,2026-11-21,processing,Harbor Ground,,,, ORD-5023,Glasswing Art Supply,orders@glasswingart.example,2026-11-12,2026-11-24,processing,summit freight,,,, ORD-5024,Marlow Creek Brewing,cellar@marlowcreek.example,2026-11-12,2026-11-19,processing,Northline Express,,,, ORD-5009,Pine Hollow Bakery,ops@pinehollowbakery.example,2026-11-05,2026-11-13,shipped,Summit Freight,2026-11-08,2026-11-17,2026-11-19, ORD-5025,Redfern Community Clinic,supply@redfernclinic.example,2026-11-09,2026-11-20,shipped,Harbor Ground,2026-11-12,2026-11-14,2026-11-19, ORD-5026,Calloway Middle School,office@callowayschool.example,2026-11-10,2026-11-23,shipped,Summit Freight,2026-11-12,2026-11-15,, ORD-5027,Ferncliff Hardware,counter@ferncliffhardware.example,2026-11-11,2026-11-20,shipped,Harbor Ground,2026-11-14,2026-11-17,2026-11-20, ORD-5028,Sable Point Marina,dock@sablepointmarina.example,2026-11-12,2026-11-23,processing,Harbor Ground,,,, ORD-5029,Kettering Optical,lab@ketteringoptical.example,2026-11-12,2026-11-25,processing,Summit Freight,,,, ORD-5030,Thistledown Yarn Co,shop@thistledownyarn.example,2026-11-12,2026-11-21,shipped,Harbor Ground,2026-11-14,2026-11-16,2026-11-20, ORD-5031,Glasswing Art Supply,orders@glasswingart.example,2026-11-13,2026-11-18,shipped,Northline Express,2026-11-16,2026-11-17,2026-11-18, ORD-5032,Dunmere Law Office,admin@dunmerelaw.example,2026-11-13,2026-11-20,processing,Northline Express,,,, ORD-5033,Wexcombe Fitness Studio,manager@wexcombefitness.example,2026-11-13,2026-11-27,shipped,Summit Freight,2026-11-16,2026-11-17,2026-11-25, ORD-5034,Redfern Community Clinic,supply@redfernclinic.example,2026-11-14,2026-11-24,shipped,Harbor Ground,2026-11-16,2026-11-18,, ORD-5035,Pine Hollow Bakery,ops@pinehollowbakery.example,2026-11-14,2026-11-25,processing,Harbor Ground,,,, ORD-5036,Halvorsen Dental Group,orders@halvorsendental.example,2026-11-16,2026-11-30,processing,Summit Freight,,,, ORD-5037,Marrowfield Catering,kitchen@marrowfieldcatering.example,2026-11-13,,shipped,Harbor Ground,2026-11-15,2026-11-17,2026-11-21, ORD-5038,Quarry Road Auto Body,parts@quarryroadauto.example,2026-11-14,2026-11-17,shipped,Northline Express,2026-11-16,2026-11-17,2026-11-18, ORD-5039,Marrowfield Catering,kitchen@marrowfieldcatering.example,2026-11-16,2026-11-19,shipped,Northline Express,2026-11-17,2026-11-17,2026-11-19, ORD-5040,Brindle Street Pharmacy,purchasing@brindlepharmacy.example,2026-11-16,2026-11-17,delivered,Northline Express,2026-11-16,2026-11-17,,2026-11-17
output/notices.md · written by the agent, 145 lines
# Customer notices ## ORD-5008 To: office@callowayschool.example Subject: Order ORD-5008 is late Dear Calloway Middle School, Order ORD-5008 was promised for 2026-11-12 and is now 6 days late. The carrier's new delivery date is 2026-11-20. We are sorry for the inconvenience. ## ORD-5009 To: ops@pinehollowbakery.example Subject: Order ORD-5009 is late Dear Pine Hollow Bakery, Order ORD-5009 was promised for 2026-11-13 and is now 5 days late. The carrier's new delivery date is 2026-11-19. We are sorry for the inconvenience. ## ORD-5010 To: no email on file Subject: Order ORD-5010 is late Dear Wexcombe Fitness Studio, Order ORD-5010 was promised for 2026-11-16 and is now 2 days late. A new delivery date is not yet confirmed. We are sorry for the inconvenience. ## ORD-5011 To: cellar@marlowcreek.example Subject: Order ORD-5011 is late Dear Marlow Creek Brewing, Order ORD-5011 was promised for 2026-11-14 and is now 4 days late. A new delivery date is not yet confirmed. We are sorry for the inconvenience. ## ORD-5012 To: admin@dunmerelaw.example Subject: Order ORD-5012 is late Dear Dunmere Law Office, Order ORD-5012 was promised for 2026-11-17 and is now 1 day late. A new delivery date is not yet confirmed. We are sorry for the inconvenience. ## ORD-5013 To: orders@halvorsendental.example Subject: Order ORD-5013 is late Dear Halvorsen Dental Grp, Order ORD-5013 was promised for 2026-11-11 and is now 7 days late. The carrier's new delivery date is 2026-11-18. We are sorry for the inconvenience. ## ORD-5014 To: dock@sablepointmarina.example Subject: Order ORD-5014 is late Dear Sable Point Marina, Order ORD-5014 was promised for 2026-11-10 and is now 8 days late. A new delivery date is not yet confirmed. We are sorry for the inconvenience. ## ORD-5017 To: lab@ketteringoptical.example Subject: Delivery exception on order ORD-5017 Dear Kettering Optical, Order ORD-5017, promised for 2026-11-20, has a delivery exception on record, so it may not arrive by that date. The carrier's new delivery date is 2026-11-20. We are sorry for the inconvenience. ## ORD-5018 To: purchasing@brindlepharmacy.example Subject: Delivery exception on order ORD-5018 Dear Brindle Street Pharmacy, Order ORD-5018, promised for 2026-11-24, has a delivery exception on record, so it may not arrive by that date. A new delivery date is not yet confirmed. We are sorry for the inconvenience. ## ORD-5019 To: hello@larkandfinch.example Subject: Order ORD-5019 may arrive after 2026-11-19 Dear Lark and Finch Florists, Order ORD-5019 was promised for 2026-11-19, but the carrier now shows a later delivery date. The carrier's new delivery date is 2026-11-21. We are sorry for the inconvenience. ## ORD-5020 To: counter@ferncliffhardware.example Subject: Order ORD-5020 may arrive after 2026-11-20 Dear Ferncliff Hardware, Order ORD-5020 was promised for 2026-11-20, but the carrier now shows a later delivery date. The carrier's new delivery date is 2026-11-23. We are sorry for the inconvenience. ## ORD-5021 To: jobs@osterhautprint.example Subject: Order ORD-5021 may arrive after 2026-11-18 Dear Osterhaut Print Shop, Order ORD-5021 was promised for 2026-11-18, but the carrier now shows a later delivery date. The carrier's new delivery date is 2026-11-19. We are sorry for the inconvenience. ## ORD-5022 To: frontdesk@tamsinvet.example Subject: Order ORD-5022 may arrive after 2026-11-21 Dear Tamsin Veterinary Clinic, Order ORD-5022 was promised for 2026-11-21, but it has not shipped yet, so it may arrive after that date. A new delivery date is not yet confirmed. We are sorry for the inconvenience. ## ORD-5023 To: orders@glasswingart.example Subject: Order ORD-5023 may arrive after 2026-11-24 Dear Glasswing Art Supply, Order ORD-5023 was promised for 2026-11-24, but it has not shipped yet, so it may arrive after that date. A new delivery date is not yet confirmed. We are sorry for the inconvenience. ## ORD-5024 To: cellar@marlowcreek.example Subject: Order ORD-5024 may arrive after 2026-11-19 Dear Marlow Creek Brewing, Order ORD-5024 was promised for 2026-11-19, but it has not shipped yet, so it may arrive after that date. A new delivery date is not yet confirmed. We are sorry for the inconvenience. ## ORD-5025 To: supply@redfernclinic.example Subject: Order ORD-5025 may be delayed Dear Redfern Community Clinic, Order ORD-5025 was promised for 2026-11-20, but its last carrier scan was on 2026-11-14, so it may be delayed. The carrier's new delivery date is 2026-11-19. We are sorry for the inconvenience. ## ORD-5026 To: office@callowayschool.example Subject: Order ORD-5026 may be delayed Dear Calloway Middle School, Order ORD-5026 was promised for 2026-11-23, but its last carrier scan was on 2026-11-15, so it may be delayed. A new delivery date is not yet confirmed. We are sorry for the inconvenience. ## ORD-5038 To: parts@quarryroadauto.example Subject: Order ORD-5038 is late Dear Quarry Road Auto Body, Order ORD-5038 was promised for 2026-11-17 and is now 1 day late. The carrier's new delivery date is 2026-11-18. We are sorry for the inconvenience.
output/shipment_status.csv · written by the agent, 41 lines
order_id,status,signal,days_late,reason ORD-5001,delivered,,0,Delivered on 2026-11-07. ORD-5002,delivered,,0,Delivered on 2026-11-05. ORD-5003,delivered,,0,Delivered on 2026-11-12. ORD-5004,delivered,,0,Delivered on 2026-11-11. ORD-5005,delivered,,0,Delivered on 2026-11-10. ORD-5006,delivered,,0,Delivered on 2026-11-13. ORD-5007,delivered,,0,Delivered on 2026-11-16. ORD-5008,late,past_promise,6,The promised date 2026-11-12 is 6 days before the export date 2026-11-18 and the order is not delivered. ORD-5009,late,past_promise,5,The promised date 2026-11-13 is 5 days before the export date 2026-11-18 and the order is not delivered. ORD-5010,late,past_promise,2,The promised date 2026-11-16 is 2 days before the export date 2026-11-18 and the order is not delivered. ORD-5011,late,past_promise,4,The promised date 2026-11-14 is 4 days before the export date 2026-11-18 and the order is not delivered. ORD-5012,late,past_promise,1,The promised date 2026-11-17 is 1 day before the export date 2026-11-18 and the order is not delivered. ORD-5013,late,past_promise,7,The promised date 2026-11-11 is 7 days before the export date 2026-11-18 and the order is not delivered. ORD-5014,late,past_promise,8,The promised date 2026-11-10 is 8 days before the export date 2026-11-18 and the order is not delivered. ORD-5015,cancelled,,0,The export status is cancelled. ORD-5016,cancelled,,0,The export status is cancelled. ORD-5017,at_risk,exception,0,The export status is exception and the promised date is 2026-11-20. ORD-5018,at_risk,exception,0,The export status is exception and the promised date is 2026-11-24. ORD-5019,at_risk,eta_after_promise,0,The carrier ETA 2026-11-21 is after the promised date 2026-11-19. ORD-5020,at_risk,eta_after_promise,0,The carrier ETA 2026-11-23 is after the promised date 2026-11-20. ORD-5021,at_risk,eta_after_promise,0,The carrier ETA 2026-11-19 is after the promised date 2026-11-18. ORD-5022,at_risk,not_shipped_in_time,0,"The order has no ship date and the export date 2026-11-18 plus 5 days of transit is 2026-11-23, after the promised date 2026-11-21." ORD-5023,at_risk,not_shipped_in_time,0,"The order has no ship date and the export date 2026-11-18 plus 7 days of transit is 2026-11-25, after the promised date 2026-11-24." ORD-5024,at_risk,not_shipped_in_time,0,"The order has no ship date and the export date 2026-11-18 plus 2 days of transit is 2026-11-20, after the promised date 2026-11-19." ORD-5025,at_risk,stalled_scan,0,"The last scan was on 2026-11-14, 4 days before the export date 2026-11-18." ORD-5026,at_risk,stalled_scan,0,"The last scan was on 2026-11-15, 3 days before the export date 2026-11-18." ORD-5027,on_track,,0,The promised date 2026-11-20 is not before the export date 2026-11-18 and no risk signal applies. ORD-5028,on_track,,0,The promised date 2026-11-23 is not before the export date 2026-11-18 and no risk signal applies. ORD-5029,on_track,,0,The promised date 2026-11-25 is not before the export date 2026-11-18 and no risk signal applies. ORD-5030,on_track,,0,The promised date 2026-11-21 is not before the export date 2026-11-18 and no risk signal applies. ORD-5031,on_track,,0,The promised date 2026-11-18 is not before the export date 2026-11-18 and no risk signal applies. ORD-5032,on_track,,0,The promised date 2026-11-20 is not before the export date 2026-11-18 and no risk signal applies. ORD-5033,on_track,,0,The promised date 2026-11-27 is not before the export date 2026-11-18 and no risk signal applies. ORD-5034,on_track,,0,The promised date 2026-11-24 is not before the export date 2026-11-18 and no risk signal applies. ORD-5035,on_track,,0,The promised date 2026-11-25 is not before the export date 2026-11-18 and no risk signal applies. ORD-5036,on_track,,0,The promised date 2026-11-30 is not before the export date 2026-11-18 and no risk signal applies. ORD-5037,needs_review,,0,"The promised date is blank, so lateness cannot be checked." ORD-5038,late,past_promise,1,The promised date 2026-11-17 is 1 day before the export date 2026-11-18 and the order is not delivered. ORD-5039,on_track,,0,The promised date 2026-11-19 is not before the export date 2026-11-18 and no risk signal applies. ORD-5040,delivered,,0,Delivered on 2026-11-17.
output/summary.md · written by the agent, 36 lines
# Shipment status summary Export date used as today: 2026-11-18. The export has 41 rows and 40 distinct orders (ORD-5009 appears twice with identical data and is counted once). ## Orders by status | Status | Orders | |---|---| | late | 8 | | at_risk | 10 | | on_track | 11 | | delivered | 8 | | cancelled | 2 | | needs_review | 1 | | **Total** | **40** | - late (8): ORD-5008, ORD-5009, ORD-5010, ORD-5011, ORD-5012, ORD-5013, ORD-5014, ORD-5038 - at_risk (10): ORD-5017, ORD-5018 (exception); ORD-5019, ORD-5020, ORD-5021 (eta_after_promise); ORD-5022, ORD-5023, ORD-5024 (not_shipped_in_time); ORD-5025, ORD-5026 (stalled_scan) - needs_review (1): ORD-5037 - 18 notices are in notices.md, one for each late or at_risk order. ## Data the order desk must fix 1. **Missing promised date:** ORD-5037 (Marrowfield Catering) has no promised_date, so it is marked needs_review and has no notice. Add the promised date and re-check it. 2. **Missing email:** ORD-5010 (Wexcombe Fitness Studio) has no contact_email. It is late, and its notice shows "To: no email on file". Wexcombe's other order, ORD-5033, has manager@wexcombefitness.example. I did not copy that address, because the row for ORD-5010 does not give one. 3. **Row exported twice:** ORD-5009 appears on two rows with identical data. I counted it once. Remove the duplicate from the export. 4. **Date in another format:** ORD-5020 has promised_date 11/20/2026. I read it as 2026-11-20. Retype it as YYYY-MM-DD. No other date uses this format. 5. **Customer name typed two ways:** ORD-5013 reads "Halvorsen Dental Grp". The other Halvorsen orders (ORD-5001, ORD-5036) read "Halvorsen Dental Group", and all use the same email. I kept the name as written on the row in the ORD-5013 notice. Fix the name in the order data. 6. **Carrier name typed two ways:** ORD-5023 reads "summit freight". Every other row reads "Summit Freight". I matched it without regard to capital letters. ## Other things to know - Two delivered orders arrived after their promised date: ORD-5003 (promised 2026-11-10, delivered 2026-11-12) and ORD-5007 (promised 2026-11-12, delivered 2026-11-16). Delivered takes priority, so both are marked delivered. No notice was written for them. - ORD-5011 has export status exception and is also past its promised date. It is marked late, because the late rule is checked first. Its notice gives the days late and does not mention the exception. - ORD-5012 has not shipped and its promised date has passed. It is marked late. - The export does not give a cause for any delay. The notices state no causes.
check.py · the check, written before the run
"""Recomputes every order's status and signal from the export, then checks each notice against its order row."""
import csv, re, sys
from datetime import date, timedelta
from pathlib import Path
root = Path(sys.argv[1]); ok = True
def say(passed, text):
global ok; ok = ok and passed; print(("PASS " if passed else "FAIL ") + text)
def day(s):
s = (s or "").strip()
if not s: return None
m = re.fullmatch(r"(\d{1,2})/(\d{1,2})/(\d{4})", s)
if m: return date(int(m.group(3)), int(m.group(1)), int(m.group(2)))
return date.fromisoformat(s)
today = day(re.search(r"Export date:\s*(\S+)", (root/"input/export_info.txt").read_text()).group(1))
transit = {r["carrier"].strip().lower(): int(r["transit_days"]) for r in csv.DictReader((root/"input/carriers.csv").open())}
orders = {}
for r in csv.DictReader((root/"input/orders.csv").open()):
orders.setdefault(r["order_id"], r)
want = {}
for oid, r in orders.items():
prom, eta, ship, scan = day(r["promised_date"]), day(r["carrier_eta"]), day(r["ship_date"]), day(r["last_scan_date"])
st, sig, late = "on_track", "", 0
if r["status"].strip().lower() == "cancelled": st = "cancelled"
elif r["delivered_date"].strip(): st = "delivered"
elif prom is None: st = "needs_review"
elif prom < today: st, sig, late = "late", "past_promise", (today - prom).days
elif r["status"].strip().lower() == "exception": st, sig = "at_risk", "exception"
elif eta and eta > prom: st, sig = "at_risk", "eta_after_promise"
elif ship is None and today + timedelta(days=transit[r["carrier"].strip().lower()]) > prom: st, sig = "at_risk", "not_shipped_in_time"
elif ship and scan and (today - scan).days >= 3: st, sig = "at_risk", "stalled_scan"
want[oid] = (st, sig, late)
path = root/"output/shipment_status.csv"
if not path.exists():
say(False, "output/shipment_status.csv was not written"); sys.exit(1)
rows = list(csv.DictReader(path.open()))
got = {r.get("order_id", ""): r for r in rows}
once = sum(1 for k in want if sum(1 for r in rows if r.get("order_id") == k) == 1)
say(once == len(want) and len(rows) == len(want), f"{once} of {len(want)} orders appear once in shipment_status.csv")
right = sum(1 for k, v in want.items() if (got.get(k, {}).get("status") or "").strip() == v[0])
say(right == len(want), f"{right} of {len(want)} statuses equal the status recomputed from the order export")
def num(s):
try: return int(float(s))
except (TypeError, ValueError): return 0 if not (s or "").strip() else None
flagged = [k for k, v in want.items() if v[0] in ("late", "at_risk")]
sig = sum(1 for k, v in want.items() if (got.get(k, {}).get("signal") or "").strip() == v[1] and num(got.get(k, {}).get("days_late")) == v[2])
say(sig == len(want), f"{sig} of {len(want)} orders have the right signal and the right days late")
text = (root/"output/notices.md").read_text() if (root/"output/notices.md").exists() else ""
notices = {}
for part in re.split(r"(?m)^## +", text)[1:]:
m = re.search(r"ORD-\d+", part.splitlines()[0])
if m: notices.setdefault(m.group(0), []).append(part)
have = sum(1 for k in flagged if len(notices.get(k, [])) == 1)
extra = [k for k in notices if k not in flagged]
say(have == len(flagged) and not extra, f"{have} of {len(flagged)} late or at risk orders have one notice and {len(extra)} notices went to other orders")
good = dates = baddates = 0
for k in flagged:
body = (notices.get(k) or [""])[0]; r = orders[k]
to = re.search(r"(?mi)^\**To:\**\s*(.+)$", body)
to = to.group(1).strip().lower() if to else ""
email = r["contact_email"].strip().lower()
to_ok = (email in to) if email else ("no email on file" in to and "@" not in to)
prom, eta = day(r["promised_date"]), day(r["carrier_eta"])
if to_ok and r["customer"].lower() in body.lower() and prom.isoformat() in body and (eta is None or eta.isoformat() in body):
good += 1
allowed = {d.isoformat() for d in (day(r[c]) for c in ("order_date", "promised_date", "ship_date", "last_scan_date", "carrier_eta")) if d} | {today.isoformat()}
for d in re.findall(r"\d{4}-\d{2}-\d{2}", body):
dates += 1; baddates += d not in allowed
baddates += len(re.findall(r"\b\d{1,2}/\d{1,2}/\d{2,4}\b|\b(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[a-z]*\.? \d{1,2}\b", body))
say(good == len(flagged), f"{good} of {len(flagged)} notices name the customer, the promised date, the carrier date when there is one and the right contact")
say(dates > 0 and baddates == 0, f"{dates - min(baddates, dates)} of {dates} dates written in the notices appear in that order's own row")
summary = (root/"output/summary.md").read_text().lower() if (root/"output/summary.md").exists() else ""
names = ["cancelled", "delivered", "needs_review", "late", "at_risk", "on_track"]
counted = 0
for n in names:
c = sum(1 for v in want.values() if v[0] == n)
pat = r"(?<![a-z_])" + n.replace("_", "[ _-]") + r"(?![a-z_])"
counted += any(re.search(pat, ln) and re.search(rf"(?<![\d-])\**{c}\**(?![\d-])", ln) for ln in summary.splitlines())
say(counted == len(names), f"summary.md gives the right count for {counted} of {len(names)} statuses")
# Dates and day counts that belong to one order: its own row, the export date and the sums the rules ask for.
iso = r"\d{4}-\d{2}-\d{2}"; slash = r"\b\d{1,2}/\d{1,2}/\d{2,4}\b"; cols = ("order_date", "promised_date", "ship_date", "last_scan_date", "carrier_eta", "delivered_date")
def facts(k):
r = orders[k]; ds = {day(r[c]) for c in cols if r[c].strip()} | {today}
lead = transit.get(r["carrier"].strip().lower())
if lead is not None: ds.add(today + timedelta(days=lead))
return {d.isoformat() for d in ds}, {abs((a - b).days) for a in ds for b in ds} | ({lead} if lead is not None else set()), {r[c].strip() for c in cols}
def plain(s): return re.sub(iso + "|" + slash + r"|ORD-\d+|\S+@\S+", " ", s)
seen = wrong = 0; odd = []
for k in want:
days_ok, counts_ok, _ = facts(k)
for s in [got.get(k, {}).get("reason") or ""] + notices.get(k, []):
for d in re.findall(iso, s):
seen += 1
if d not in days_ok: wrong += 1; odd.append(f"{d} for {k}")
for n in re.findall(r"\d+", plain(s)):
seen += 1
if int(n) not in counts_ok: wrong += 1; odd.append(f"{n} for {k}")
for i in re.findall(r"ORD-\d+", " ".join(notices.get(k, []))): # a notice may name only its own order
seen += 1
if i != k: wrong += 1; odd.append(f"{i} in the notice for {k}")
if want[k][0] == "late": # a late notice must state the days late, and no other number of days late
said = [int(n) for n in re.findall(r"(\d+) days? late", plain(" ".join(notices.get(k, []))))]
seen += 1
if said != [want[k][2]] * max(1, len(said)): wrong += 1; odd.append(f"days late for {k}")
say(seen > 0 and wrong == 0, f"{seen - wrong} of {seen} order numbers, dates and day counts in the reasons and notices come from that order's own row and the export date" + (": not " + ", ".join(odd[:3]) if odd else ""))
stext = (root/"output/summary.md").read_text() if (root/"output/summary.md").exists() else ""
raw_rows = sum(1 for _ in csv.DictReader((root/"input/orders.csv").open()))
world = {raw_rows, len(want), len(flagged), raw_rows - len(want)} | {sum(1 for v in want.values() if v[0] == n) for n in names} | {sum(1 for v in want.values() if v[1] == s) for s in {v[1] for v in want.values()}} | set(transit.values())
seen = wrong = 0; odd = []
for ln in stext.splitlines():
here = [k for k in dict.fromkeys(re.findall(r"ORD-\d+", ln)) if k in want]
days_ok, counts_ok, typed = {today.isoformat()}, set(world), set()
for k in here:
a, b, c = facts(k); days_ok |= a; counts_ok |= b; typed |= c
for d in re.findall(iso, ln):
seen += 1
if d not in days_ok: wrong += 1; odd.append(d)
for d in re.findall(slash, ln):
seen += 1
if d not in typed: wrong += 1; odd.append(d)
for n in re.findall(r"\d+", plain(re.sub(r"^\s*\d+\.\s", "", ln))):
seen += 1
if int(n) not in counts_ok: wrong += 1; odd.append(n)
for n in names + ["total"]: # a count written right after a status name must be that status's count
c = len(want) if n == "total" else sum(1 for v in want.values() if v[0] == n)
for m in re.finditer(r"(?<![a-z_])" + n.replace("_", "[ _-]") + r"(?![a-z_])[^a-z0-9]{1,8}(\d+)(?![\d-])", plain(ln).lower()):
seen += 1
if int(m.group(1)) != c: wrong += 1; odd.append(f"{n} {m.group(1)}")
lead = re.match(r"[^a-z0-9]*(" + "|".join(n.replace("_", "[ _-]") for n in names) + r")(?![a-z_])", ln.lower())
for k in re.findall(r"ORD-\d+", ln): # every order number must be a real order
seen += 1
if k not in want: wrong += 1; odd.append(k)
if lead: # a line that opens with a status lists orders of that status, each once
ids = re.findall(r"ORD-\d+", ln)
for k in here:
seen += 1
if want[k][0] != re.sub(r"[ -]", "_", lead.group(1)) or ids.count(k) > 1: wrong += 1; odd.append(f"{k} listed as {lead.group(1)}")
say(seen > 0 and wrong == 0, f"{seen - wrong} of {seen} dates and counts in summary.md match the export: order rows for the orders a line names, recomputed counts for the rest" + (": not " + ", ".join(odd[:3]) if odd else ""))
sys.exit(0 if ok else 1)
carriers.csv: sample data written by Atris. Fingerprint d66ebfed9b02.
export_info.txt: sample data written by Atris. Fingerprint f2148f77c65c.
orders.csv: sample data written by Atris. Fingerprint 5d8c7ca30b79.
notices.md: written by the agent. Fingerprint b8a30a33f56c.
shipment_status.csv: written by the agent. Fingerprint 6e2f86e95743.
summary.md: written by the agent. Fingerprint 037eee89f238.