Atris

Check expense reports against the expense policy.
Done by an agent. Checked twice.

Every expense line is approved, cut to the limit or refused, with the policy section and the sums behind each decision.

Have Atris do this for you›

1

Real files in

  • expense_lines.csv
    Forty-six expense lines from seven reports, with missing receipts, late claims, a repeat claim and over-limit meals planted in them. 47 lines, 5 KB.
  • expense_policy.md
    A ten-section travel and expense policy for an invented design firm. 63 lines, 2 KB.

Sample data written by Atris. Not a real company.

2

Three steps

  1. 1.Read the policy and the expense lines
  2. 2.Decide each line
  3. 3.Write the result

Claude Sonnet 5.5, 1 min 4 s. No web. It never saw the check.

3

Checked twice

  • ✓Passed: 46 of 46 expense lines appear once in expense_review.csv and 46 carry the report and the amount claimed on the report
  • ✓Passed: 46 of 46 statuses equal the status worked out from the policy text
  • ✓Passed: 46 of 46 approved amounts equal the amount the policy allows
  • ✓Passed: 23 of 23 lines that are not ok name the policy section that covers their status
  • ✓Passed: summary.md states the total claimed of 12,512.98 and the total approved of 8,752.29
  • ✓Passed: 7 of 7 reports are on one line of summary.md with the employee and the claimed and approved totals recomputed from the lines
  • ✓Passed: 23 of 23 lines that are not ok are named in summary.md with their status
  • ✓Passed: 70 of 70 figures in summary.md and 109 of 109 in the reasons equal a figure of the line or report they sit beside, a policy figure or a recomputed 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.

What it wrote. Lines 1 to 14 of expense_review.csv, copied from the file.
line_id,report_id,status,claimed,approved,reason
E-001,R-301,ok,412.60,412.60,"Section 6: economy class, no approval needed."
E-002,R-301,over_limit,520.00,480.00,Section 5: lodging of 520.00 for 2 night(s) is over the limit of 240.00 x 2 = 480.00; paid at 480.00.
E-003,R-301,ok,58.40,58.40,Section 4: 58.40 is within 65.00 x 1 = 65.00.
E-004,R-301,over_limit,212.00,195.00,Section 4: meal of 212.00 for 3 person(s) is over the limit of 65.00 x 3 = 195.00; paid at 195.00.
E-005,R-301,ok,24.99,24.99,Section 2: 24.99 is under 25.00 so no receipt is needed; no other rule applies.
E-006,R-301,no_receipt,25.00,0.00,Section 2: an expense of 25.00 or more needs an itemized receipt and this 25.00 line has none.
E-007,R-301,ok,38.00,38.00,"Sections 2, 3 and 8: receipt present, submitted within 45 days, 38.00 is not over 500.00 and category parking is not banned."
E-008,R-302,ok,60.20,60.20,"Section 7: 86 miles x 0.70 = 60.20, matches the claim."
E-009,R-302,late,90.00,0.00,"Section 3: submitted 46 days after the expense date, past the 45-day limit (day 46 or later is not paid)."
E-010,R-302,wrong_mileage,104.40,99.40,"Section 7: 142 miles x 0.70 = 99.40, but 104.40 was claimed; paid at 99.40."
E-011,R-302,ok,130.00,130.00,Section 4: 130.00 is within 65.00 x 2 = 130.00.
E-012,R-302,ok,46.15,46.15,"Sections 2, 3 and 8: receipt present, submitted within 45 days, 46.15 is not over 500.00 and category supplies is not banned."
E-013,R-302,not_allowed,75.00,0.00,Section 9: category fine is one the company never pays.

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 2 of 2 on 1 December 2026. The agent took 1 min 4 s. Run 1 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

  • All 46 input lines appear once in line_id order. Totals recomputed from the CSV match summary.md: 12512.98 claimed and 8752.29 approved. All seven per-report figures also match, e.g. R-303 3332.70 / 873.20.
  • Deadline day counts recomputed: E-008 (Oct 4 to Nov 18) and E-045 (Oct 16 to Nov 30) are 45 days, so they are on time. E-009 and E-046 are 46 days and E-028 (Sep 28 to Nov 27) is 60 days, so all three are correctly late under Section 3.
  • Mileage at 0.70 per mile: 142 x 0.70 = 99.40, so E-010 (claimed 104.40) is wrong_mileage and paid 99.40. 86 x 0.70 = 60.20, 210 x 0.70 = 147.00 and 64 x 0.70 = 44.80 all match their claims.
  • Edge cases follow the policy and the check order: E-006 at 25.00 with no receipt is no_receipt; E-042 at 26.00 with no receipt is no_receipt, which comes before over_limit; E-033 at 500.00 is not over 500.00, so ok; E-035 duplicates E-003 even though the merchant is spelled Café/Cafe; E-016 has no attendee count, so the 65.00 limit for one person applies; E-022 at 388.00 is within 6 x 65.00 = 390.00.

What this run does not show

  • The policy and the expense lines were written for this run with clear limits, while a real policy leaves cases that need a manager's call.
  • The order the policy rules apply in was written into the check by hand before the run.
  • The check compares the figures in each reason and the section it names, so the wording is judged only by the second review.

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
# Check expense reports against the expense policy

function: finance
for: the finance person who approves staff expense reports
goal: Every expense line is approved, cut to the policy limit or refused with the policy section that says why.

## 1. Read the policy and the expense lines
Read input/expense_policy.md from top to bottom, then input/expense_lines.csv. Take every limit, rate,
deadline and banned category from the policy text. Do not use limits from memory or from another
company's policy.

## 2. Decide each line
Give every line exactly one status. Check in this order and use the first that applies:
- `missing_info` the line lacks something the policy says every line must have.
- `duplicate` the policy's own test says an earlier line (lower line_id) is the same expense. The earlier line is judged on its own.
- `not_allowed` the category is one the company never pays.
- `late` submitted after the policy deadline.
- `no_receipt` the policy requires a receipt and the receipt column is not `yes`.
- `not_economy` air travel with no approval number in a class the policy does not pay without one.
- `needs_approval` a large purchase with no approval number.
- `over_limit` a meal or lodging line above the policy limit.
- `wrong_mileage` a mileage amount that differs from miles times the policy rate.
- `ok` none of the above.
The approved amount is the claimed amount for `ok`, the policy limit for `over_limit` and miles times
the rate for `wrong_mileage`. It is 0.00 for every other status. A blank amount counts as 0.00 claimed.

## 3. Write the result
Write output/expense_review.csv with columns line_id,report_id,status,claimed,approved,reason. One
row per expense line, in line_id order, money with two decimals. reason is one plain sentence that
names the policy section number and the figures behind the decision.
Write output/summary.md for the approver: the total claimed and the total approved across all
reports, then one line per report with report_id, employee, claimed and approved, then one line for
every expense line that is not `ok` with its line_id, status and reason.

## Done looks like
- Every expense line appears once in expense_review.csv with one status.
- The totals in summary.md equal the sums of the claimed and approved columns.
- Every line that is not `ok` names the policy section behind it.
input/expense_lines.csv · 47 lines, 5 KB
line_id,report_id,employee,submitted_date,expense_date,category,merchant,amount,attendees,nights,miles,travel_class,receipt,approval_no,memo
E-001,R-301,Imogen Hartley,2026-11-20,2026-11-03,airfare,Skyline Air,412.60,,,,economy,yes,,Flight to client workshop
E-002,R-301,Imogen Hartley,2026-11-20,2026-11-03,lodging,Harbor Gate Hotel,520.00,,2,,,yes,,Two nights for workshop
E-003,R-301,Imogen Hartley,2026-11-20,2026-11-03,meal,Blue Heron Cafe,58.40,1,,,,yes,,Dinner on arrival
E-004,R-301,Imogen Hartley,2026-11-20,2026-11-04,meal,Mason & Rye,212.00,3,,,,yes,,Dinner with two client staff
E-005,R-301,Imogen Hartley,2026-11-20,2026-11-04,taxi,City Cab,24.99,,,,,no,,Hotel to client office
E-006,R-301,Imogen Hartley,2026-11-20,2026-11-05,taxi,City Cab,25.00,,,,,no,,Client office to airport
E-007,R-301,Imogen Hartley,2026-11-20,2026-11-05,parking,Dockside Parking,38.00,,,,,yes,,Airport parking
E-008,R-302,Rafael Quintero,2026-11-18,2026-10-04,mileage,,60.20,,,86,,,,Site visit Ashgrove
E-009,R-302,Rafael Quintero,2026-11-18,2026-10-03,mileage,,90.00,,,120,,,,Site visit Tiverton
E-010,R-302,Rafael Quintero,2026-11-18,2026-11-02,mileage,,104.40,,,142,,,,Site visit Wexcombe
E-011,R-302,Rafael Quintero,2026-11-18,2026-11-09,meal,Tin Lantern,130.00,2,,,,yes,,Lunch with supplier
E-012,R-302,Rafael Quintero,2026-11-18,2026-11-09,supplies,Dovecote Stationery,46.15,,,,,yes,,Sample boards
E-013,R-302,Rafael Quintero,2026-11-18,2026-11-10,fine,City parking office,75.00,,,,,yes,,Parking ticket outside client site
E-014,R-303,Priya Nandakumar,2026-11-24,2026-11-11,airfare,Skyline Air,1840.00,,,,business,yes,,Flight to design forum
E-015,R-303,Priya Nandakumar,2026-11-24,2026-11-11,lodging,The Wexcombe,705.00,,3,,,yes,,Three nights for forum
E-016,R-303,Priya Nandakumar,2026-11-24,2026-11-12,meal,Saffron Yard,96.50,,,,,yes,,Dinner
E-017,R-303,Priya Nandakumar,2026-11-24,2026-11-12,gift,Fernhill Florist,62.00,,,,,yes,,Thank you flowers for client
E-018,R-303,Priya Nandakumar,2026-11-24,2026-11-13,software,Glyphworks,588.00,,,,,yes,,Annual plan for type library
E-019,R-303,Priya Nandakumar,2026-11-24,2026-11-13,meal,Saffron Yard,41.20,1,,,,yes,,Lunch
E-020,R-304,Tobias Lindgren,2026-11-25,2026-11-16,airfare,Northwind Airways,2210.00,,,,business,yes,AP-5521,Overnight flight to pitch
E-021,R-304,Tobias Lindgren,2026-11-25,2026-11-16,lodging,Kestrel Court Hotel,1010.00,,4,,,yes,,Four nights for pitch
E-022,R-304,Tobias Lindgren,2026-11-25,2026-11-17,meal,Oyster & Vine,388.00,6,,,,yes,,Dinner with pitch team and client
E-023,R-304,Tobias Lindgren,2026-11-25,2026-11-17,alcohol,Oyster & Vine,64.00,,,,,yes,,Bar tab after dinner
E-024,R-304,Tobias Lindgren,2026-11-25,2026-11-18,conference,Northern Design Forum,895.00,,,,,yes,AP-5530,Forum pass
E-025,R-304,Tobias Lindgren,2026-11-25,2026-11-18,taxi,Metro Cars,31.50,,,,,yes,,Hotel to forum
E-026,R-304,Tobias Lindgren,2026-11-25,2026-11-18,taxi,Metro Cars Ltd,31.50,,,,,yes,,Taxi to forum
E-027,R-304,Tobias Lindgren,2026-11-25,2026-11-19,meal,Corner Bakehouse,18.75,1,,,,no,,Breakfast
E-028,R-305,Dele Okafor,2026-11-27,2026-09-28,lodging,Pinewater Inn,189.00,,1,,,yes,,Night before site survey
E-029,R-305,Dele Okafor,2026-11-27,2026-11-05,meal,Tin Lantern,72.00,1,,,,yes,,Dinner
E-030,R-305,Dele Okafor,2026-11-27,2026-11-05,mileage,,147.00,,,210,,,,Site survey round trip
E-031,R-305,Dele Okafor,2026-11-27,2026-11-06,equipment,Castlereach Telecom,129.99,,,,,no,,Headset for site calls
E-032,R-305,Dele Okafor,2026-11-27,,meal,Station Grill,22.10,1,,,,yes,,Lunch
E-033,R-305,Dele Okafor,2026-11-27,2026-11-20,training,Glyphworks,500.00,,,,,yes,,Lettering workshop
E-034,R-305,Dele Okafor,2026-11-27,2026-11-21,personal,Harbor Gate Hotel,85.00,,,,,yes,,Spa
E-035,R-306,Imogen Hartley,2026-11-27,2026-11-03,meal,Blue Heron Café,58.40,1,,,,yes,,Dinner
E-036,R-306,Imogen Hartley,2026-11-27,2026-11-23,airfare,Skyline Air,366.20,,,,premium economy,yes,,Flight to print check
E-037,R-306,Imogen Hartley,2026-11-27,2026-11-23,lodging,Marlow House,240.00,,1,,,yes,,One night
E-038,R-306,Imogen Hartley,2026-11-27,2026-11-23,meal,Marlow House,64.00,1,,,,yes,,Dinner
E-039,R-306,Imogen Hartley,2026-11-27,2026-11-24,taxi,City Cab,,,,,,yes,,Printer to airport
E-040,R-306,Imogen Hartley,2026-11-27,2026-11-24,supplies,Quillfeather Print,540.00,,,,,yes,AP-5544,Proof prints for client
E-041,R-307,Mei Castellanos,2026-11-30,2026-11-25,mileage,,44.80,,,64,,,,Client visit
E-042,R-307,Mei Castellanos,2026-11-30,2026-11-25,meal,Tin Lantern,26.00,1,,,,no,,Lunch
E-043,R-307,Mei Castellanos,2026-11-30,2026-11-26,parking,Dockside Parking,12.00,,,,,no,,Street meter
E-044,R-307,Mei Castellanos,2026-11-30,2026-11-26,meal,Mason & Rye,131.00,2,,,,yes,,Lunch with client
E-045,R-307,Mei Castellanos,2026-11-30,2026-10-16,supplies,Dovecote Stationery,88.30,,,,,yes,,Mount board
E-046,R-307,Mei Castellanos,2026-11-30,2026-10-15,supplies,Dovecote Stationery,19.00,,,,,yes,,Tape and blades
input/expense_policy.md · 63 lines, 2 KB
# Travel and expense policy

Larkfield Design Group. Version 4, in force from 1 January 2026. Owner: Finance.

This policy says what the company pays back when staff spend their own money on company business.
Finance checks every line of every expense report against it before payment.

## 1. What a claim must contain

Every expense line needs an expense date and an amount. A line missing either one cannot be paid
until the employee fills it in.

## 2. Receipts

An itemized receipt is required for every expense of 25.00 or more. An expense under 25.00 can be
paid without one. Mileage claims never need a receipt because the trip log is the record.
A line that needs a receipt and has none is not paid.

## 3. Deadline

Submit expenses within 45 days of the expense date. Count the days from the expense date to the date
the report was submitted. An expense submitted on day 46 or later is not paid.

## 4. Meals

The company pays up to 65.00 per person for a meal, tip included. Multiply the limit by the number of
people at the table shown on the claim. If no number of people is given, count one person.
The amount above the limit is not paid back.

## 5. Lodging

The company pays up to 240.00 per night. Multiply the limit by the number of nights.
The amount above the limit is not paid back.

## 6. Air travel

Book economy class. Any other class (premium economy, business, first) is paid only when a director
approved it before booking and the approval number is on the claim. Without an approval number the
fare is not paid.

## 7. Driving your own car

Mileage is paid at 0.70 per mile. Finance pays miles times the rate, rounded to the cent, whatever
amount was typed on the claim.

## 8. Large purchases

Any single expense over 500.00 needs an approval number on the claim. Air travel and lodging are
exempt from this rule because sections 5 and 6 already cover them. Without an approval number the
expense is not paid.

## 9. What the company never pays

- Alcohol bought on its own (category `alcohol`).
- Fines and parking tickets (category `fine`).
- Personal items and services such as spa visits, laundry at home or gifts for family (category `personal`).

## 10. Claiming the same expense twice

An expense is paid once. If the same employee claims the same expense again, in the same report or a
later one, the second claim is not paid. Finance treats two lines as the same expense when the
employee, the expense date, the category and the amount are all the same, even if the merchant name
is written differently.
output/expense_review.csv · written by the agent, 47 lines
line_id,report_id,status,claimed,approved,reason
E-001,R-301,ok,412.60,412.60,"Section 6: economy class, no approval needed."
E-002,R-301,over_limit,520.00,480.00,Section 5: lodging of 520.00 for 2 night(s) is over the limit of 240.00 x 2 = 480.00; paid at 480.00.
E-003,R-301,ok,58.40,58.40,Section 4: 58.40 is within 65.00 x 1 = 65.00.
E-004,R-301,over_limit,212.00,195.00,Section 4: meal of 212.00 for 3 person(s) is over the limit of 65.00 x 3 = 195.00; paid at 195.00.
E-005,R-301,ok,24.99,24.99,Section 2: 24.99 is under 25.00 so no receipt is needed; no other rule applies.
E-006,R-301,no_receipt,25.00,0.00,Section 2: an expense of 25.00 or more needs an itemized receipt and this 25.00 line has none.
E-007,R-301,ok,38.00,38.00,"Sections 2, 3 and 8: receipt present, submitted within 45 days, 38.00 is not over 500.00 and category parking is not banned."
E-008,R-302,ok,60.20,60.20,"Section 7: 86 miles x 0.70 = 60.20, matches the claim."
E-009,R-302,late,90.00,0.00,"Section 3: submitted 46 days after the expense date, past the 45-day limit (day 46 or later is not paid)."
E-010,R-302,wrong_mileage,104.40,99.40,"Section 7: 142 miles x 0.70 = 99.40, but 104.40 was claimed; paid at 99.40."
E-011,R-302,ok,130.00,130.00,Section 4: 130.00 is within 65.00 x 2 = 130.00.
E-012,R-302,ok,46.15,46.15,"Sections 2, 3 and 8: receipt present, submitted within 45 days, 46.15 is not over 500.00 and category supplies is not banned."
E-013,R-302,not_allowed,75.00,0.00,Section 9: category fine is one the company never pays.
E-014,R-303,not_economy,1840.00,0.00,Section 6: business class is paid only with a director approval number and none is on the claim.
E-015,R-303,ok,705.00,705.00,Section 5: 705.00 is within 240.00 x 3 night(s) = 720.00.
E-016,R-303,over_limit,96.50,65.00,"Section 4: meal of 96.50 for 1 person(s) is over the limit of 65.00 x 1 = 65.00 (no attendee count given, so one person); paid at 65.00."
E-017,R-303,ok,62.00,62.00,"Sections 2, 3 and 8: receipt present, submitted within 45 days, 62.00 is not over 500.00 and category gift is not banned. Category gift is not on the Section 9 never-pay list (only gifts for family under personal)."
E-018,R-303,needs_approval,588.00,0.00,Section 8: a single expense of 588.00 is over 500.00 and has no approval number.
E-019,R-303,ok,41.20,41.20,Section 4: 41.20 is within 65.00 x 1 = 65.00.
E-020,R-304,ok,2210.00,2210.00,Section 6: business class with approval number AP-5521.
E-021,R-304,over_limit,1010.00,960.00,Section 5: lodging of 1010.00 for 4 night(s) is over the limit of 240.00 x 4 = 960.00; paid at 960.00.
E-022,R-304,ok,388.00,388.00,Section 4: 388.00 is within 65.00 x 6 = 390.00.
E-023,R-304,not_allowed,64.00,0.00,Section 9: category alcohol is one the company never pays.
E-024,R-304,ok,895.00,895.00,Section 8: 895.00 is over 500.00 and approval number AP-5530 is on the claim.
E-025,R-304,ok,31.50,31.50,"Sections 2, 3 and 8: receipt present, submitted within 45 days, 31.50 is not over 500.00 and category taxi is not banned."
E-026,R-304,duplicate,31.50,0.00,"Section 10: same employee, expense date 2026-11-18, category taxi and amount 31.50 as earlier line E-025, so this second claim is not paid."
E-027,R-304,ok,18.75,18.75,Section 4: 18.75 is within 65.00 x 1 = 65.00. Under 25.00 so no receipt is needed (Section 2).
E-028,R-305,late,189.00,0.00,"Section 3: submitted 60 days after the expense date, past the 45-day limit (day 46 or later is not paid)."
E-029,R-305,over_limit,72.00,65.00,Section 4: meal of 72.00 for 1 person(s) is over the limit of 65.00 x 1 = 65.00; paid at 65.00.
E-030,R-305,ok,147.00,147.00,"Section 7: 210 miles x 0.70 = 147.00, matches the claim."
E-031,R-305,no_receipt,129.99,0.00,Section 2: an expense of 25.00 or more needs an itemized receipt and this 129.99 line has none.
E-032,R-305,missing_info,22.10,0.00,"Section 1: every line needs an expense date and an amount, and this line has no expense date, so it cannot be paid until filled in."
E-033,R-305,ok,500.00,500.00,"Sections 2, 3 and 8: receipt present, submitted within 45 days, 500.00 is not over 500.00 and category training is not banned."
E-034,R-305,not_allowed,85.00,0.00,Section 9: category personal is one the company never pays.
E-035,R-306,duplicate,58.40,0.00,"Section 10: same employee, expense date 2026-11-03, category meal and amount 58.40 as earlier line E-003, so this second claim is not paid."
E-036,R-306,not_economy,366.20,0.00,Section 6: premium economy class is paid only with a director approval number and none is on the claim.
E-037,R-306,ok,240.00,240.00,Section 5: 240.00 is within 240.00 x 1 night(s) = 240.00.
E-038,R-306,ok,64.00,64.00,Section 4: 64.00 is within 65.00 x 1 = 65.00.
E-039,R-306,missing_info,0.00,0.00,"Section 1: every line needs an expense date and an amount, and this line has no amount, so it cannot be paid until filled in."
E-040,R-306,ok,540.00,540.00,Section 8: 540.00 is over 500.00 and approval number AP-5544 is on the claim.
E-041,R-307,ok,44.80,44.80,"Section 7: 64 miles x 0.70 = 44.80, matches the claim."
E-042,R-307,no_receipt,26.00,0.00,Section 2: an expense of 25.00 or more needs an itemized receipt and this 26.00 line has none.
E-043,R-307,ok,12.00,12.00,Section 2: 12.00 is under 25.00 so no receipt is needed; no other rule applies.
E-044,R-307,over_limit,131.00,130.00,Section 4: meal of 131.00 for 2 person(s) is over the limit of 65.00 x 2 = 130.00; paid at 130.00.
E-045,R-307,ok,88.30,88.30,"Sections 2, 3 and 8: receipt present, submitted within 45 days, 88.30 is not over 500.00 and category supplies is not banned."
E-046,R-307,late,19.00,0.00,"Section 3: submitted 46 days after the expense date, past the 45-day limit (day 46 or later is not paid)."
output/summary.md · written by the agent, 49 lines
# Expense review summary

Policy: Larkfield Design Group travel and expense policy v4.

**Total claimed: 12512.98**
**Total approved: 8752.29**

## By report

- R-301 | Imogen Hartley | claimed 1290.99 | approved 1208.99
- R-302 | Rafael Quintero | claimed 505.75 | approved 335.75
- R-303 | Priya Nandakumar | claimed 3332.70 | approved 873.20
- R-304 | Tobias Lindgren | claimed 4648.75 | approved 4503.25
- R-305 | Dele Okafor | claimed 1145.09 | approved 712.00
- R-306 | Imogen Hartley | claimed 1268.60 | approved 844.00
- R-307 | Mei Castellanos | claimed 321.10 | approved 275.10

## Lines not approved in full

- E-002 | over_limit | Section 5: lodging of 520.00 for 2 night(s) is over the limit of 240.00 x 2 = 480.00; paid at 480.00.
- E-004 | over_limit | Section 4: meal of 212.00 for 3 person(s) is over the limit of 65.00 x 3 = 195.00; paid at 195.00.
- E-006 | no_receipt | Section 2: an expense of 25.00 or more needs an itemized receipt and this 25.00 line has none.
- E-009 | late | Section 3: submitted 46 days after the expense date, past the 45-day limit (day 46 or later is not paid).
- E-010 | wrong_mileage | Section 7: 142 miles x 0.70 = 99.40, but 104.40 was claimed; paid at 99.40.
- E-013 | not_allowed | Section 9: category fine is one the company never pays.
- E-014 | not_economy | Section 6: business class is paid only with a director approval number and none is on the claim.
- E-016 | over_limit | Section 4: meal of 96.50 for 1 person(s) is over the limit of 65.00 x 1 = 65.00 (no attendee count given, so one person); paid at 65.00.
- E-018 | needs_approval | Section 8: a single expense of 588.00 is over 500.00 and has no approval number.
- E-021 | over_limit | Section 5: lodging of 1010.00 for 4 night(s) is over the limit of 240.00 x 4 = 960.00; paid at 960.00.
- E-023 | not_allowed | Section 9: category alcohol is one the company never pays.
- E-026 | duplicate | Section 10: same employee, expense date 2026-11-18, category taxi and amount 31.50 as earlier line E-025, so this second claim is not paid.
- E-028 | late | Section 3: submitted 60 days after the expense date, past the 45-day limit (day 46 or later is not paid).
- E-029 | over_limit | Section 4: meal of 72.00 for 1 person(s) is over the limit of 65.00 x 1 = 65.00; paid at 65.00.
- E-031 | no_receipt | Section 2: an expense of 25.00 or more needs an itemized receipt and this 129.99 line has none.
- E-032 | missing_info | Section 1: every line needs an expense date and an amount, and this line has no expense date, so it cannot be paid until filled in.
- E-034 | not_allowed | Section 9: category personal is one the company never pays.
- E-035 | duplicate | Section 10: same employee, expense date 2026-11-03, category meal and amount 58.40 as earlier line E-003, so this second claim is not paid.
- E-036 | not_economy | Section 6: premium economy class is paid only with a director approval number and none is on the claim.
- E-039 | missing_info | Section 1: every line needs an expense date and an amount, and this line has no amount, so it cannot be paid until filled in.
- E-042 | no_receipt | Section 2: an expense of 25.00 or more needs an itemized receipt and this 26.00 line has none.
- E-044 | over_limit | Section 4: meal of 131.00 for 2 person(s) is over the limit of 65.00 x 2 = 130.00; paid at 130.00.
- E-046 | late | Section 3: submitted 46 days after the expense date, past the 45-day limit (day 46 or later is not paid).

## Notes

- E-017 (category gift, flowers for a client) is not on the Section 9 never-pay list, which names only gifts for family under `personal`; treated as ok. Approver may want to confirm.
- E-039 has no amount, so it is missing_info (Section 1) and counts as 0.00 claimed.
- Deadline counts: E-008 (45 days) and E-045 (45 days) are on time; E-009 and E-046 (46 days) are late.
- Section 8 does not apply to air travel or lodging, so E-015 (705.00 for 3 nights) is checked only against Section 5.
check.py · the check, written before the run
"""Applies the written policy to every expense line and compares the result with what the agent wrote."""
import csv, re, sys
from datetime import date
from decimal import Decimal
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 money(s):
    try: return round(float(str(s).replace(",", "").replace("$", "").strip()), 2)
    except ValueError: return None
# Figures in the written files. A figure is a number that is not part of an id or a date.
FIG = re.compile(r"(?<![\w.])(?<!\w-)(?:\d{1,3}(?:,\d{3})+|\d+)(?:\.\d+)?(?!\w|-\w)")
DAY = re.compile(r"\d{4}-\d{2}-\d{2}")
def dec(x): return abs(Decimal(str(x).replace(",", "").replace("$", "").strip()))
def figs(line): return [dec(m.group(0)) for m in FIG.finditer(line)]
def together(text, *vals):
    """True when one line of the text carries every one of these figures."""
    return any(all(dec(v) in figs(ln) for v in vals) for ln in text.splitlines())
def writeup(text, id_re, rec, glob):
    """Every figure of two or more characters and every date must belong to a record named on its line
    or to the facts that hold for the whole file. Returns how many were seen and the ones that do not."""
    seen, bad = 0, []
    for ln in text.splitlines():
        allow = set(glob).union(*(rec[i] for i in re.findall(id_re, ln) if i in rec))
        for t in [m.group(0) for m in FIG.finditer(ln) if len(m.group(0)) > 1] + DAY.findall(ln):
            seen += 1
            if (t if DAY.fullmatch(t) else dec(t)) not in allow: bad.append(t)
    return seen, bad
policy = (root/"input/expense_policy.md").read_text()
def rule(pattern): return float(re.search(pattern, policy).group(1))
RECEIPT = rule(r"expense of ([\d.]+) or more")
DAYS = int(rule(r"within (\d+) days"))
MEAL = rule(r"up to ([\d.]+) per person")
NIGHT = rule(r"up to ([\d.]+) per night")
RATE = rule(r"paid at ([\d.]+) per mile")
LARGE = rule(r"expense over ([\d.]+) needs")
BANNED = set(re.findall(r"\(category `(\w+)`\)", policy))
lines = list(csv.DictReader((root/"input/expense_lines.csv").open()))
want, seen = {}, set()
for r in sorted(lines, key=lambda r: r["line_id"]):
    amt = money(r["amount"]); cat = r["category"].strip(); appr = r["approval_no"].strip()
    key = (r["employee"].strip(), r["expense_date"].strip(), cat, amt)
    st, pay = "ok", amt
    if amt is None or not r["expense_date"].strip(): st, pay = "missing_info", 0.0
    elif key in seen: st, pay = "duplicate", 0.0
    elif cat in BANNED: st, pay = "not_allowed", 0.0
    elif (date.fromisoformat(r["submitted_date"]) - date.fromisoformat(r["expense_date"])).days > DAYS: st, pay = "late", 0.0
    elif cat != "mileage" and amt >= RECEIPT and r["receipt"].strip().lower() != "yes": st, pay = "no_receipt", 0.0
    elif cat == "airfare" and r["travel_class"].strip().lower() != "economy" and not appr: st, pay = "not_economy", 0.0
    elif cat not in ("airfare", "lodging") and amt > LARGE and not appr: st, pay = "needs_approval", 0.0
    elif cat == "meal" and amt > round(MEAL * int(r["attendees"] or 1), 2): st, pay = "over_limit", round(MEAL * int(r["attendees"] or 1), 2)
    elif cat == "lodging" and amt > round(NIGHT * int(r["nights"] or 1), 2): st, pay = "over_limit", round(NIGHT * int(r["nights"] or 1), 2)
    elif cat == "mileage" and amt != round(RATE * float(r["miles"]) + 1e-9, 2): st, pay = "wrong_mileage", round(RATE * float(r["miles"]) + 1e-9, 2)
    if st != "missing_info": seen.add(key)
    want[r["line_id"]] = (st, amt or 0.0, pay, r["report_id"])
path = root/"output/expense_review.csv"
if not path.exists():
    say(False, "output/expense_review.csv was not written"); sys.exit(1)
rows = list(csv.DictReader(path.open()))
got = {(r.get("line_id") or "").strip(): r for r in rows}
n = len(want)
copied = sum(1 for k, v in want.items() if k in got and (got[k].get("report_id") or "").strip() == v[3] and (money(got[k].get("claimed")) or 0.0) == v[1])
say(set(got) == set(want) and len(rows) == n and copied == n,
    f"{len(set(got) & set(want))} of {n} expense lines appear once in expense_review.csv and {copied} carry the report and the amount claimed on the report")
right = sum(1 for k, v in want.items() if (got.get(k, {}).get("status") or "").strip() == v[0])
say(right == n, f"{right} of {n} statuses equal the status worked out from the policy text")
paid = sum(1 for k, v in want.items() if k in got and money(got[k].get("approved")) == v[2])
say(paid == n, f"{paid} of {n} approved amounts equal the amount the policy allows")
flagged = [k for k, v in want.items() if v[0] != "ok"]
# the section that covers a status is read from the policy headings by the words each heading uses
def heading(word): return re.search(r"^## (\d+)\. [^\n]*" + word, policy, re.M | re.I).group(1)
by_cat = {r["line_id"]: r["category"].strip() for r in lines}
def covers(k):
    st = want[k][0]
    word = {"missing_info": "must contain", "no_receipt": "Receipts", "late": "Deadline", "not_economy": "Air travel",
            "wrong_mileage": "Driving", "needs_approval": "Large", "not_allowed": "never pays", "duplicate": "twice",
            "over_limit": "Meals" if by_cat[k] == "meal" else "Lodging"}[st]
    return heading(word)
def cites(k):
    m = re.search(r"\b(?:sections?|sec\.?|§)\s*(\d+)", got.get(k, {}).get("reason") or "", re.I)
    return bool(m) and m.group(1) == covers(k)
cited = sum(1 for k in flagged if cites(k))
say(cited == len(flagged), f"{cited} of {len(flagged)} lines that are not ok name the policy section that covers their status")
md = (root/"output/summary.md").read_text() if (root/"output/summary.md").exists() else ""
nums = {money(x) for x in re.findall(r"\d[\d,]*\.\d{2}", md)}
claimed = round(sum(v[1] for v in want.values()), 2); approved = round(sum(v[2] for v in want.values()), 2)
say(claimed in nums and approved in nums, f"summary.md states the total claimed of {claimed:,.2f} and the total approved of {approved:,.2f}")
reports = sorted({v[3] for v in want.values()})
who = {r["report_id"]: r["employee"].strip() for r in lines}
def tot(rep, i): return round(sum(v[i] for v in want.values() if v[3] == rep), 2)
rep_ok = sum(1 for rep in reports if any(rep in ln and who[rep] in ln and tot(rep, 1) in map(float, figs(ln)) and tot(rep, 2) in map(float, figs(ln)) for ln in md.splitlines()))
say(rep_ok == len(reports), f"{rep_ok} of {len(reports)} reports are on one line of summary.md with the employee and the claimed and approved totals recomputed from the lines")
named = sum(1 for k in flagged if any(k in ln and want[k][0] in ln for ln in md.splitlines()))
say(named == len(flagged), f"{named} of {len(flagged)} lines that are not ok are named in summary.md with their status")
# every number written beside an expense line or a report must be a number of that line, of that report or of the policy
rec = {}
for r in lines:
    k = r["line_id"]; st, amt, pay, _ = want[k]
    own = {dec(amt), dec(pay), dec(round(amt - pay, 2)), r["expense_date"].strip(), r["submitted_date"].strip()}
    own |= {dec(r[c]) for c in ("attendees", "nights", "miles") if r[c].strip()}
    if r["expense_date"].strip(): own.add(dec((date.fromisoformat(r["submitted_date"]) - date.fromisoformat(r["expense_date"])).days))
    own |= {dec(round(MEAL * int(r["attendees"] or 1), 2)), dec(round(NIGHT * int(r["nights"] or 1), 2))}
    if r["miles"].strip(): own.add(dec(round(RATE * float(r["miles"]) + 1e-9, 2)))
    rec[k] = own
for rep in reports:
    rec[rep] = {dec(tot(rep, 1)), dec(tot(rep, 2)), dec(round(tot(rep, 1) - tot(rep, 2), 2)), dec(sum(1 for v in want.values() if v[3] == rep)),
                dec(sum(1 for v in want.values() if v[3] == rep and v[0] != "ok"))}
rules = set(figs(policy))
tally = {}
for v in want.values(): tally[v[0]] = tally.get(v[0], 0) + 1
facts = rules | {dec(claimed), dec(approved), dec(round(claimed - approved, 2)), dec(n), dec(len(reports)), dec(len(flagged))} | {dec(c) for c in tally.values()}
seen, bad = writeup(md, r"[ER]-\d+", rec, facts)
seen2 = bad2 = 0
for k, r in got.items():
    s2, b2 = writeup(r.get("reason") or "", r"[ER]-\d+", rec, rules | rec.get(k, set()))
    seen2 += s2; bad2 += len(b2)
say(seen > 0 and not bad and bad2 == 0, f"{seen - len(bad)} of {seen} figures in summary.md and {seen2 - bad2} of {seen2} in the reasons equal a figure of the line or report they sit beside, a policy figure or a recomputed total")
sys.exit(0 if ok else 1)

expense_lines.csv: sample data written by Atris. Fingerprint d20fc87ffc68.

expense_policy.md: sample data written by Atris. Fingerprint 7955725f06e6.

expense_review.csv: written by the agent. Fingerprint 87fc16340c08.

summary.md: written by the agent. Fingerprint dfe02c856402.


More finance work, and every other desk job

For agentsGitHub
What is AtrisBlogApp StorePricingPrivacyTerms