Decide refund requests against the policy.
Done by an agent. Checked twice.
Every refund request gets a decision and an amount under your written policy, with the totals to pay and to review.
Real files in
- orders.csv
Thirty two orders with dates, price paid, shipping paid and final sale marks. 33 lines, 4 KB. - refund_policy.md
A home goods shop's written refund policy, seven rules. 60 lines, 3 KB. - refund_requests.csv
Thirty three refund requests from two weeks, with repeats, a missing order number, a wrong order number, a request from the wrong email and a missing condition. 34 lines, 5 KB.
Sample data written by Atris. Not a real company.
Three steps
- 1.Read the policy, orders and requests
- 2.Decide each request
- 3.Write the decisions and the summary
Claude Sonnet 5.5, 1 min 3 s. No web. It never saw the check.
Checked twice
- Passed: 33 of 33 requests appear once in decisions.csv
- Passed: 33 of 33 decisions equal the decision recomputed from the policy
- Passed: 33 of 33 refund amounts equal the amount recomputed from the orders file
- Passed: 33 of 33 rule numbers equal the policy rule that settles the request when the rules are walked in order
- Passed: summary.md states the total approved to pay, 1,408.24
- Passed: summary.md states the total waiting on a manager, 943.00
- Passed: 7 of 7 requests sent to a person are named in summary.md
- Passed: 5 of 5 decision counts in summary.md equal the counts recomputed from the policy
- Passed: 31 of 31 figures in summary.md trace to the request on the same line, its order, the policy or a recomputed count or total
Second review by Claude Opus 5.5: pass.
Then we broke a copy of the output 6 ways on purpose. The check caught 6.
Total approved to pay: 1408.24 Total waiting on a manager: 943.00 ## Referred requests: what a person has to check - Q-808 (0.00): Ask the carrier whether PB-20301 was delivered on 2026-11-06; the customer says no parcel arrived. The orders file shows price 92.00 and shipping 7.95 if it turns out to be lost. - Q-811 (0.00): Find the order: no order number was given. The customer says a table runner and the orders file has a Pia Lund linen table runner (PB-20188), but policy says not to guess, so confirm the order with the customer. - Q-812 (0.00): Order PB-20417 is not in our orders; check with the customer which order they mean (do not assume another order). - Q-813 (0.00): Email dan.nakamura@mailhaven.example is not the buyer email on PB-20285 (h.nakamura@mailhaven.example); confirm who the buyer is. Hana Nakamura later sent Q-833 herself. - Q-820 (529.00): Sign off 529.00 on PB-20308 (unopened, 18 days after delivery); it is over the 400.00 limit. Nothing in the files confirms the bench is still boxed. - Q-821 (414.00): Sign off 414.00 on PB-20315 (389.00 price plus 25.00 shipping, damaged mirror); it is over the 400.00 limit. Check the damage report. - Q-823 (0.00): Ask the customer for the item condition (unopened, opened or used) on PB-20333; it is missing from the request.
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 1 of 1 on 1 December 2026. The agent took 1 min 3 s.
What the second review verified
- Day counts at the edge of a limit: Q-804 is 31 days after the 2026-10-17 delivery, so it was correctly denied. Q-805 is 30 days after 2026-10-18, so it was correctly approved at 38.00. Q-829 is 10 days after shipping on 2026-11-15, so it was correctly approved at 67.40.
- Restocking fees, recomputed: 64.99→55.24, 449.00→381.65, 31.20→26.52, 75.80→64.43 and 58.00→49.30. Q-822 comes to 381.65, which is under 400, so it is correctly approved and not sent to a manager. Q-820 (529.00) and Q-821 (389.00+25.00=414.00) are correctly referred under rule 7 with their amounts kept.
- Rule order: Q-814 and Q-826 were correctly denied under rule 3 because Q-801 and Q-802 had already been approved for the same orders. Q-813 has a different email and was referred, which does not block Q-833 (approved at 49.30). Q-827's email differs only in capital letters, so it was correctly approved. Q-812's order PB-20417 does not exist and was correctly referred instead of being matched to PB-20471.
- Totals: there are 7 approve_full, 4 approve_item, 5 approve_less_fee, 10 deny and 7 refer, which makes 33. The approve amounts add up to 567.60+263.50+577.14=1408.24, and the referred amounts add up to 529.00+414.00=943.00. Both match summary.md.
What this run does not show
- Decisions, amounts and rule numbers are recomputed from the policy. The written reasons and the notes on what a person has to check are read only by the second review.
- A rule number named in a free note under the summary can be wrong without the check noticing.
- On this run the second review worked in a folder where it could see the check file. It was not fully independent of 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
# Decide refund requests against the policy function: support for: the support manager who signs off the week's refunds goal: Every refund request has a decision and an amount that follow the written policy, with the reason stated. ## 1. Read the policy, orders and requests Read input/refund_policy.md, input/orders.csv and input/refund_requests.csv. The policy is the only authority. Apply its rules in the order it gives them. A sad story in a customer note does not change a rule and neither does the amount the customer asks for. ## 2. Decide each request Look up the order for each request, then walk the policy rules in order until one settles it. Give each request exactly one decision from the policy: `approve_full`, `approve_item`, `approve_less_fee`, `deny` or `refer`. Work out the refund from the orders file as the policy says. Count days with a calendar, not by eye. ## 3. Write the decisions and the summary Write output/decisions.csv with columns request_id,decision,refund_amount,rule,reason. One row per request, in the order of the requests file. refund_amount has two decimals. rule is the number of the policy rule that settled it. reason is one plain sentence with the dates or amounts that decided it. Write output/summary.md for the manager with: - how many requests got each decision - `Total approved to pay:` the sum of refund_amount over the three approve decisions - `Total waiting on a manager:` the sum of refund_amount over the `refer` rows - one line per `refer` request saying what a person has to check ## Done looks like - Every request appears once in decisions.csv with a decision from the policy. - Every refund amount can be traced to the price paid and shipping paid on the order. - The totals in summary.md equal the sums in decisions.csv.
input/orders.csv · 33 lines, 4 KB
order_id,order_date,ship_date,delivered_date,customer_email,customer_name,item,category,list_price,price_paid,shipping_paid,final_sale PB-20105,2026-09-04,2026-09-07,2026-09-11,r.okafor@mailhaven.example,Renata Okafor,Stoneware mixing bowl set,kitchen,58.00,58.00,6.50,no PB-20188,2026-09-28,2026-09-29,2026-10-02,pia.lund@postbox.example,Pia Lund,Linen table runner,dining,34.00,34.00,4.95,no PB-20240,2026-10-12,2026-10-13,2026-10-17,theo.marsh@mailhaven.example,Theo Marsh,Cast iron skillet 30 cm,kitchen,79.00,79.00,9.50,no PB-20244,2026-10-13,2026-10-14,2026-10-18,yusra.haddad@inboxly.example,Yusra Haddad,Bamboo drawer organiser,storage,38.00,38.00,4.95,no PB-20260,2026-09-30,2026-10-01,2026-10-05,gwen.abara@postbox.example,Gwen Abara,Enamel dutch oven 5 litre,kitchen,120.00,120.00,9.50,no PB-20275,2026-10-26,2026-10-27,2026-10-30,marcel.dubois@inboxly.example,Marcel Dubois,"Glass storage jars, set of 6",storage,64.99,64.99,0.00,no PB-20285,2026-10-29,2026-10-30,2026-11-03,h.nakamura@mailhaven.example,Hana Nakamura,Wool throw blanket,bedroom,58.00,58.00,5.50,no PB-20290,2026-11-02,2026-11-03,,silas.grant@postbox.example,Silas Grant,Ceramic planter pair,garden,56.00,56.00,6.50,no PB-20298,2026-10-23,2026-10-24,2026-10-28,odette.ferreira@inboxly.example,Odette Ferreira,Marble serving board,dining,142.50,142.50,12.00,no PB-20301,2026-11-02,2026-11-03,2026-11-06,ben.adeyemi@mailhaven.example,Ben Adeyemi,Copper kettle,kitchen,92.00,92.00,7.95,no PB-20308,2026-10-30,2026-11-02,2026-11-05,clara.voss@postbox.example,Clara Voss,Oak dining bench,dining,529.00,529.00,45.00,no PB-20311,2026-10-28,2026-10-29,2026-11-02,ines.castell@inboxly.example,Ines Castell,"Cotton duvet cover, queen",bedroom,89.00,89.00,7.95,no PB-20315,2026-11-09,2026-11-10,2026-11-13,joel.amato@mailhaven.example,Joel Amato,"Standing mirror, walnut frame",bedroom,389.00,389.00,25.00,no PB-20318,2026-11-05,2026-11-06,2026-11-10,tamsin.reid@postbox.example,Tamsin Reid,Hand blown vase,decor,90.00,45.00,8.00,yes PB-20322,2026-11-06,2026-11-09,2026-11-12,kofi.boateng@inboxly.example,Kofi Boateng,"Outdoor lantern, end of line",garden,60.00,30.00,6.50,yes PB-20327,2026-11-06,2026-11-09,2026-11-12,leila.farouk@mailhaven.example,Leila Farouk,Espresso machine,kitchen,449.00,449.00,0.00,no PB-20330,2026-11-10,2026-11-11,,dmitri.volkov@postbox.example,Dmitri Volkov,"Knife block, 7 piece",kitchen,134.00,134.00,0.00,no PB-20333,2026-11-10,2026-11-11,2026-11-14,amara.nwosu@inboxly.example,Amara Nwosu,Bath towel bundle,bathroom,72.00,72.00,5.50,no PB-20335,2026-11-11,2026-11-11,2026-11-11,piotr.zielinski@mailhaven.example,Piotr Zielinski,Pebblecroft gift card,gift_card,50.00,50.00,0.00,no PB-20338,2026-11-11,2026-11-12,2026-11-16,rosa.delgado@postbox.example,Rosa Delgado,"Salad servers, olive wood",dining,26.00,26.00,4.95,no PB-20340,2026-11-03,2026-11-09,2026-11-12,fiona.mackay@inboxly.example,Fiona Mackay,Engraved chopping board,personalised,48.00,48.00,5.50,no PB-20341,2026-11-04,2026-11-05,2026-11-09,arjun.bhatt@mailhaven.example,Arjun Bhatt,Non-stick frying pan,kitchen,42.00,42.00,5.50,no PB-20346,2026-11-12,2026-11-13,2026-11-17,nell.oduya@postbox.example,Nell Oduya,Scented candle trio,decor,39.00,31.20,4.95,no PB-20350,2026-11-13,2026-11-16,2026-11-19,sven.halvorsen@inboxly.example,Sven Halvorsen,Tea towel set,kitchen,24.50,24.50,4.95,no PB-20352,2026-11-05,2026-11-11,2026-11-14,mina.rahimi@mailhaven.example,Mina Rahimi,Monogrammed bath robe,personalised,72.00,72.00,5.00,no PB-20356,2026-11-16,2026-11-17,2026-11-20,caleb.stone@postbox.example,Caleb Stone,Measuring cup set,kitchen,18.75,18.75,4.95,no PB-20360,2026-11-13,2026-11-15,,esme.thackeray@inboxly.example,Esme Thackeray,"Pillowcase pair, sateen",bedroom,67.40,67.40,0.00,no PB-20362,2026-11-16,2026-11-17,2026-11-20,lucas.moreau@mailhaven.example,Lucas Moreau,"Wall clock, brass",decor,75.80,75.80,6.50,no PB-20366,2026-11-17,2026-11-18,2026-11-21,aiko.tanabe@postbox.example,Aiko Tanabe,Stand mixer attachment kit,kitchen,112.00,112.00,0.00,no PB-20370,2026-09-21,2026-09-22,2026-09-25,wren.calloway@inboxly.example,Wren Calloway,"Clearance rug, 120 by 180",decor,210.00,105.00,15.00,yes PB-20374,2026-11-18,2026-11-19,2026-11-23,omar.siddiqui@mailhaven.example,Omar Siddiqui,"Spice rack, wall mounted",kitchen,46.00,46.00,5.50,no PB-20471,2026-11-12,2026-11-13,2026-11-17,greta.lindholm@postbox.example,Greta Lindholm,"Laundry basket, woven",storage,54.00,54.00,6.50,no
input/refund_policy.md · 60 lines, 3 KB
# Pebblecroft Home Goods refund policy Version 4, in force from 1 September 2026. Support applies these rules in the order written. The first rule that settles a request ends it, except rule 7, which is always checked last. All day counts use calendar days. "Within 30 days" means the request date is no more than 30 days after the date named. Day 30 is inside. Day 31 is outside. ## 1. The order must be found If the request has no order number, or the order number is not in our orders, the request goes to a person. Decision `refer`, refund 0.00. Do not guess the order from the customer's name or the item. ## 2. Only the buyer is refunded The email on the request must be the email on the order. Ignore capital letters. Spelling differences in the customer's name do not matter. If the emails differ, decision `refer`, refund 0.00. ## 3. One refund for each order Take requests in order of request date, then request id. If an earlier request for the same order was approved, any later request for that order is `deny`, refund 0.00. An earlier request that was denied or referred does not block a later one. ## 4. When the fault is ours These reasons mean the fault is ours: `arrived_damaged`, `wrong_item`, `never_arrived`. Sale items, final sale items, gift cards and personalised items are all covered by this rule. - `arrived_damaged` or `wrong_item`: approve when the request is within 60 days of the delivered date. Otherwise `deny`. - `never_arrived`: if the order shows a delivered date, a person must check with the carrier, so the decision is `refer`, refund 0.00. If there is no delivered date, approve when at least 10 days have passed between the ship date and the request date. If fewer than 10 days have passed, `deny` and ask the customer to wait. An approval under this rule is `approve_full`. The refund is the price paid plus the shipping paid. ## 5. When the customer changed their mind These reasons fall here: `changed_mind`, `not_as_expected`. Check in this order: 1. More than 30 days after the delivered date: `deny`. 2. The order is marked final sale, or the category is `gift_card` or `personalised`: `deny`. 3. Item condition `unopened`: `approve_item`. The refund is the price paid. Shipping is not refunded. 4. Item condition `opened`: `approve_less_fee`. The refund is the price paid less a 15% restocking fee, rounded to the nearest cent. Shipping is not refunded. 5. Item condition `used`: `deny`. 6. Item condition missing: a person must ask the customer, so the decision is `refer`, refund 0.00. ## 6. What the refund is based on Refunds are worked out from the price paid on the order, never from the list price and never from the amount the customer asks for. A denied request has a refund of 0.00. ## 7. Large refunds If the refund worked out under rule 4 or rule 5 is more than 400.00, a manager must sign it off. The decision becomes `refer` and the refund column keeps the amount that was worked out.
input/refund_requests.csv · 34 lines, 5 KB
request_id,request_date,customer_email,customer_name,order_id,reason,item_condition,amount_requested,customer_note Q-801,2026-11-16,ines.castell@inboxly.example,Ines Castell,PB-20311,changed_mind,unopened,96.95,Wrong size for our bed. Still in the wrapper. I would like the delivery charge back too. Q-802,2026-11-16,odette.ferreira@inboxly.example,Odette Ferreira,PB-20298,arrived_damaged,,154.50,The board arrived cracked right across. Photos attached. Q-803,2026-11-16,marcel.dubois@inboxly.example,Marcel Dubois,PB-20275,changed_mind,opened,64.99,Opened the box and they are smaller than I pictured. Q-804,2026-11-17,theo.marsh@mailhaven.example,Theo Marsh,PB-20240,changed_mind,unopened,79.00,Never got round to using it. Still sealed. Q-805,2026-11-17,yusra.haddad@inboxly.example,Yusra Haddad,PB-20244,not_as_expected,unopened,38.00,Colour is darker than on the site. Have not opened it. Q-806,2026-11-17,dmitri.volkov@postbox.example,Dmitri Volkov,PB-20330,never_arrived,,134.00,Tracking has not moved in days. I want my money back. Q-807,2026-11-17,silas.grant@postbox.example,Silas Grant,PB-20290,never_arrived,,62.50,Two weeks and nothing has come. Q-808,2026-11-18,ben.adeyemi@mailhaven.example,Ben Adeyemi,PB-20301,never_arrived,,99.95,Your site says delivered but there was no parcel at my door. Q-809,2026-11-18,kofi.boateng@inboxly.example,Kofi Boateng,PB-20322,changed_mind,unopened,60.00,Bought two by mistake. This one is unopened. Q-810,2026-11-18,tamsin.reid@postbox.example,Tamsin Reid,PB-20318,arrived_damaged,,90.00,Vase was in pieces when I opened the parcel. I know it was a sale item. Q-811,2026-11-18,pia.lund@postbox.example,Pia Lund,,changed_mind,unopened,34.00,I cannot find my order number. It was a table runner. Q-812,2026-11-19,greta.lindholm@postbox.example,Greta Lindholm,PB-20417,changed_mind,unopened,54.00,Basket is too big for the space. Q-813,2026-11-19,dan.nakamura@mailhaven.example,Dan Nakamura,PB-20285,changed_mind,opened,58.00,My wife ordered this blanket. It is scratchy. Please refund to my card. Q-814,2026-11-19,ines.castell@inboxly.example,Ines Castell,PB-20311,arrived_damaged,,96.95,Asking again. On second look the cover has a pulled thread. Q-815,2026-11-19,gwen.abara@postbox.example,Gwen Abara,PB-20260,wrong_item,,129.50,I ordered the 5 litre and you sent the 3 litre. Only noticed when I came to use it. Q-816,2026-11-20,r.okafor@mailhaven.example,Renata Okafor,PB-20105,arrived_damaged,,64.50,One bowl has a chip. I was away and only just unpacked them. Q-817,2026-11-20,piotr.zielinski@mailhaven.example,Piotr Zielinski,PB-20335,changed_mind,unopened,50.00,Bought the gift card for someone who has since moved abroad. Q-818,2026-11-20,fiona.mackay@inboxly.example,Fiona Mackay,PB-20340,not_as_expected,opened,48.00,The engraving is fine but the wood is paler than I hoped. Q-819,2026-11-20,mina.rahimi@mailhaven.example,Mina Rahimi,PB-20352,arrived_damaged,,77.00,The robe has a torn seam on the left sleeve. Q-820,2026-11-23,clara.voss@postbox.example,Clara Voss,PB-20308,changed_mind,unopened,574.00,Bench does not suit the room. It is still boxed. Q-821,2026-11-23,joel.amato@mailhaven.example,Joel Amato,PB-20315,arrived_damaged,,414.00,Mirror glass is shattered in one corner. Q-822,2026-11-23,leila.farouk@mailhaven.example,Leila Farouk,PB-20327,changed_mind,opened,449.00,Unboxed it and it is too tall for under my cupboards. Not used. Q-823,2026-11-23,amara.nwosu@inboxly.example,Amara Nwosu,PB-20333,changed_mind,,72.00,Do not need these any more. Q-824,2026-11-24,arjun.bhatt@mailhaven.example,Arjun Bhatt,PB-20341,changed_mind,used,42.00,Cooked with it twice and food sticks. Q-825,2026-11-24,nell.oduya@postbox.example,Nell Oduya,PB-20346,not_as_expected,opened,39.00,Scent is much stronger than described. Opened one to smell it. Q-826,2026-11-24,odette.ferreira@inboxly.example,Odette Ferreira,PB-20298,arrived_damaged,,154.50,I have not heard back about my cracked board so sending this again. Q-827,2026-11-24,Sven.Halvorsen@Inboxly.example,Sven Halvorson,PB-20350,changed_mind,unopened,24.50,Got the same set as a present. Q-828,2026-11-25,caleb.stone@postbox.example,Caleb Stone,PB-20356,wrong_item,,23.70,"Sent spoons, ordered cups." Q-829,2026-11-25,esme.thackeray@inboxly.example,Esme Thackeray,PB-20360,never_arrived,,67.40,Nothing has arrived and tracking stopped on the 16th. Q-830,2026-11-25,lucas.moreau@mailhaven.example,Lucas Moreau,PB-20362,changed_mind,opened,82.30,"Took it out of the box, it is louder than I can live with." Q-831,2026-11-26,aiko.tanabe@postbox.example,Aiko Tanabe,PB-20366,not_as_expected,unopened,112.00,It does not fit my model of mixer. Box is sealed. Q-832,2026-11-26,wren.calloway@inboxly.example,Wren Calloway,PB-20370,arrived_damaged,,120.00,Unrolled the rug at last and there is a tear along one edge. Q-833,2026-11-27,h.nakamura@mailhaven.example,Hana Nakamura,PB-20285,changed_mind,opened,58.00,My husband wrote in last week about this blanket. I am the one who bought it.
output/decisions.csv · written by the agent, 34 lines
request_id,decision,refund_amount,rule,reason Q-801,approve_item,89.00,5,"Unopened and 14 days after delivery on 2026-11-02; refund is the price paid 89.00, no shipping." Q-802,approve_full,154.50,4,Fault is ours and the request is 19 days after delivery on 2026-10-28 (limit 60); refund is price 142.50 plus shipping 12.00. Q-803,approve_less_fee,55.24,5,"Opened and 17 days after delivery on 2026-10-30; price paid 64.99 less 15% fee, no shipping." Q-804,deny,0.00,5,"The request is 31 days after delivery on 2026-10-17, outside the 30-day limit." Q-805,approve_item,38.00,5,"Unopened and 30 days after delivery on 2026-10-18; refund is the price paid 38.00, no shipping." Q-806,deny,0.00,4,No delivered date and only 6 days since shipping on 2026-11-11 (10 needed); ask the customer to wait. Q-807,approve_full,62.50,4,No delivered date and 14 days since shipping on 2026-11-03 (10 needed); refund is price 56.00 plus shipping 6.50. Q-808,refer,0.00,4,"The order shows delivered on 2026-11-06, so a person must check with the carrier." Q-809,deny,0.00,5,"Change-of-mind refunds are not allowed for this order (final sale: yes, category: garden)." Q-810,approve_full,53.00,4,Fault is ours and the request is 8 days after delivery on 2026-11-10 (limit 60); refund is price 45.00 plus shipping 8.00. Q-811,refer,0.00,1,"The request has no order number, so a person must find the order." Q-812,refer,0.00,1,"Order PB-20417 is not in our orders, so a person must check it." Q-813,refer,0.00,2,Request email dan.nakamura@mailhaven.example differs from the order email h.nakamura@mailhaven.example. Q-814,deny,0.00,3,"An earlier request for PB-20311 was already approved, so only one refund is allowed." Q-815,approve_full,129.50,4,Fault is ours and the request is 45 days after delivery on 2026-10-05 (limit 60); refund is price 120.00 plus shipping 9.50. Q-816,deny,0.00,4,"Fault is ours but the request is 70 days after delivery on 2026-09-11, outside the 60-day limit." Q-817,deny,0.00,5,"Change-of-mind refunds are not allowed for this order (final sale: no, category: gift_card)." Q-818,deny,0.00,5,"Change-of-mind refunds are not allowed for this order (final sale: no, category: personalised)." Q-819,approve_full,77.00,4,Fault is ours and the request is 6 days after delivery on 2026-11-14 (limit 60); refund is price 72.00 plus shipping 5.00. Q-820,refer,529.00,7,"Worked-out refund 529.00 is over 400.00 so a manager must sign off. (Unopened and 18 days after delivery on 2026-11-05; refund is the price paid 529.00, no shipping.)" Q-821,refer,414.00,7,Worked-out refund 414.00 is over 400.00 so a manager must sign off. (Fault is ours and the request is 10 days after delivery on 2026-11-13 (limit 60); refund is price 389.00 plus shipping 25.00.) Q-822,approve_less_fee,381.65,5,"Opened and 11 days after delivery on 2026-11-12; price paid 449.00 less 15% fee, no shipping." Q-823,refer,0.00,5,"Item condition is missing, so a person must ask the customer." Q-824,deny,0.00,5,"The item is used, so a change-of-mind refund is not allowed." Q-825,approve_less_fee,26.52,5,"Opened and 7 days after delivery on 2026-11-17; price paid 31.20 less 15% fee, no shipping." Q-826,deny,0.00,3,"An earlier request for PB-20298 was already approved, so only one refund is allowed." Q-827,approve_item,24.50,5,"Unopened and 5 days after delivery on 2026-11-19; refund is the price paid 24.50, no shipping." Q-828,approve_full,23.70,4,Fault is ours and the request is 5 days after delivery on 2026-11-20 (limit 60); refund is price 18.75 plus shipping 4.95. Q-829,approve_full,67.40,4,No delivered date and 10 days since shipping on 2026-11-15 (10 needed); refund is price 67.40 plus shipping 0.00. Q-830,approve_less_fee,64.43,5,"Opened and 5 days after delivery on 2026-11-20; price paid 75.80 less 15% fee, no shipping." Q-831,approve_item,112.00,5,"Unopened and 5 days after delivery on 2026-11-21; refund is the price paid 112.00, no shipping." Q-832,deny,0.00,4,"Fault is ours but the request is 62 days after delivery on 2026-09-25, outside the 60-day limit." Q-833,approve_less_fee,49.30,5,"Opened and 24 days after delivery on 2026-11-03; price paid 58.00 less 15% fee, no shipping."
output/summary.md · written by the agent, 28 lines
# Refund decisions summary 33 requests decided against refund policy version 4. ## Decisions - approve_full: 7 - approve_item: 4 - approve_less_fee: 5 - deny: 10 - refer: 7 Total approved to pay: 1408.24 Total waiting on a manager: 943.00 ## Referred requests: what a person has to check - Q-808 (0.00): Ask the carrier whether PB-20301 was delivered on 2026-11-06; the customer says no parcel arrived. The orders file shows price 92.00 and shipping 7.95 if it turns out to be lost. - Q-811 (0.00): Find the order: no order number was given. The customer says a table runner and the orders file has a Pia Lund linen table runner (PB-20188), but policy says not to guess, so confirm the order with the customer. - Q-812 (0.00): Order PB-20417 is not in our orders; check with the customer which order they mean (do not assume another order). - Q-813 (0.00): Email dan.nakamura@mailhaven.example is not the buyer email on PB-20285 (h.nakamura@mailhaven.example); confirm who the buyer is. Hana Nakamura later sent Q-833 herself. - Q-820 (529.00): Sign off 529.00 on PB-20308 (unopened, 18 days after delivery); it is over the 400.00 limit. Nothing in the files confirms the bench is still boxed. - Q-821 (414.00): Sign off 414.00 on PB-20315 (389.00 price plus 25.00 shipping, damaged mirror); it is over the 400.00 limit. Check the damage report. - Q-823 (0.00): Ask the customer for the item condition (unopened, opened or used) on PB-20333; it is missing from the request. ## Notes - Q-801 asked for 96.95, but a change of mind pays the price paid only (89.00); shipping is not refunded. - Q-814 and Q-826 are denied under rule 3 because Q-801 and Q-802 were approved first for the same orders. - Q-833 is approved although Q-813 was referred, because a referred request does not block a later one. - Q-822 is 381.65 after the fee, so it is under the 400.00 manager limit.
check.py · the check, written before the run
"""Recomputes every refund decision and amount from the policy, the orders and the requests."""
import csv, re, sys
from datetime import date
from decimal import Decimal, ROUND_HALF_UP
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):
return date.fromisoformat(s.strip())
def money(x):
return Decimal(x).quantize(Decimal("0.01"), rounding=ROUND_HALF_UP)
orders = {r["order_id"].strip(): r for r in csv.DictReader((root/"input/orders.csv").open())}
reqs = list(csv.DictReader((root/"input/refund_requests.csv").open()))
want, approved, traceable = {}, set(), {}
for r in sorted(reqs, key=lambda r: (r["request_date"], r["request_id"])):
o = orders.get(r["order_id"].strip())
when, zero = day(r["request_date"]), Decimal("0.00")
if not r["order_id"].strip() or not o:
res = ("refer", zero, 1)
elif r["customer_email"].strip().lower() != o["customer_email"].strip().lower():
res = ("refer", zero, 2)
elif o["order_id"] in approved:
res = ("deny", zero, 3)
else:
paid, ship = Decimal(o["price_paid"]), Decimal(o["shipping_paid"])
reason, cond = r["reason"].strip(), r["item_condition"].strip()
if reason in ("arrived_damaged", "wrong_item"):
res = ("approve_full", paid + ship, 4) if (when - day(o["delivered_date"])).days <= 60 else ("deny", zero, 4)
elif reason == "never_arrived":
if o["delivered_date"].strip(): res = ("refer", zero, 4)
elif (when - day(o["ship_date"])).days >= 10: res = ("approve_full", paid + ship, 4)
else: res = ("deny", zero, 4)
else:
if (when - day(o["delivered_date"])).days > 30: res = ("deny", zero, 5)
elif o["final_sale"].strip() == "yes" or o["category"].strip() in ("gift_card", "personalised"): res = ("deny", zero, 5)
elif cond == "unopened": res = ("approve_item", paid, 5)
elif cond == "opened": res = ("approve_less_fee", money(paid * Decimal("0.85")), 5)
elif cond == "used": res = ("deny", zero, 5)
else: res = ("refer", zero, 5)
if res[1] > Decimal("400.00"):
res = ("refer", res[1], 7)
if res[0].startswith("approve"):
approved.add(o["order_id"])
want[r["request_id"]] = (res[0], money(res[1]), res[2])
# every figure a line about this request may fairly restate: its own records, the order's and what follows from them
mine = {r["request_date"].strip(), r["amount_requested"].strip()}
mine.add(f"{money(res[1])}")
if o:
paid, ship = Decimal(o["price_paid"]), Decimal(o["shipping_paid"])
for c in ("order_date", "ship_date", "delivered_date", "list_price", "price_paid", "shipping_paid"):
mine.add(o[c].strip())
mine |= {f"{money(paid + ship)}", f"{money(paid * Decimal('0.85'))}", f"{money(paid * Decimal('0.15'))}"}
for c in ("order_date", "ship_date", "delivered_date"):
if o[c].strip(): mine.add(str((when - day(o[c])).days))
traceable[r["request_id"]] = mine
path = root/"output/decisions.csv"
if not path.exists():
say(False, "output/decisions.csv was not written"); sys.exit(1)
rows = list(csv.DictReader(path.open()))
got = {(r.get("request_id") or "").strip(): r for r in rows}
def amount(k):
try: return money((got[k].get("refund_amount") or "").replace(",", "").replace("$", "").strip())
except Exception: return None
n = len(want)
once = sum(1 for k in want if sum(1 for r in rows if (r.get("request_id") or "").strip() == k) == 1)
say(once == n and len(rows) == n, f"{once} of {n} requests appear once in decisions.csv")
right = sum(1 for k, w in want.items() if (got.get(k, {}).get("decision") or "").strip().lower() == w[0])
say(right == n, f"{right} of {n} decisions equal the decision recomputed from the policy")
right = sum(1 for k, w in want.items() if k in got and amount(k) == w[1])
say(right == n, f"{right} of {n} refund amounts equal the amount recomputed from the orders file")
right = sum(1 for k, w in want.items() if re.sub(r"\D", "", got.get(k, {}).get("rule") or "") == str(w[2]))
say(right == n, f"{right} of {n} rule numbers equal the policy rule that settles the request when the rules are walked in order")
pay = sum(w[1] for w in want.values() if w[0].startswith("approve"))
wait = sum(w[1] for w in want.values() if w[0] == "refer")
summary = (root/"output/summary.md").read_text() if (root/"output/summary.md").exists() else ""
def stated(label):
m = re.search(label + r"[^\n]*?([\d,]+\.\d{2})", summary, re.I)
return money(m.group(1).replace(",", "")) if m else None
say(stated("Total approved to pay") == pay, f"summary.md states the total approved to pay, {pay:,.2f}")
say(stated("Total waiting on a manager") == wait, f"summary.md states the total waiting on a manager, {wait:,.2f}")
refer = [k for k, w in want.items() if w[0] == "refer"]
named = sum(1 for k in refer if k in summary)
say(named == len(refer), f"{named} of {len(refer)} requests sent to a person are named in summary.md")
from collections import Counter
tally = Counter(w[0] for w in want.values())
good = sum(1 for d in tally if (m := re.search(r"^[\s\-*`|]*" + d + r"\b[`*\s|:]*?(\d+)\b", summary, re.M)) and int(m.group(1)) == tally[d])
say(good == len(tally), f"{good} of {len(tally)} decision counts in summary.md equal the counts recomputed from the policy")
policy = set(re.findall(r"\d+(?:\.\d+)?", (root/"input/refund_policy.md").read_text()))
general = policy | {str(n), f"{pay}", f"{wait}"} | {str(c) for c in tally.values()}
figures = traced = 0
for line in summary.splitlines():
named = [k for k in re.findall(r"Q-\d+", line) if k in traceable]
allowed = set().union(*(traceable[k] for k in named)) | policy if named else general
bare = re.sub(r"\b(?:Q|PB)-\d+|[\w.]+@[\w.]+", " ", line).replace(",", "")
for f in re.findall(r"\d{4}-\d{2}-\d{2}|\d+(?:\.\d+)?", bare):
figures += 1; traced += f in allowed
version = re.search(r"^Version (\d+)", (root/"input/refund_policy.md").read_text(), re.M).group(1)
for v in re.findall(r"version (\d+)", summary, re.I):
traced -= v != version
say(figures > 0 and traced == figures, f"{traced} of {figures} figures in summary.md trace to the request on the same line, its order, the policy or a recomputed count or total")
sys.exit(0 if ok else 1)
orders.csv: sample data written by Atris. Fingerprint 5e12675eea0e.
refund_policy.md: sample data written by Atris. Fingerprint cc52a71e5e2d.
refund_requests.csv: sample data written by Atris. Fingerprint 9fcc79834291.
decisions.csv: written by the agent. Fingerprint e3cf0b19bdcb.
summary.md: written by the agent. Fingerprint 56a9d8b25b4f.