Atris

Find unusual payments in a ledger.
Done by an agent. Checked twice.

Every payment that breaks a written review rule, listed with each rule it breaks and the facts behind it.

Have Atris do this for you›

1

Real files in

  • approved_vendors.csv
    The list of sixteen vendors the company has approved. 17 lines, 481 bytes.
  • ledger.csv
    Eighty one rows from a small company's payments ledger for two months. 82 lines, 6 KB.
  • review_rules.md
    Seven written rules finance uses to decide which payments need a second look. 20 lines, 1 KB.

Sample data written by Atris. Not a real company.

2

Three steps

  1. 1.Read the ledger and the rules
  2. 2.Test every payment against every rule
  3. 3.Write the result

Claude Sonnet 5.5, 39 seconds. No web. It never saw the check.

3

Checked twice

  • ✓Passed: 17 of 17 payments that break a rule are in flags.csv and 0 of the 64 clean rows are flagged by mistake
  • ✓Passed: 17 of 17 flagged payments list exactly the rules they break, in the order of the rules file
  • ✓Passed: 17 of 17 flagged amounts equal the amount in the ledger
  • ✓Passed: summary.md states 81 payments read, 17 flagged and 30,441.73 flagged in all
  • ✓Passed: 7 of 7 rule counts in summary.md equal the counts rebuilt from the ledger
  • ✓Passed: 3 of 3 payments that break more than one rule are named in that section of summary.md with their vendor, amount and rules
  • ✓Passed: 17 of 17 flagged rows carry the date and vendor from the ledger and the rows are in ledger order
  • ✓Passed: 17 of 17 reasons state the fact behind each rule broken (the amount, the day of the week, the earlier txn_id or the name) and no figure from elsewhere

Second review by Claude Opus 5.5: pass.

Then we broke a copy of the output 5 ways on purpose. The check caught 5.

What it wrote. Lines 1 to 12 of flags.csv, copied from the file.
txn_id,date,vendor,amount,rules,reason
L-6009,2026-10-08,Dovetail Staffing,3840.00,no_approval,"Amount 3840.00 is 2,500.00 or more and approved_by is blank."
L-6012,2026-10-09,Mossback Hardware,2450.00,just_under,"Amount 2450.00 is just under the 2,500.00 approval line."
L-6016,2026-10-14,Pemberton Travel,1184.60,self_approved,Milo Achterberg both entered and approved it.
L-6020,2026-10-18,Fennel Catering,365.25,weekend,"Dated 2026-10-18, a Sunday."
L-6027,2026-10-21,Alder Office Supply,318.77,unknown_vendor,Vendor 'Alder Office Supply' is not on the approved vendor list.
L-6030,2026-10-22,Highmoor Print,742.18,duplicate,"Same vendor and amount 742.18 as L-6025 dated 2026-10-20, 2 day(s) earlier."
L-6033,2026-10-27,Dovetail Staffing,1500.00,round_amount,Amount 1500.00 is a whole multiple of 500.
L-6037,2026-10-29,Mossback Hardware,2499.99,just_under,"Amount 2499.99 is just under the 2,500.00 approval line."
L-6048,2026-11-05,Kelp and Coral Design,3150.00,self_approved,Renata Kovacs both entered and approved it.
L-6050,2026-11-08,Quillfeather Consulting,2000.00,weekend;round_amount;unknown_vendor,"Dated 2026-11-08, a Sunday; amount 2000.00 is a whole multiple of 500; vendor 'Quillfeather Consulting' is not on the approved vendor list."
L-6054,2026-11-10,Northpier Freight,1318.45,duplicate,"Same vendor and amount 1318.45 as L-6042 dated 2026-11-03, 7 day(s) earlier."

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 39 seconds.

What the second review verified

  • Recounted all 81 ledger rows (L-6001 to L-6081) by hand and found the same 17 flagged payments. Each one lists the same rules, in the rules-file order: for example, L-6050 has weekend;round_amount;unknown_vendor, and L-6058 and L-6073 both have no_approval;round_amount.
  • Re-added the 17 flagged amounts and got 30441.73, the same as 'Amount flagged'. The per-rule counts 3/2/3/3/4/3/3 also match flags.csv.
  • Checked the weekdays (2026-10-01 is a Thursday): 10-18, 11-08 and 11-22 are Sundays. L-6031 falls on Saturday 10-24 but is a credit, so leaving it out is correct.
  • Checked the edge cases: Larkspur 480.00 is 8 days apart, so it is not a duplicate. Northpier 1318.45 is exactly 7 days apart, so it is. Bayline 96.40 is on the same date and the higher id is the one flagged. 'BAYLINE COURIER' and ' alder office supplies' match approved vendors once case and outer spaces are ignored. 'Alder Office Supply' is a different vendor. 2399.99 is not just under; 2400.00 is. 6,200.00 is not a multiple of 500. The two credits (-2450.00 and -127.30) are not treated as earlier payments of duplicates.

What this run does not show

  • The ledger was written for this run with a few clear payments placed to break each rule. A real month has cases that sit closer to the line.
  • The check tests the seven written rules only. It cannot say whether a flagged payment is truly a problem or a clean one is truly fine.
  • Each reason is tested for the facts it carries. How clearly it reads 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 5 of 5. 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
# Find unusual payments in a ledger

function: data
for: the person who reviews the payments ledger each month
goal: Every payment that breaks a written review rule is listed with the rules it breaks while no clean payment is flagged.

## 1. Read the ledger and the rules
Read input/ledger.csv, input/approved_vendors.csv and input/review_rules.md. The rules file is the
only source of what counts as unusual. Read its notes as well as its table. Some amounts are written
with a comma for thousands, like 3,200.00. Read them as numbers.

## 2. Test every payment against every rule
Go through the ledger row by row and test each rule on each row. Do not stop at the first rule a
payment breaks. Keep the rules a payment breaks in the order of the rules file. A payment that breaks
no rule is clean and is not listed.

## 3. Write the result
Write output/flags.csv with columns txn_id,date,vendor,amount,rules,reason. One row per flagged payment
in ledger order. amount has two decimals and no comma. rules holds the rule names joined with a
semicolon. reason is one plain sentence with the facts that broke each rule (the amount, the day of the
week, the other txn_id, the names).
Write output/summary.md for the reviewer. Start with these three lines, each with its number:
`Payments read:` (every row in the ledger), `Payments flagged:` and `Amount flagged:` (the sum of the
flagged amounts). Then one line per rule in the form `rule name: count`, in the order of the rules
file. Then a section "Breaks more than one rule" with one line for each such payment giving its
txn_id, vendor, amount and rules.

## Done looks like
- Every payment that breaks a rule is in flags.csv with every rule it breaks.
- No clean payment and no credit is flagged.
- The counts in summary.md equal the rows in flags.csv.
input/approved_vendors.csv · 17 lines, 481 bytes
vendor,account
Alder Office Supplies,office
Bayline Courier,shipping
Cobalt Cloud Hosting,software
Dovetail Staffing,contractors
Eastgate Property Trust,rent
Fennel Catering,meals
Granite Insurance Mutual,insurance
Highmoor Print,marketing
Ivybridge Legal,legal
Junction Telecom,utilities
Kelp and Coral Design,marketing
Larkspur Cleaning,facilities
Mossback Hardware,equipment
Northpier Freight,shipping
Oakhurst Payroll Services,software
Pemberton Travel,travel
input/ledger.csv · 82 lines, 6 KB
txn_id,date,vendor,account,amount,entered_by,approved_by,memo
L-6001,2026-10-01,Eastgate Property Trust,rent,"6,200.00",Dana Whitlock,Renata Kovacs,October rent
L-6002,2026-10-02,Larkspur Cleaning,facilities,176.85,Dana Whitlock,,
L-6003,2026-10-05,Pemberton Travel,travel,3013.50,Sipho Ndlovu,Renata Kovacs,
L-6004,2026-10-05,Oakhurst Payroll Services,software,"1,620.37",Arjun Mehta,,
L-6005,2026-10-05,Larkspur Cleaning,facilities,480.00,Sipho Ndlovu,,Weekly clean
L-6006,2026-10-06,Alder Office Supplies,office,7448.00,Colette Fournier,Renata Kovacs,
L-6007,2026-10-06,Pemberton Travel,travel,"3,814.25",Sipho Ndlovu,Renata Kovacs,
L-6008,2026-10-07,Granite Insurance Mutual,insurance,194.94,Sipho Ndlovu,,
L-6009,2026-10-08,Dovetail Staffing,contractors,3840.00,Sipho Ndlovu,,"Temp cover, two weeks"
L-6010,2026-10-09,Bayline Courier,shipping,421.07,Colette Fournier,,
L-6011,2026-10-09,Pemberton Travel,travel,592.18,Sipho Ndlovu,,
L-6012,2026-10-09,Mossback Hardware,equipment,2450.00,Colette Fournier,,Shelving
L-6013,2026-10-12,Junction Telecom,utilities,267.12,Colette Fournier,,
L-6014,2026-10-13,Larkspur Cleaning,facilities,480.00,Dana Whitlock,,Weekly clean
L-6015,2026-10-14,Highmoor Print,marketing,1919.20,Colette Fournier,,
L-6016,2026-10-14,Pemberton Travel,travel,"1,184.60",Milo Achterberg,Milo Achterberg,"Flights, trade show"
L-6017,2026-10-15,Bayline Courier,shipping,327.26,Arjun Mehta,Milo Achterberg,
L-6018,2026-10-15,BAYLINE COURIER,shipping,58.20,Colette Fournier,,Document run
L-6019,2026-10-16,Highmoor Print,marketing,259.68,Colette Fournier,,
L-6020,2026-10-18,Fennel Catering,meals,365.25,Dana Whitlock,,Offsite lunch
L-6021,2026-10-20,Pemberton Travel,travel,368.08,Arjun Mehta,,
L-6022,2026-10-20,Dovetail Staffing,contractors,"4,290.90",Colette Fournier,Milo Achterberg,
L-6023,2026-10-20,Larkspur Cleaning,facilities,119.52,Arjun Mehta,,
L-6024,2026-10-20,Ivybridge Legal,legal,5990.57,Dana Whitlock,Renata Kovacs,
L-6025,2026-10-20,Highmoor Print,marketing,742.18,Sipho Ndlovu,,Invoice 3391
L-6026,2026-10-21,Cobalt Cloud Hosting,software,1297.78,Sipho Ndlovu,,
L-6027,2026-10-21,Alder Office Supply,other,318.77,Arjun Mehta,,Paper and toner
L-6028,2026-10-22,Highmoor Print,marketing,"4,722.48",Arjun Mehta,Renata Kovacs,
L-6029,2026-10-22,Ivybridge Legal,legal,267.42,Colette Fournier,,
L-6030,2026-10-22,Highmoor Print,marketing,742.18,Colette Fournier,,Invoice 3391
L-6031,2026-10-24,Alder Office Supplies,office,-127.30,Colette Fournier,,"Credit, returned chairs"
L-6032,2026-10-27,Highmoor Print,marketing,468.19,Colette Fournier,,
L-6033,2026-10-27,Dovetail Staffing,contractors,1500.00,Sipho Ndlovu,,"Day rate, three days"
L-6034,2026-10-28,Highmoor Print,marketing,"1,990.42",Colette Fournier,Milo Achterberg,
L-6035,2026-10-28,Fennel Catering,meals,500.00,Arjun Mehta,,Deposit
L-6036,2026-10-29,Granite Insurance Mutual,insurance,138.10,Sipho Ndlovu,Renata Kovacs,
L-6037,2026-10-29,Mossback Hardware,equipment,"2,499.99",Arjun Mehta,,"Shelving, second lot"
L-6038,2026-11-02,Oakhurst Payroll Services,software,365.30,Arjun Mehta,Milo Achterberg,
L-6039,2026-11-02,Ivybridge Legal,legal,394.71,Arjun Mehta,,
L-6040,2026-11-02,Eastgate Property Trust,rent,"6,200.00",Dana Whitlock,Renata Kovacs,November rent
L-6041,2026-11-03,Ivybridge Legal,legal,343.74,Dana Whitlock,,
L-6042,2026-11-03,Northpier Freight,shipping,1318.45,Dana Whitlock,,"Pallets, lane 4"
L-6043,2026-11-04,Pemberton Travel,travel,"6,339.30",Colette Fournier,Renata Kovacs,
L-6044,2026-11-04,Larkspur Cleaning,facilities,3520.77,Arjun Mehta,Milo Achterberg,
L-6045,2026-11-04, alder office supplies,office,127.30,Colette Fournier,,Desk lamps
L-6046,2026-11-05,Cobalt Cloud Hosting,software,"1,444.52",Colette Fournier,,
L-6047,2026-11-05,Highmoor Print,marketing,348.50,Arjun Mehta,Milo Achterberg,
L-6048,2026-11-05,Kelp and Coral Design,marketing,3150.00,Renata Kovacs,Renata Kovacs,Brochure design
L-6049,2026-11-06,Mossback Hardware,equipment,59.06,Dana Whitlock,,
L-6050,2026-11-08,Quillfeather Consulting,other,2000.00,Sipho Ndlovu,,Advisory retainer
L-6051,2026-11-09,Northpier Freight,shipping,285.63,Arjun Mehta,Milo Achterberg,
L-6052,2026-11-10,Northpier Freight,shipping,572.35,Arjun Mehta,Milo Achterberg,
L-6053,2026-11-10,Highmoor Print,marketing,622.85,Sipho Ndlovu,,
L-6054,2026-11-10,Northpier Freight,shipping,1318.45,Arjun Mehta,,"Pallets, lane 4"
L-6055,2026-11-11,Bayline Courier,shipping,509.27,Colette Fournier,,
L-6056,2026-11-11,Cobalt Cloud Hosting,software,2400.00,Colette Fournier,Milo Achterberg,Annual plan
L-6057,2026-11-12,Northpier Freight,shipping,2132.86,Sipho Ndlovu,Milo Achterberg,
L-6058,2026-11-12,Ivybridge Legal,legal,"2,500.00",Dana Whitlock,,Contract review
L-6059,2026-11-13,Mossback Hardware,equipment,-2450.00,Dana Whitlock,,"Credit, shelving returned"
L-6060,2026-11-16,Larkspur Cleaning,facilities,401.48,Dana Whitlock,Milo Achterberg,
L-6061,2026-11-16,Pemberton Travel,travel,"6,594.35",Arjun Mehta,Renata Kovacs,
L-6062,2026-11-16,Eastgate Property Trust,rent,310.55,Colette Fournier,,
L-6063,2026-11-16,Bayline Courier,shipping,96.40,Sipho Ndlovu,,Same day run
L-6064,2026-11-16,Bayline Courier,shipping,96.40,Colette Fournier,,Same day run
L-6065,2026-11-17,Cobalt Cloud Hosting,software,593.21,Colette Fournier,Renata Kovacs,
L-6066,2026-11-17,Dovetail Staffing,contractors,83.57,Colette Fournier,,
L-6067,2026-11-17,Tamarack Logistics,other,864.00,Sipho Ndlovu,,"Storage, one month"
L-6068,2026-11-18,Fennel Catering,meals,407.94,Dana Whitlock,,
L-6069,2026-11-18,Eastgate Property Trust,rent,378.29,Colette Fournier,,
L-6070,2026-11-18,Pemberton Travel,travel,"2,399.99",Arjun Mehta,,Hotel block
L-6071,2026-11-19,Larkspur Cleaning,facilities,1666.57,Dana Whitlock,,
L-6072,2026-11-19,Eastgate Property Trust,rent,305.78,Colette Fournier,,
L-6073,2026-11-19,Mossback Hardware,equipment,"5,000.00",Sipho Ndlovu,,Racking deposit
L-6074,2026-11-20,Dovetail Staffing,contractors,1170.51,Arjun Mehta,Milo Achterberg,
L-6075,2026-11-20,Kelp and Coral Design,marketing,2170.03,Sipho Ndlovu,,
L-6076,2026-11-22,Junction Telecom,utilities,212.09,Arjun Mehta,,Line rental
L-6077,2026-11-23,Mossback Hardware,equipment,1670.94,Dana Whitlock,,
L-6078,2026-11-23,Cobalt Cloud Hosting,software,1871.78,Arjun Mehta,Renata Kovacs,
L-6079,2026-11-24,Highmoor Print,marketing,"1,250.00",Colette Fournier,,Banner run
L-6080,2026-11-25,Northpier Freight,shipping,4443.94,Dana Whitlock,Milo Achterberg,
L-6081,2026-11-25,Bayline Courier,shipping,576.18,Dana Whitlock,,
input/review_rules.md · 20 lines, 1 KB
# Payment review rules

Finance reviews the payments ledger every month. A payment is flagged when it breaks any rule below.
A payment can break more than one rule. List the rules it breaks in the order they appear here.

| rule | a payment breaks it when |
|---|---|
| no_approval | the amount is 2,500.00 or more and approved_by is blank |
| self_approved | approved_by is the same person as entered_by |
| duplicate | an earlier payment has the same vendor and the same amount and is dated 0 to 7 days before it. Only the later payment is flagged. On the same date the lower txn_id is the earlier one |
| weekend | the date is a Saturday or a Sunday |
| round_amount | the amount is 1,000.00 or more and is a whole multiple of 500 |
| just_under | the amount is from 2,400.00 to 2,499.99, just under the approval line |
| unknown_vendor | the vendor is not on the approved vendor list |

Notes
- Vendor names are compared after removing spaces at the ends and ignoring capital letters. Nothing
  else is forgiven: a name spelled a different way is a different vendor.
- A row with an amount below zero is a credit from a vendor. No rule applies to credits and a credit
  never counts as the earlier payment of a duplicate.
output/flags.csv · written by the agent, 18 lines
txn_id,date,vendor,amount,rules,reason
L-6009,2026-10-08,Dovetail Staffing,3840.00,no_approval,"Amount 3840.00 is 2,500.00 or more and approved_by is blank."
L-6012,2026-10-09,Mossback Hardware,2450.00,just_under,"Amount 2450.00 is just under the 2,500.00 approval line."
L-6016,2026-10-14,Pemberton Travel,1184.60,self_approved,Milo Achterberg both entered and approved it.
L-6020,2026-10-18,Fennel Catering,365.25,weekend,"Dated 2026-10-18, a Sunday."
L-6027,2026-10-21,Alder Office Supply,318.77,unknown_vendor,Vendor 'Alder Office Supply' is not on the approved vendor list.
L-6030,2026-10-22,Highmoor Print,742.18,duplicate,"Same vendor and amount 742.18 as L-6025 dated 2026-10-20, 2 day(s) earlier."
L-6033,2026-10-27,Dovetail Staffing,1500.00,round_amount,Amount 1500.00 is a whole multiple of 500.
L-6037,2026-10-29,Mossback Hardware,2499.99,just_under,"Amount 2499.99 is just under the 2,500.00 approval line."
L-6048,2026-11-05,Kelp and Coral Design,3150.00,self_approved,Renata Kovacs both entered and approved it.
L-6050,2026-11-08,Quillfeather Consulting,2000.00,weekend;round_amount;unknown_vendor,"Dated 2026-11-08, a Sunday; amount 2000.00 is a whole multiple of 500; vendor 'Quillfeather Consulting' is not on the approved vendor list."
L-6054,2026-11-10,Northpier Freight,1318.45,duplicate,"Same vendor and amount 1318.45 as L-6042 dated 2026-11-03, 7 day(s) earlier."
L-6056,2026-11-11,Cobalt Cloud Hosting,2400.00,just_under,"Amount 2400.00 is just under the 2,500.00 approval line."
L-6058,2026-11-12,Ivybridge Legal,2500.00,no_approval;round_amount,"Amount 2500.00 is 2,500.00 or more and approved_by is blank; amount 2500.00 is a whole multiple of 500."
L-6064,2026-11-16,Bayline Courier,96.40,duplicate,"Same vendor and amount 96.40 as L-6063 dated 2026-11-16, 0 day(s) earlier."
L-6067,2026-11-17,Tamarack Logistics,864.00,unknown_vendor,Vendor 'Tamarack Logistics' is not on the approved vendor list.
L-6073,2026-11-19,Mossback Hardware,5000.00,no_approval;round_amount,"Amount 5000.00 is 2,500.00 or more and approved_by is blank; amount 5000.00 is a whole multiple of 500."
L-6076,2026-11-22,Junction Telecom,212.09,weekend,"Dated 2026-11-22, a Sunday."
output/summary.md · written by the agent, 16 lines
Payments read: 81
Payments flagged: 17
Amount flagged: 30441.73

no_approval: 3
self_approved: 2
duplicate: 3
weekend: 3
round_amount: 4
just_under: 3
unknown_vendor: 3

## Breaks more than one rule
- L-6050, Quillfeather Consulting, 2000.00, weekend;round_amount;unknown_vendor
- L-6058, Ivybridge Legal, 2500.00, no_approval;round_amount
- L-6073, Mossback Hardware, 5000.00, no_approval;round_amount
check.py · the check, written before the run
"""Tests every ledger row against the seven written rules and compares the result with what the agent wrote."""
import csv, re, sys
from datetime import date
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 num(s):
    try: return float(str(s).replace(",", "").replace("$", "").strip())
    except ValueError: return None
norm = lambda v: v.strip().lower()
approved = {norm(r["vendor"]) for r in csv.DictReader((root/"input/approved_vendors.csv").open())}
ledger = list(csv.DictReader((root/"input/ledger.csv").open()))
for r in ledger: r["amt"] = num(r["amount"]); r["day"] = date.fromisoformat(r["date"].strip()); r["id"] = r["txn_id"].strip()
order = ["no_approval", "self_approved", "duplicate", "weekend", "round_amount", "just_under", "unknown_vendor"]
want = {}
for r in ledger:
    if r["amt"] < 0: continue
    a, hit = r["amt"], []
    if a >= 2500 and not r["approved_by"].strip(): hit.append("no_approval")
    if r["approved_by"].strip() and norm(r["approved_by"]) == norm(r["entered_by"]): hit.append("self_approved")
    r["twins"] = [o for o in ledger if o is not r and o["amt"] >= 0 and norm(o["vendor"]) == norm(r["vendor"]) and abs(o["amt"] - a) < 0.005
                  and 0 <= (r["day"] - o["day"]).days <= 7 and (o["day"], o["id"]) < (r["day"], r["id"])]
    if r["twins"]: hit.append("duplicate")
    if r["day"].weekday() >= 5: hit.append("weekend")
    if a >= 1000 and round(a * 100) % 50000 == 0: hit.append("round_amount")
    if 2400 <= a < 2500: hit.append("just_under")
    if norm(r["vendor"]) not in approved: hit.append("unknown_vendor")
    if hit: want[r["id"]] = hit
amt = {r["id"]: r["amt"] for r in ledger}
path = root/"output/flags.csv"
if not path.exists():
    say(False, "output/flags.csv was not written"); sys.exit(1)
rows = list(csv.DictReader(path.open()))
got = {r.get("txn_id", "").strip(): [x.strip() for x in (r.get("rules") or "").split(";") if x.strip()] for r in rows}
found = len(set(got) & set(want)); extra = len(set(got) - set(want))
say(found == len(want) and extra == 0 and len(rows) == len(got), f"{found} of {len(want)} payments that break a rule are in flags.csv and {extra} of the {len(ledger) - len(want)} clean rows are flagged by mistake")
right = sum(1 for k, v in want.items() if got.get(k) == v)
say(right == len(want), f"{right} of {len(want)} flagged payments list exactly the rules they break, in the order of the rules file")
multi = [k for k, v in want.items() if len(v) > 1]
arow = {r.get("txn_id", "").strip(): num(r.get("amount")) for r in rows}
aok = sum(1 for k in want if arow.get(k) is not None and abs(arow[k] - amt[k]) < 0.005)
say(aok == len(want), f"{aok} of {len(want)} flagged amounts equal the amount in the ledger")
summary = (root/"output/summary.md").read_text() if (root/"output/summary.md").exists() else ""
def line(label):
    m = re.search(re.escape(label) + r"[^\n]*", summary, re.I); return m.group(0) if m else ""
nums = lambda s: [float(x.replace(",", "")) for x in re.findall(r"\d[\d,]*\.?\d*", s)]
total = sum(amt[k] for k in want)
top = (len(ledger) in nums(line("Payments read:")) and len(want) in nums(line("Payments flagged:")) and any(abs(x - total) < 0.005 for x in nums(line("Amount flagged:"))))
say(top, f"summary.md states {len(ledger)} payments read, {len(want)} flagged and {total:,.2f} flagged in all")
count = {name: sum(1 for v in want.values() if name in v) for name in order}
cr = sum(1 for name in order if re.search(r"^\W*" + name + r"\W*:\W*%d\b" % count[name], summary, re.M))
say(cr == len(order), f"{cr} of {len(order)} rule counts in summary.md equal the counts rebuilt from the ledger")
part = re.split("more than one rule", summary, maxsplit=1, flags=re.I)[1] if re.search("more than one rule", summary, re.I) else ""
named = sum(1 for k in multi if k in part)
by_id = {r["id"]: r for r in ledger}
def full(k):   # the line for this payment gives its vendor, its amount and its rules in order, and no other rule
    ln = next((x for x in part.splitlines() if k in x), "")
    rest = ln.replace(k, " ")
    said = [name for name in sorted(order, key=lambda n: rest.find(n)) if name in rest]
    return norm(by_id[k]["vendor"]) in rest.lower() and any(abs(x - amt[k]) < 0.005 for x in nums(rest)) and said == want[k]
whole_lines = sum(1 for k in multi if full(k))
extra_lines = sum(1 for k in want if k not in multi and k in part)
say(named == len(multi) and whole_lines == len(multi) and extra_lines == 0, f"{whole_lines} of {len(multi)} payments that break more than one rule are named in that section of summary.md with their vendor, amount and rules")
# the columns copied from the ledger
got_rows = {r.get("txn_id", "").strip(): r for r in rows}
dv = sum(1 for k in want if k in got_rows and (got_rows[k].get("date") or "").strip() == by_id[k]["day"].isoformat() and norm(got_rows[k].get("vendor") or "") == norm(by_id[k]["vendor"]))
in_order = [k for k in got_rows if k in want] == [r["id"] for r in ledger if r["id"] in want]
say(dv == len(want) and in_order, f"{dv} of {len(want)} flagged rows carry the date and vendor from the ledger and the rows {'are' if in_order else 'are not'} in ledger order")
# the reason has to state the fact behind each rule and nothing that is not in the ledger or the rules file
limits = nums(re.sub(r"\b[A-Za-z]+-\d+\b", " ", (root/"input/review_rules.md").read_text()))
week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
def reason_ok(k):
    r, text = by_id[k], got_rows.get(k, {}).get("reason") or ""
    low = text.lower(); others = {o["id"] for o in r["twins"]}
    ids = set(re.findall(r"\b[A-Za-z]+-\d+\b", text)); days = set(re.findall(r"\d{4}-\d{2}-\d{2}", text))
    bare = re.sub(r"\d{4}-\d{2}-\d{2}|\b[A-Za-z]+-\d+\b", " ", text)
    figures = nums(bare); gaps = [(r["day"] - o["day"]).days for o in r["twins"]]
    need = {"no_approval": any(abs(x - r["amt"]) < 0.005 for x in figures), "round_amount": any(abs(x - r["amt"]) < 0.005 for x in figures),
            "just_under": any(abs(x - r["amt"]) < 0.005 for x in figures), "weekend": week[r["day"].weekday()].lower() in low,
            "duplicate": bool(ids & others), "self_approved": norm(r["approved_by"]) in low, "unknown_vendor": norm(r["vendor"]) in low}
    stray = (ids - others - {k}) or (days - {r["day"].isoformat()} - {o["day"].isoformat() for o in r["twins"]})
    stray = stray or any(d.lower() in low for d in week if d != week[r["day"].weekday()])
    stray = stray or any(not any(abs(x - y) < 0.005 for y in [r["amt"]] + limits + gaps) for x in figures)
    return all(need[name] for name in want[k]) and not stray
rs = sum(1 for k in want if reason_ok(k))
say(rs == len(want), f"{rs} of {len(want)} reasons state the fact behind each rule broken (the amount, the day of the week, the earlier txn_id or the name) and no figure from elsewhere")
sys.exit(0 if ok else 1)

approved_vendors.csv: sample data written by Atris. Fingerprint 3f62b1e7fd48.

ledger.csv: sample data written by Atris. Fingerprint ce8601f16f6c.

review_rules.md: sample data written by Atris. Fingerprint 8067412fec01.

flags.csv: written by the agent. Fingerprint 22e96845baee.

summary.md: written by the agent. Fingerprint 64497059b0fd.


More data and analysis work, and every other desk job

For agentsGitHub
What is AtrisBlogApp StorePricingPrivacyTerms