-
-
One messy payment and its characteristics
-
Decision on the single payment and the reason why
-
Uploaded a sample set of failed payments (up to 50 rows).
-
Decision made on the payments and the reason, including categorising it on the type of decisions made
-
The evaluation table: Result on completion of the 3rd test (150 cases: 30 known codes, 120 messy) and on how ar3 handled it
-
Some more information on cases AR3 got wrong (3) and Nemotron tiers on the 120 messy cases + the result of the first 2 tests (run 1 and 2)
Inspiration -
I first built AR3 for a payments buildathon (after August 26th so its a new project) with a single LLM call deciding what to do with a failed payment. It worked in the demo, but it had a flaw I couldn't ignore: the model once invented an action that didn't exist ("REROUTE_TO_CARD") and the code passed it straight through. For anything that touches money, "the model said so" isn't good enough.
The problem itself is real. When a UPI or card payment fails, gateways already retry, but many failures come back vague. UPI's U30 just says "debit failed". Retry blindly and you waste attempts and annoy the bank and the customer; give up and you lose the sale. I wanted a layer that says what to do next, explains why, and knows when it doesn't know.
What it does -
You give AR3 a failed payment (method, live checkout or recurring, error code, description, attempt number). It recommends one of five actions: retry through another acquirer, retry later, ask the customer, stop, or send to a person. Every recommendation comes with a reason and the path it took.
- Known error codes go to a rule table: instant, free, predictable.
- Unknown or messy errors go to NVIDIA Nemotron on Nebius Token Factory. Nemotron Nano answers first; if its answer is invalid or below 0.7 confidence, Nemotron Ultra gets a look; if both are unsure, it goes to a person.
- Ten independent safety checks run on every decision and can overrule it: never retry fraud or a dead card, retry cap, minimum wait, no prompting a customer who isn't there, and two checks that read the raw error text so a wrong diagnosis can't cause a risky retry.
AR3 only recommends. It never moves money.
The demo lets you decide one payment and see exactly how the decision was made, run a batch from a CSV, and read the full evaluation.
How I built it -
Python, Pydantic and Streamlit, with Nemotron through Nebius Token Factory's OpenAI-compatible API.
- schemas.py: Pydantic models for a failed payment and a decision. The model can only answer with one of the allowed categories and actions, so an invented action is rejected.
- rules.py: the rule table for known card and UPI codes, with different actions for live checkout and recurring payments.
- llm.py: the two-tier Nemotron diagnosis with a safe fallback. Any timeout, bad JSON or invalid answer becomes "send to a person", never a crash.
- policy.py: the safety checks. Each one runs on every decision and every override is recorded.
- engine.py: rules, then Nemotron, then safety checks, then retry details (idempotency key, alternate acquirer). 45 tests with a fake model, so they run free, offline and in seconds.
- evaluate.py: runs 150 labelled failed payments through three policies (retry everything, rules only, full AR3) and compares the Nemotron tiers.
The results -
On 150 labelled payments (30 known codes, 120 messy errors):
- AR3 with Nemotron: 98% correct decisions, 0 unsafe actions, 11% sent to a person.
- Rules only: 31% correct, 80% sent to a person.
- Retrying everything once: 33% correct, 50 unsafe actions.
Nemotron Nano decided 69% of payments, the rule table 20%, Ultra 1%. Median time on a messy case: 0.9 s.
Challenges I ran into -
- Confidence isn't evidence. Early on I ran the same vague U30 payment through Nemotron Nano with reasoning on and off, at temperature 0. With reasoning off it said "hard decline" at 0.95 confidence; with reasoning on it said "gateway glitch" at 0.85. Same input, opposite answers, both confident. That's why AR3 never lets the model decide alone, and why U30 now goes Nano (unsure) → Ultra (unsure) → a person.
- My first full evaluation scored 87%. All 20 mistakes were the model stopping when it should have retried later or asked the customer. It diagnosed correctly but didn't know which action each category gets. Adding the action table to the prompt took it to 97%.
- That run had one unsafe action. The model called a compliance hold a temporary bank problem, so the "never retry risk" check, which trusts the model's category, never fired. I added checks that read the error text itself. Final run: 98%, 0 unsafe.
- Being honest about the numbers. Those fixes were found on the same test set they're measured on, so I say so in the README and list the three cases AR3 still gets wrong.
- Practical ones: reasoning tokens count against max_tokens, so long reasoning cut answers off until I raised the limit; Windows Smart App Control blocked pytest and pandas locally, so the demo runs on Streamlit Community Cloud.
Accomplishments I'm proud of -
- Zero unsafe actions on 150 cases, against 50 for "retry everything".
- Every decision shows its path: which step decided, which safety check changed it, and why.
- The evaluation is one command (python evaluate.py --tiers), and the earlier, worse runs are kept in the repo.
What I learned -
- A bigger model isn't automatically better. On this task Nemotron Ultra wasn't more accurate than Nano (94% vs 97%), and it was slower and used more tokens, so Ultra is only an escalation tier.
- Measuring changes what you build. Each improvement came from reading the failures, not from guessing.
- Safety checks shouldn't depend only on the thing they're checking. Checking the raw error text as well as the model's diagnosis is what got unsafe actions to zero.
What's next for AR3 -
- A held-out test set, and real outcome data from merchants.
- Calibrate Nemotron's confidence against real outcomes and set the threshold from data.
- An API endpoint that accepts gateway "payment failed" webhooks.
- An outage detector that pauses retries to a bank that's down.
- I reached out to 29 people, including 22 founders across 17 Indian fintech and consumer startups that collect payments. No replies yet; their answers will shape what comes next.
Built With
- nebius-token-factory
- nvidia-nemotron
- pydantic
- pytest
- python
- streamlit