Building Analytics With AI Agents: Silent Errors and How to Catch Them
AI coding agents wrote most of our loan analytics platform. Their mistakes never crashed anything; they produced numbers that looked right. This article walks through the five agent habits behind those errors with real examples from our build, then offers a starter kit of rules and prompts any analyst can reuse.
Nancy Li10 min read
I spent many years leading the Credit Analytics team at BHG Financial and, before that, the Investor Analytics team at LendingClub, where most of the hours went to pulling, cleaning and charting data before anyone got to the insight. When we built our own loan analytics platform at Shreem Insights, AI agents did much of that work, and they were very good at it. They were also wrong in a new way: they never crashed and never doubted. One of our loss curves showed a 98% default rate in month 46 of a 36-month loan. The tests passed, the chart rendered, and nothing flagged it.
This article is for analysts who are starting to use agents, whether for a notebook, a SQL pipeline, a dashboard or a full application. It begins with how we split the work between agents and people, then walks through the five agent habits behind errors like that 98%, using real examples from our build and the check that catches each one. It ends with a starter kit you can set up this week.
Who does what
Agents write the plumbing, the interface, the tests and the first drafts. People own the data judgment, the definitions, the conventions, and the review of every number.
The platform itself is split along the same line, into two layers. The engine is a separate service that computes every risk and return number, and the application calls it and then displays, arranges and exports what comes back. The application never computes a risk or return number of its own, so every model lives in one place where people can review it. Habit 3 below shows what happened before we drew that line.
Five habits behind the silent errors and how we check
The five habits below show what an agent does with the things nobody told it. Each one produced numbers in our build that looked right, and each comes with the check we now use to catch it, starting with the 98% default rate.
1. "It runs" isn't "it's right"
The 98% came from curves that ran ten months past term, where so little balance is left that a few defaults produce an enormous rate. Nothing in the agent's loop knows that a 98% default rate after maturity is absurd.
The fix had its own trap. A vintage mixing 36- and 60-month loans can average 48 months, a term no loan has. A curve that ended at that average cut the 60-month loans off a year early.
Smaller things slip through the same way. Our term mix labelled its buckets "36 mo", and the agent's code tried to read that label as a number. It got nothing back, so the weighted average term showed up blank and the slide that looks for the 36-month row never found it. There was no error, only a missing line.
Check: before trusting any rate, look at its denominator. Set one end rule per measure, write it in the agent's rules file (the starter kit below shows one), and use it on every chart. Our default rates stop at term, and our cumulative measures run four months past it to allow for charge-off timing. Never end a curve at the average of a mixed group.
2. It trusts the data as delivered
If you hand an agent a loan tape and ask for prepayment speeds, it will be grouping by vintage within a minute. It takes each field at its name and never asks how the field was populated. Loan data rarely survives that.
Prepayments are one example. A loan that makes its last scheduled payment at maturity is paid off, not prepaid, but both show up as a loan with a zero balance and a "paid in full" status. One prepayment analysis counted every such loan as a prepayment, which pushed prepayment speeds up in exactly the months when loans were simply reaching term on schedule.
Updated FICO is another trap. The column promised a refreshed score each month, but where no new bureau pull existed, the gap had been filled with an earlier score. A borrower whose credit had not been checked looked like a borrower whose credit had not changed, and any analysis of credit migration inherited that false stability.
Missing bureau data is the third. Some loans have no bureau attributes at all, because the borrower had a thin file or the pull failed. An agent will fill those blanks with zero or the average, or quietly drop the loans, and each choice moves a different segment.
Even the shape of a clean tape can mislead. A vintage's payment due dates are spread across the month, so at the data cut-off, its latest month on book only contains the loans whose due date has already passed. The rest haven't reached that month yet. With the whole vintage's origination as the denominator, delinquency in that month fell, and the newest data looked like the best data.
Most of the time the agent never notices. When it does, it fixes the problem on the spot by relabelling, filling or dropping, and then it keeps going. Either way, the data quality decision becomes an assumption nobody made on purpose.
Check: make data profiling and validation a separate step before any analysis, using the profiling prompt in the starter kit. As any experienced analyst would, the agent should understand the data before it draws insights or builds models. Have it explain how each key field is populated, not only what it is called, and flag every anomaly with loan counts and balances without attempting to fix any of them. Decisions on how to handle each one stay with the analyst, and they should be written down.
3. It calculates the same number in more than one place
When a page needs a number, the shortest path is to compute it right there. Early on, our application carried its own copy of the loss and IRR math alongside the engine's. We deleted it, and we made the app show an error when the engine fails rather than fall back to the copy. A fallback to a different model keeps the page running, but it shows numbers from a model nobody chose.
Copies also grow between pages. Return and Valuation each built their own cash flows after fees. Return held back every recovery for the collection lag, including recoveries already on the tape, so those were paid a second time months later. Valuation handled it correctly, and each page looked fine on its own.
Check: decide where each number is calculated and put it in the rules file. Ours is a single line saying that the application never computes risk or return numbers and always asks the engine. Then tie out the results, so the same total appears under the same name on every page, tab and download.
4. It makes choices and doesn't tell you
A 1% monthly IRR is 12.00% annualized by multiplying by 12, and 12.68% by compounding. Both are defensible. Our reference analysis used one, the application used the other, and nobody noticed until the two sat side by side.
Agents choose defaults the same way. Our overview trends quietly read only vintages with six or more months on book. That sounds reasonable, but the newest vintages are the ones clients ask about first, and the trend lines simply stopped early without saying why.
Check: put every convention that moves a number in the rules file, such as how IRR is annualized, whether month on book starts at 0 or 1, what the loss-rate denominator is, when a loss counts, and whether recoveries are gross or net. Before any calculation, ask the agent which conventions, defaults and filters it plans to use. Count vintages, loans and balance going into and out of every step. Name every exclusion on the page.
5. It loses the thread
An analyst who changes a method knows what else is touched. An agent sees only the task it is on. When our forecast moved to a transition-matrix model, the page kept a historical-vintages slider the new model ignored. It still looked live. A collection-fee input sat on the Return page, but our IRR never used it.
Long sessions make it worse. Late in a session, an agent can forget a decision made at the start, and a new session starts from zero.
Check: ask for one change at a time, say what not to touch, and read the difference. After any change, ask what depends on it, move every input to confirm the output moves, and open the final deliverable. Record each decision in the rules file so the next session starts from it.
A starter kit
The checks above are easiest to keep when they are written down before the agent starts, not remembered after something has gone wrong. This kit collects them into three parts, which are a rules file the agent reads every session, a handful of numbers you trust, and a few prompts to paste before an analysis, before coding, after a change, and whenever a number looks off.
1. A rules file the agent reads every session
Most coding agents load an instructions file from the project folder at the
start of every session. Claude Code reads CLAUDE.md, and Codex and several
others read AGENTS.md. Your analytics rules belong there, with the
brackets below filled in for your own data.
Data
- Before any analysis, profile the data and list anomalies with loan
counts and balances. Don't fix anything without asking.
- Never drop rows, vintages or segments without saying so. Print loan
count and balance before and after every filter and join.
Conventions
- Month on book: origination month is [0 / 1].
- Charge-off: a loan is a loss at [servicer flag / N days past due].
- Recoveries: [gross / net of fees], credited to [month collected /
month of charge-off].
- Loss rates: denominator is [original / outstanding] balance.
- IRR: monthly IRR annualized by [× 12 / compounding].
- Curves: rates end at [term]; cumulative measures at [term + N].
- If a convention isn't listed here, stop and ask.
Code
- Risk and return math lives only in [module / file]. Call it; never
rewrite it, and never fall back to a local copy when it fails.
- Search for an existing function before adding one.
- Every input must change the output. Remove the ones that don't.
- Change only what was asked. Don't rewrite labels or text.
Checks
- After changing any calculation, compare against [reference file]
and report every difference.
When you settle a question in a session, add it to the file. Otherwise the next session reopens it.
2. A few numbers you trust
The second part is a handful of numbers worked out by hand in a spreadsheet you can audit, such as one vintage's cumulative net loss at month 12, its lifetime IRR, and a pool total. That spreadsheet becomes the reference file named above. After every change to a calculation, the agent compares its results against it. A difference is either a fix you meant to make or a bug, and you'll know which.
3. Prompts to paste
Before any analysis, ask the agent to profile the data:
Profile
[file]. For each column, report the type, share missing, min, max and distinct values. Then list loan-level problems: duplicate loan-months, balances that rise without a modification, charge-offs with no charge-off date, payments after charge-off, loans that disappear before maturity, payoffs at or near maturity that could be mistaken for prepayments, refreshed fields such as updated FICO that never change, loans with missing bureau data, and months where a vintage is only partly observed. Give loan counts and balances for each. Don't fix anything.
Before it writes any code, ask what it plans to assume:
Before writing any code, list every convention, default, filter and cutoff you plan to use, and mark the ones you're unsure about.
After a change, ask it to show its work:
Show loan count and balance at each step, list anything excluded and why, and show [measure] for vintage [X] before and after your change.
When a number looks off, ask where else it lives:
Where else in this project is [measure] calculated or read? List every place.
Making the checks routine
Every error in this article passed its tests and rendered without complaint. Each one surfaced only when someone who knew how loans behave looked closely at the number. The starter kit turns that close look into steps the agent runs every time, so catching the next 98% does not depend on someone happening to notice it.