Atris

Find stale and at-risk open deals.
Done by an agent. Checked twice.

Every open deal is tested against your own review rules, so the weekly review starts with the deals at risk.

Have Atris do this for you›

1

Real files in

  • deal_review_rules.md
    One sales team's rules for the weekly deal review: five flags, the day limits for each stage and how to read messy fields. 40 lines, 2 KB.
  • open_deals_export.csv
    Fifty-two rows exported from a sales record system, with closed deals mixed in, two deals exported twice, two date styles and amounts typed five ways. 53 lines, 6 KB.

Sample data written by Atris. Not a real company.

2

Three steps

  1. 1.Read the rules and clean the export
  2. 2.Test every open deal
  3. 3.Write the review sheet

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

3

Checked twice

  • ✓Passed: 44 of 44 open deals appear once in deal_flags.csv and 0 closed deals appear
  • ✓Passed: 44 of 44 deals have the day counts worked out again from the dates in the export
  • ✓Passed: 44 of 44 deals carry exactly the flags the rules give them
  • ✓Passed: 44 of 44 deals have the right level, owner name, stage, account and amount
  • ✓Passed: review.md gives the right count and total for 3 of 3 levels, with 17 deals and 475,900.00 at risk
  • ✓Passed: review.md gives the right at-risk count and total for 4 of 4 owners
  • ✓Passed: review.md lists 17 of 17 at-risk deals, largest amount first
  • ✓Passed: 17 of 17 at-risk deals are listed in review.md with their own account, owner, amount and flags
  • ✓Passed: 47 of 47 numbers and dates in review.md are a count or total worked out again, or a value from the row of a deal named on that line

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 16 to 28 of review.md, copied from the file.
| deal_id | account | owner | amount | flags |
|---|---|---|---|---|
| D-5142 | Silverdale Spa | Priti Sandhu | 120,000.00 | stale, stuck, overdue |
| D-5145 | Wennington Wines | Marcus Oyelowo | 120,000.00 | stale, overdue |
| D-5130 | Forton Storage | Priti Sandhu | 58,000.00 | stale, stuck, no_next_step |
| D-5149 | Claughton Brick | Marcus Oyelowo | 31,500.00 | stale, stuck |
| D-5104 | Eskdale Motors | Dana Whitlock | 24,000.00 | stuck, overdue |
| D-5106 | Gilling Timber | Priti Sandhu | 18,000.00 | stale, stuck, overdue |
| D-5117 | Ribblehead Rail | Marcus Oyelowo | 18,000.00 | stale, stuck, overdue |
| D-5129 | Ellel Foods | Marcus Oyelowo | 18,000.00 | stuck, no_next_step |
| D-5123 | Yealand Bakers | Tom Ferrant | 12,500.00 | stale, stuck |
| D-5125 | Arkholme Dental | Marcus Oyelowo | 12,500.00 | stale, stuck |
| D-5111 | Lathom Plastics | Tom Ferrant | 9,500.00 | stale, stuck, no_next_step |

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 2 s.

What the second review verified

  • Recomputed all 44 open deals from the export (6 Won/Lost dropped: D-5103, D-5112, D-5124, D-5131, D-5138, D-5144). Every row of deal_flags.csv matched: owner, stage, amount, days, flags and level.
  • Duplicates handled by the rules: D-5107 kept the 11/30/2026 row (0 days quiet, 40 days in Demo, so stuck and watch). D-5128 kept the lower row.
  • Edge cases follow the rules: D-5106 has no last activity, so it counts from created 2026-08-28 (94 days). D-5114 is exactly on its limits (21 and 45 days) and closes on the export date, so it is healthy. D-5127 has amount 0 and gets no_amount. D-5122 has no close date and gets overdue.
  • Review totals match: at_risk 17 / 475,900.00, watch 10 / 280,500.00, healthy 17 / 913,500.00. By owner: Dana 1 / 24,000, Marcus 6 / 207,500, Priti 6 / 215,200, Tom 4 / 29,200. The at-risk list is in the right order, largest amount first.

What this run does not show

  • The export and the review rules were written by Atris for this run, with the mess planted on purpose.
  • The first check did not test the stage or account columns or the figures in the review sheet. The stricter check does and the same output passed.
  • The advice on what to fix at the source is tested only for its numbers. Whether it is the right advice is read by the second review alone.

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
# Find stale and at-risk open deals

function: sales
for: the sales manager who runs the weekly deal review
goal: Every open deal in the export is tested against the team's own rules, so the review starts with the deals that need a decision.

## 1. Read the rules and clean the export
Read input/deal_review_rules.md first, then input/open_deals_export.csv. The rules file says which
date to count from, which rows count, how to read dates, amounts, stages and names that were typed
in different ways. It also says what to do when the same deal appears twice. Follow it to the letter. Work
out the dates with python3, not by eye.

## 2. Test every open deal
For each deal that counts, work out the days since the last activity and the days in its stage, test
it for every flag in the rules and give it the level the rules give for that number of flags.

Write output/deal_flags.csv with columns
deal_id,account,owner,stage,amount,days_since_activity,days_in_stage,flags,level. One row per open
deal, each deal once. owner and stage are written the way the rules file spells them. amount is a
plain number with two decimals, blank when the deal has none. flags holds the flag names from the
rules joined by a semicolon, in the order the rules list them, blank when there are none.

## 3. Write the review sheet
Write output/review.md for the manager:
- one line per level in the form `- at_risk: 12 deals, 345,000.00`, giving the count and the total
  amount at that level
- one line per owner in the form `- Dana Whitlock: 3 at risk, 45,000.00`, giving that owner's count
  and total amount of at-risk deals
- then every at-risk deal, largest amount first, with deal_id, account, owner, amount and its flags
- then a short note of anything in the export the manager should fix at the source, such as rows
  that appear twice or names typed two ways.

## Done looks like
- Every open deal appears once in deal_flags.csv and no closed deal appears.
- Every flag can be worked out again from the deal's own row and the rules.
- The totals in review.md equal the sums in deal_flags.csv.
input/deal_review_rules.md · 40 lines, 2 KB
# Weekly deal review rules

Marrowfield Systems sales team. The export in this folder was taken on 2026-11-30. Count every number
of days up to that date.

## Which rows count

- Review open deals only. Skip any row whose status is Won or Lost. Status can be typed in any mix of
  capital and small letters.
- A deal edited while the export ran shows up twice with the same deal_id. Keep the row with the
  later last_activity_date. If they are the same, keep the one lower down the file.

## Reading the fields

- Dates come as 2026-11-03 or as 11/03/2026 (month first). Both are fine.
- Amounts are typed in many ways: $12,500 and 12,500.00 and 12500 are all 12500. A k means thousand,
  so 45k is 45000.
- Stage is one of Discovery, Demo, Proposal, Negotiation. Ignore capital letters and stray spaces.
- The team is Dana Whitlock, Marcus Oyelowo, Priti Sandhu and Tom Ferrant. The export sometimes
  shortens or misspells a name. Write every owner the way this list does.

## Flags

Test every open deal for all five. A deal can carry several.

| Flag | When |
|---|---|
| stale | More days since last_activity_date than the stage allows: Discovery 21, Demo 14, Proposal 10, Negotiation 7. If last_activity_date is blank, count from created_date. |
| stuck | More days since stage_entered_date than the stage allows: Discovery 45, Demo 30, Proposal 30, Negotiation 21. |
| overdue | close_date is before the export date, or blank. |
| no_next_step | next_step is blank. |
| no_amount | amount is blank or zero. |

A deal exactly on a limit is inside it. 21 days quiet in Discovery is not stale. 22 is.

## Level

- two or more flags: `at_risk`
- one flag: `watch`
- no flags: `healthy`
input/open_deals_export.csv · 53 lines, 6 KB
deal_id,account,owner,stage,amount,created_date,stage_entered_date,last_activity_date,close_date,next_step,status
D-5100,Aldergate Clinics,Dana Whitlock,Demo,"$12,500",2026-09-15,2026-11-24,2026-11-24,2027-01-15,Book demo with operations,Open
D-5101,Bramhall Foods,Marcus Oyelowo,Discovery,12500,2026-10-05,2026-11-14,2026-11-29,2026-11-10,Follow up on trial,Open
D-5102,Coldstream Freight,Priti Sandhu,Proposal,18000,2026-10-23,2026-11-12,2026-11-20,2026-12-20,Pricing call,Open
D-5103,Dunmere Schools Trust,Tom Ferrant,Discovery,12500,08/22/2026,10/01/2026,11/11/2026,12/18/2026,Legal review of contract,Won
D-5104,Eskdale Motors,D. Whitlock,Proposal,"24,000.00",2026-09-15,2026-10-25,2026-11-24,2026-11-24,Pricing call,Open
D-5105,Farrowby Hotels,Marcus Oyelowo,Proposal,42000,2026-10-23,2026-11-12,2026-11-19,2026-12-20,Legal review of contract,Open
D-5106,Gilling Timber,Priti Sandhu,Discovery,18000,2026-08-28,2026-10-07,,2026-11-10,Await purchase order,Open
D-5107,Hawksworth Legal,Tom Ferrant,Demo,31500,2026-10-01,10/21/2026,11/04/2026,12/20/2026,Await purchase order,Open
D-5108,Inchmarlo Dairies,Dana Whitlock,Negotiation,18000,2026-10-20,2026-11-09,2026-11-23,2026-12-20,Await purchase order,Open
D-5109,Jesmond Print,Marcus Oyelowo,Discovery,45k,2026-09-19,2026-11-28,2026-11-28,2026-12-18,Follow up on trial,Open
D-5110,Kirkby Optical,Priti Sandhu,proposal,7200,2026-10-09,2026-10-29,2026-11-06,2026-12-11,Intro to finance lead,Open
D-5111,Lathom Plastics,Tom Ferrant,Negotiation,9500,10/19/2026,11/08/2026,11/22/2026,12/20/2026,,Open
D-5112,Morland Tools,Dana Whitlock,Negotiation,12500,2026-09-05,2026-10-15,2026-11-06,2027-01-29,Pricing call,Lost
D-5113,Netherby Pharma,Marcus Oyelowo,Discovery,"$ 58,000",2026-10-10,2026-10-30,2026-11-29,2026-12-18,Await purchase order,Open
D-5114,Oxenhope Mills,Priti Sandhu,Discovery,42000,2026-09-26,2026-10-16,2026-11-09,2026-11-30,Book demo with operations,Open
D-5115,Penhallow Marine,Tom Ferrant,Discovery,120000,10/18/2026,10/23/2026,11/22/2026,12/18/2026,Pricing call,Open
D-5116,Quernmore Energy,D. Whitlock,Discovery,120000,2026-10-05,2026-11-14,2026-11-22,2026-12-04,Intro to finance lead,Open
D-5117,Ribblehead Rail,Marcus Oyelowo,Demo,18000,2026-10-10,2026-10-30,2026-11-15,2026-11-29,Legal review of contract,Open
D-5118,Skelwith Homes,Priti Sandhu,Proposal,76000,2026-10-10,2026-10-30,2026-11-21,2026-12-25,Send proposal,Open
D-5119,Thirlmere Water,Tom Ferrant,Demo ,24000,10/25/2026,11/14/2026,11/29/2026,12/25/2026,Share security answers,Open
D-5120,Ulpha Outdoor,Dana Whitlock,Discovery,,2026-09-07,2026-11-16,2026-11-19,2026-12-11,Send proposal,Open
D-5121,Vennington Glass,Priti Sandu,Discovery,76000,2026-10-10,2026-10-30,2026-11-29,2026-12-04,Send proposal,Open
D-5122,Wharfedale Vets,Priti Sandhu,Negotiation,7200,2026-10-02,2026-11-11,2026-11-14,,Follow up on trial,Open
D-5123,Yealand Bakers,Tom Ferrant,Proposal,12500,09/23/2026,10/13/2026,10/28/2026,01/15/2027,Call back after budget meeting,Open
D-5124,Zetland Shipping,Dana Whitlock,Negotiation,31500,2026-11-01,2026-11-06,2026-11-21,2026-12-11,Site visit,Won
D-5125,Arkholme Dental,Marcus Oyelowo,Demo,12500,2026-10-07,2026-10-27,2026-11-11,2027-01-15,Send proposal,Open
D-5126,Bowland Brewing,Priti Sandhu,NEGOTIATION,12500,2026-10-27,2026-11-16,2026-11-24,2027-01-29,Call back after budget meeting,Open
D-5127,Caton Robotics,Tom Ferrant,Negotiation,0,10/12/2026,11/21/2026,11/24/2026,11/10/2026,Await purchase order,Open
D-5128,Dolphinholme Care,Dana Whitlock,Discovery,31500,2026-10-25,2026-10-30,2026-11-14,2027-01-15,Book demo with operations,Open
D-5128,Dolphinholme Care,Dana Whitlock,Discovery,"31,500",2026-10-25,2026-10-30,2026-11-14,2027-01-15,Book demo with operations,Open
D-5129,Ellel Foods,Marcus Oyelowo,Negotiation,18000,2026-09-25,2026-10-15,2026-11-25,2026-12-25,,Open
D-5130,Forton Storage,Priti Sandhu,Negotiation,58000,2026-08-19,2026-09-28,2026-10-28,2026-12-31,   ,Open
D-5131,Galgate Auto,Tom Ferrant,Proposal,18000,08/29/2026,11/07/2026,11/22/2026,11/24/2026,,Lost
D-5132,Halton Fabrics,Dana Whitlock,Demo,120000,2026-10-25,2026-11-14,2026-11-29,2026-12-18,Send proposal,Open
D-5133,Ingleton Quarries,Marcus Oyelowo,Demo,7.5k,2026-07-29,2026-10-07,2026-11-06,2027-01-15,Intro to finance lead,Open
D-5134,Kellet Couriers,Priti Sandhu,Demo,4800,2026-10-08,2026-10-28,2026-10-28,2026-12-04,Await purchase order,Open
D-5135,Lowgill Farms,Tom Ferrant,Proposal,58000,09/04/2026,11/13/2026,11/28/2026,12/11/2026,Send proposal,Open
D-5136,Mewith Media,Dana Whitlock,Demo,42000,2026-09-18,2026-10-28,2026-11-27,2027-01-29,Follow up on trial,Open
D-5137,Newby Insurance,Marcus Oyelowo,Negotiation,42000,2026-11-24,2026-11-29,2026-11-29,2026-11-24,Follow up on trial,Open
D-5138,Overton Seafood,Priti Sandhu,Proposal,24000,2026-09-14,2026-10-04,2026-11-14,2026-11-10,Book demo with operations,Lost
D-5139,Priest Hutton Hotels,Tom Ferrant,Discovery,7200,09/04/2026,10/14/2026,11/24/2026,11/24/2026,Follow up on trial,Open
D-5140,Quernside Travel,Dana Whitlock,Negotiation,12500,2026-10-09,2026-11-18,2026-11-21,2026-12-31,Site visit,Open
D-5107,Hawksworth Legal,Tom Ferrant,Demo,31500,09/16/2026,10/21/2026,11/30/2026,12/20/2026,Call back after budget meeting,Open
D-5141,Roeburn Cycles,Marcus Oyelowo,Negotiation,58000,2026-11-23,2026-11-28,2026-11-28,2026-12-25,Intro to finance lead,Open
D-5142,Silverdale Spa,Priti Sandhu,Negotiation,120000,2026-07-18,2026-09-26,2026-11-06,2026-11-24,Call back after budget meeting,Open
D-5143,Tatham Roofing,Tom Ferrant,Proposal,9500,10/30/2026,11/04/2026,11/19/2026,01/29/2027,Pricing call,Open
D-5144,Underley Estates,Dana Whitlock,Demo,42000,2026-10-08,2026-10-28,2026-11-27,2026-12-25,Pricing call,Won
D-5145,Wennington Wines,Marcus Oyelowo,Proposal,120000,2026-10-28,2026-11-17,2026-11-17,2026-11-10,Share security answers,Open
D-5146,Whittington Labs,Priti Sandhu,Discovery,58000,2026-09-08,2026-11-17,2026-11-17,2027-01-15,Book demo with operations,Open
D-5147,Yarlside Fitness,Tom Ferrant,Demo,12500,09/01/2026,10/11/2026,11/21/2026,12/25/2026,Legal review of contract,open
D-5148,Burrow Software,Dana Whitlock,Discovery,42000,2026-10-02,2026-11-11,2026-11-11,2027-01-29,Await purchase order,Open
D-5149,Claughton Brick,Marcus Oyelowo,Proposal,31500,2026-07-29,2026-10-07,2026-11-17,2027-01-15,Legal review of contract,Open
output/deal_flags.csv · written by the agent, 45 lines
deal_id,account,owner,stage,amount,days_since_activity,days_in_stage,flags,level
D-5100,Aldergate Clinics,Dana Whitlock,Demo,12500.00,6,6,,healthy
D-5101,Bramhall Foods,Marcus Oyelowo,Discovery,12500.00,1,16,overdue,watch
D-5102,Coldstream Freight,Priti Sandhu,Proposal,18000.00,10,18,,healthy
D-5104,Eskdale Motors,Dana Whitlock,Proposal,24000.00,6,36,stuck;overdue,at_risk
D-5105,Farrowby Hotels,Marcus Oyelowo,Proposal,42000.00,11,18,stale,watch
D-5106,Gilling Timber,Priti Sandhu,Discovery,18000.00,94,54,stale;stuck;overdue,at_risk
D-5107,Hawksworth Legal,Tom Ferrant,Demo,31500.00,0,40,stuck,watch
D-5108,Inchmarlo Dairies,Dana Whitlock,Negotiation,18000.00,7,21,,healthy
D-5109,Jesmond Print,Marcus Oyelowo,Discovery,45000.00,2,2,,healthy
D-5110,Kirkby Optical,Priti Sandhu,Proposal,7200.00,24,32,stale;stuck,at_risk
D-5111,Lathom Plastics,Tom Ferrant,Negotiation,9500.00,8,22,stale;stuck;no_next_step,at_risk
D-5113,Netherby Pharma,Marcus Oyelowo,Discovery,58000.00,1,31,,healthy
D-5114,Oxenhope Mills,Priti Sandhu,Discovery,42000.00,21,45,,healthy
D-5115,Penhallow Marine,Tom Ferrant,Discovery,120000.00,8,38,,healthy
D-5116,Quernmore Energy,Dana Whitlock,Discovery,120000.00,8,16,,healthy
D-5117,Ribblehead Rail,Marcus Oyelowo,Demo,18000.00,15,31,stale;stuck;overdue,at_risk
D-5118,Skelwith Homes,Priti Sandhu,Proposal,76000.00,9,31,stuck,watch
D-5119,Thirlmere Water,Tom Ferrant,Demo,24000.00,1,16,,healthy
D-5120,Ulpha Outdoor,Dana Whitlock,Discovery,,11,14,no_amount,watch
D-5121,Vennington Glass,Priti Sandhu,Discovery,76000.00,1,31,,healthy
D-5122,Wharfedale Vets,Priti Sandhu,Negotiation,7200.00,16,19,stale;overdue,at_risk
D-5123,Yealand Bakers,Tom Ferrant,Proposal,12500.00,33,48,stale;stuck,at_risk
D-5125,Arkholme Dental,Marcus Oyelowo,Demo,12500.00,19,34,stale;stuck,at_risk
D-5126,Bowland Brewing,Priti Sandhu,Negotiation,12500.00,6,14,,healthy
D-5127,Caton Robotics,Tom Ferrant,Negotiation,0.00,6,9,overdue;no_amount,at_risk
D-5128,Dolphinholme Care,Dana Whitlock,Discovery,31500.00,16,31,,healthy
D-5129,Ellel Foods,Marcus Oyelowo,Negotiation,18000.00,5,46,stuck;no_next_step,at_risk
D-5130,Forton Storage,Priti Sandhu,Negotiation,58000.00,33,63,stale;stuck;no_next_step,at_risk
D-5132,Halton Fabrics,Dana Whitlock,Demo,120000.00,1,16,,healthy
D-5133,Ingleton Quarries,Marcus Oyelowo,Demo,7500.00,24,54,stale;stuck,at_risk
D-5134,Kellet Couriers,Priti Sandhu,Demo,4800.00,33,33,stale;stuck,at_risk
D-5135,Lowgill Farms,Tom Ferrant,Proposal,58000.00,2,17,,healthy
D-5136,Mewith Media,Dana Whitlock,Demo,42000.00,3,33,stuck,watch
D-5137,Newby Insurance,Marcus Oyelowo,Negotiation,42000.00,1,1,overdue,watch
D-5139,Priest Hutton Hotels,Tom Ferrant,Discovery,7200.00,6,47,stuck;overdue,at_risk
D-5140,Quernside Travel,Dana Whitlock,Negotiation,12500.00,9,12,stale,watch
D-5141,Roeburn Cycles,Marcus Oyelowo,Negotiation,58000.00,2,2,,healthy
D-5142,Silverdale Spa,Priti Sandhu,Negotiation,120000.00,24,65,stale;stuck;overdue,at_risk
D-5143,Tatham Roofing,Tom Ferrant,Proposal,9500.00,11,26,stale,watch
D-5145,Wennington Wines,Marcus Oyelowo,Proposal,120000.00,13,13,stale;overdue,at_risk
D-5146,Whittington Labs,Priti Sandhu,Discovery,58000.00,13,13,,healthy
D-5147,Yarlside Fitness,Tom Ferrant,Demo,12500.00,9,50,stuck,watch
D-5148,Burrow Software,Dana Whitlock,Discovery,42000.00,19,19,,healthy
D-5149,Claughton Brick,Marcus Oyelowo,Proposal,31500.00,13,54,stale;stuck,at_risk
output/review.md · written by the agent, 46 lines
# Weekly deal review (export of 2026-11-30)

## By level
- at_risk: 17 deals, 475,900.00
- watch: 10 deals, 280,500.00
- healthy: 17 deals, 913,500.00

## At-risk by owner
- Dana Whitlock: 1 at risk, 24,000.00
- Marcus Oyelowo: 6 at risk, 207,500.00
- Priti Sandhu: 6 at risk, 215,200.00
- Tom Ferrant: 4 at risk, 29,200.00

## At-risk deals, largest first

| deal_id | account | owner | amount | flags |
|---|---|---|---|---|
| D-5142 | Silverdale Spa | Priti Sandhu | 120,000.00 | stale, stuck, overdue |
| D-5145 | Wennington Wines | Marcus Oyelowo | 120,000.00 | stale, overdue |
| D-5130 | Forton Storage | Priti Sandhu | 58,000.00 | stale, stuck, no_next_step |
| D-5149 | Claughton Brick | Marcus Oyelowo | 31,500.00 | stale, stuck |
| D-5104 | Eskdale Motors | Dana Whitlock | 24,000.00 | stuck, overdue |
| D-5106 | Gilling Timber | Priti Sandhu | 18,000.00 | stale, stuck, overdue |
| D-5117 | Ribblehead Rail | Marcus Oyelowo | 18,000.00 | stale, stuck, overdue |
| D-5129 | Ellel Foods | Marcus Oyelowo | 18,000.00 | stuck, no_next_step |
| D-5123 | Yealand Bakers | Tom Ferrant | 12,500.00 | stale, stuck |
| D-5125 | Arkholme Dental | Marcus Oyelowo | 12,500.00 | stale, stuck |
| D-5111 | Lathom Plastics | Tom Ferrant | 9,500.00 | stale, stuck, no_next_step |
| D-5133 | Ingleton Quarries | Marcus Oyelowo | 7,500.00 | stale, stuck |
| D-5110 | Kirkby Optical | Priti Sandhu | 7,200.00 | stale, stuck |
| D-5122 | Wharfedale Vets | Priti Sandhu | 7,200.00 | stale, overdue |
| D-5139 | Priest Hutton Hotels | Tom Ferrant | 7,200.00 | stuck, overdue |
| D-5134 | Kellet Couriers | Priti Sandhu | 4,800.00 | stale, stuck |
| D-5127 | Caton Robotics | Tom Ferrant | 0.00 | overdue, no_amount |

## Fix at the source

- **Rows that appear twice (2 deals):**
  - D-5107 Hawksworth Legal: the two rows differ. One has last activity 11/04/2026, created 2026-10-01 and next step "Await purchase order". The other has last activity 11/30/2026, created 09/16/2026 and next step "Call back after budget meeting". I kept the later-activity row, as the rules say. The two created dates disagree, so please confirm which is right.
  - D-5128 Dolphinholme Care: identical apart from how the amount is typed (31500 and "31,500"). I kept the lower row.
- **Owner names typed two ways:** "D. Whitlock" (D-5104, D-5116) is Dana Whitlock. "Priti Sandu" (D-5121) is Priti Sandhu.
- **Stage typed with odd case or spaces:** "proposal" (D-5110), "Demo " (D-5119) and "NEGOTIATION" (D-5126). Status "open" in lower case also appears (D-5147).
- **Amounts and dates typed many ways:** "$12,500", "45k", "7.5k", "$ 58,000" and "24,000.00". Dates are mixed between YYYY-MM-DD and MM/DD/YYYY.
- **Zero or blank amount:** D-5127 Caton Robotics has amount 0 (written as 0.00 in deal_flags.csv, flagged no_amount). D-5120 Ulpha Outdoor has a blank amount (blank in the CSV, flagged no_amount).
- **Blank fields:** D-5106 Gilling Timber has no last_activity_date, so days were counted from created_date. D-5122 Wharfedale Vets has no close_date, so it is flagged overdue. D-5111, D-5129 and D-5130 have a blank next_step. D-5131 does too, but it is Lost.
- **Closed deals left out (6):** D-5103, D-5112, D-5124, D-5131, D-5138, D-5144 (Won or Lost).
check.py · the check, written before the run
"""Works out every open deal's day counts, flags and level again from the export and the rules, then compares."""
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)
rules = (root/"input/deal_review_rules.md").read_text()
TODAY = date.fromisoformat(re.search(r"taken on (\d{4}-\d\d-\d\d)", rules).group(1))
STALE = {"discovery": 21, "demo": 14, "proposal": 10, "negotiation": 7}
STUCK = {"discovery": 45, "demo": 30, "proposal": 30, "negotiation": 21}
TEAM = ["Dana Whitlock", "Marcus Oyelowo", "Priti Sandhu", "Tom Ferrant"]
def day(text):
    text = text.strip()
    if not text: return None
    if "/" in text:
        m, d, y = text.split("/"); return date(int(y), int(m), int(d))
    return date.fromisoformat(text)
def money(text):
    t = text.replace("$", "").replace(",", "").replace(" ", "").lower()
    if not t: return 0.0
    return float(t[:-1]) * 1000 if t.endswith("k") else float(t)
def owner(text):          # first initial and first three letters of the surname pick out one person on the team
    first, last = text.strip().split()[0], text.strip().split()[-1]
    return next(t for t in TEAM if t[0] == first[0] and t.split()[1][:3] == last[:3])
DATE = r"\d{4}-\d\d-\d\d|\d{1,2}/\d{1,2}/\d{4}"
def figures(text):
    text = re.sub(r"\b[A-Za-z]+-\d+\b|" + DATE, " ", text)
    return [float(x.rstrip(",").replace(",", "")) for x in re.findall(r"(?<![\w.])\d[\d,]*(?:\.\d+)?", text)]
keep, typed, closed, raw = {}, {}, 0, 0
for r in csv.DictReader((root/"input/open_deals_export.csv").open()):
    raw += 1; typed[r["deal_id"]] = typed.get(r["deal_id"], "") + " " + " ".join(r.values())
    if r["status"].strip().lower() != "open":
        closed += 1; continue
    old = keep.get(r["deal_id"])
    if old is None or (day(r["last_activity_date"]) or date.min) >= (day(old["last_activity_date"]) or date.min): keep[r["deal_id"]] = r
want = {}
for k, r in keep.items():
    st = r["stage"].strip().lower(); amt = money(r["amount"])
    quiet = (TODAY - (day(r["last_activity_date"]) or day(r["created_date"]))).days
    held = (TODAY - day(r["stage_entered_date"])).days
    close = day(r["close_date"])
    flags = [f for f, on in (("stale", quiet > STALE[st]), ("stuck", held > STUCK[st]), ("overdue", close is None or close < TODAY),
                             ("no_next_step", not r["next_step"].strip()), ("no_amount", amt == 0)) if on]
    want[k] = dict(owner=owner(r["owner"]), amount=amt, quiet=quiet, held=held, flags=flags, stage=st.title(), account=r["account"].strip(),
                   level="at_risk" if len(flags) >= 2 else "watch" if flags else "healthy")
path = root/"output/deal_flags.csv"
if not path.exists():
    say(False, "output/deal_flags.csv was not written"); sys.exit(1)
rows = list(csv.DictReader(path.open())); got = {(r.get("deal_id") or "").strip(): r for r in rows}
n = len(want)
def val(k, col): return (got.get(k, {}).get(col) or "").strip()
def num(text):
    try: return float(text.replace(",", "").replace("$", ""))
    except ValueError: return None
say(set(got) == set(want) and len(rows) == n, f"{len(set(got) & set(want))} of {n} open deals appear once in deal_flags.csv and {len(set(got) - set(want))} closed deals appear")
days = sum(1 for k, w in want.items() if num(val(k, "days_since_activity")) == w["quiet"] and num(val(k, "days_in_stage")) == w["held"])
say(days == n, f"{days} of {n} deals have the day counts worked out again from the dates in the export")
fl = sum(1 for k, w in want.items() if [f.strip() for f in val(k, "flags").split(";") if f.strip()] == w["flags"])
say(fl == n, f"{fl} of {n} deals carry exactly the flags the rules give them")
lv = sum(1 for k, w in want.items() if val(k, "level") == w["level"] and val(k, "owner") == w["owner"] and (num(val(k, "amount")) or 0) == w["amount"]
         and val(k, "stage") == w["stage"] and val(k, "account") == w["account"])
say(lv == n, f"{lv} of {n} deals have the right level, owner name, stage, account and amount")
review = (root/"output/review.md").read_text() if (root/"output/review.md").exists() else ""
def line_has(label, count, total):
    for ln in review.splitlines():
        if label.lower() in ln.lower():
            nums = [float(x.replace(",", "")) for x in re.findall(r"\d[\d,]*(?:\.\d+)?", ln)]
            if count in nums and any(abs(x - total) < 0.005 for x in nums): return True
    return False
levels = {lv_: [w for w in want.values() if w["level"] == lv_] for lv_ in ("at_risk", "watch", "healthy")}
ls = sum(1 for name, ws in levels.items() if line_has(name, len(ws), sum(w["amount"] for w in ws)))
risk = levels["at_risk"]
say(ls == 3, f"review.md gives the right count and total for {ls} of 3 levels, with {len(risk)} deals and {sum(w['amount'] for w in risk):,.2f} at risk")
os_ = sum(1 for t in TEAM if line_has(t, len([w for w in risk if w["owner"] == t]), sum(w["amount"] for w in risk if w["owner"] == t)))
say(os_ == len(TEAM), f"review.md gives the right at-risk count and total for {os_} of {len(TEAM)} owners")
ids = [k for k, w in want.items() if w["level"] == "at_risk"]
pos = [review.find(k) for k in sorted(ids, key=lambda k: -want[k]["amount"])]
amounts = [want[k]["amount"] for k in sorted(ids, key=lambda k: review.find(k))]
say(all(p >= 0 for p in pos) and amounts == sorted(amounts, reverse=True), f"review.md lists {sum(1 for p in pos if p >= 0)} of {len(ids)} at-risk deals, largest amount first")
NAMES = ["stale", "stuck", "overdue", "no_next_step", "no_amount"]
def row_ok(k):
    ln = next((x for x in review.splitlines() if k in x), ""); w = want[k]
    return (w["account"] in ln and w["owner"] in ln and any(abs(x - w["amount"]) < 0.005 for x in figures(ln))
            and [f for f in NAMES if re.search(r"\b" + f + r"\b", ln)] == w["flags"])
shown = sum(1 for k in ids if row_ok(k))
say(shown == len(ids), f"{shown} of {len(ids)} at-risk deals are listed in review.md with their own account, owner, amount and flags")
whole = set(figures(rules)) | {x for t in typed.values() for x in figures(t)}
base = {float(len(ws)) for ws in levels.values()} | {sum(w["amount"] for w in ws) for ws in levels.values()} | {float(n), float(raw), float(closed), float(len(keep)), float(sum(1 for t in typed if t not in keep))}
base |= {float(len([w for w in risk if w["owner"] == t])) for t in TEAM} | {sum(w["amount"] for w in risk if w["owner"] == t) for t in TEAM}
dup = {}
for r in csv.DictReader((root/"input/open_deals_export.csv").open()): dup[r["deal_id"]] = dup.get(r["deal_id"], 0) + 1
base |= {float(sum(1 for v in dup.values() if v > 1)), float(sum(v - 1 for v in dup.values()))}
every = (root/"input/open_deals_export.csv").read_text() + rules
claims = good = 0
for ln in review.splitlines():
    named = [k for k in re.findall(r"\b[A-Za-z]+-\d+\b", ln) if k in typed]
    allowed = set(base) | (whole if not named else set())
    for k in named: allowed |= set(figures(typed[k])) | ({want[k]["amount"], float(want[k]["quiet"]), float(want[k]["held"])} if k in want else set())
    for x in figures(ln): claims += 1; good += any(abs(x - a) < 0.005 for a in allowed)
    for d in re.findall(DATE, ln): claims += 1; good += d in (" ".join(typed[k] for k in named) if named else every)
say(claims > 0 and good == claims, f"{good} of {claims} numbers and dates in review.md are a count or total worked out again, or a value from the row of a deal named on that line")
sys.exit(0 if ok else 1)

deal_review_rules.md: sample data written by Atris. Fingerprint e0fb2d7efbeb.

open_deals_export.csv: sample data written by Atris. Fingerprint 47b3bef4a30b.

deal_flags.csv: written by the agent. Fingerprint 201a72414ed5.

review.md: written by the agent. Fingerprint 0ce174bc7194.


More sales work, and every other desk job

For agentsGitHub
What is AtrisBlogApp StorePricingPrivacyTerms