← All work(01) / (04) · Case study

Banking compliance agent.

An agent that knows when it doesn’t know. It reviews loan agreements against the FCA Consumer Duty, cites its evidence and hands uncertain cases to a person.

RoleAI / ML Engineer
StackAI — Claude API · MCP · LlamaIndex · PydanticData — ChromaDB · local embeddings (bge-small)Ship — Streamlit · Docker · pytest · GitHub Actions CI
DataFCA Consumer Duty corpus · 34 synthetic loan agreements
StatusFixed workflow and agentic tool loop both evaluated live · live demo online
0Missed breaches · fixed workflow, 15 synthetic agreements × 3 runs
540/542Cited quotes found in the excerpt they named
8 / 8Wrong verdicts fell where the 3 runs disagreed
316Tests · 276 offline, 40 live against the Claude API
01 · The problem

Why it needs to exist

Pointing an LLM at a loan agreement and asking “is this compliant?” creates a worse problem than it solves. A confident wrong answer about regulatory compliance isn’t a quirky bug. It’s the failure mode.

Compliance review of consumer credit documents is still mostly manual: someone reads the agreement, reads the relevant FCA guidance, and judges whether the two line up. It’s slow, and two reviewers can reasonably disagree.

The core design problem is making the “I don’t know” case work as reliably as the “yes, compliant” case: grounding every claim in real regulatory text, and routing anything uncertain to a person.

02 · How it works

One document, five steps

  1. 01

    Extract the terms

    Lender, borrower, amount, APR, term, fees and clauses pulled into a validated schema.

    1 LLM call · Pydantic
  2. 02

    Retrieve the regulation

    One query per Consumer Duty outcome against 344 pages of FCA text.

    ChromaDB · top 5 · local embeddings
  3. 03

    Judge each outcome

    A verdict per outcome, with reasoning and verbatim quotes as claims.

    4 LLM calls · structured output
  4. 04

    Validate deterministically

    Confidence comes from retrieval quality, never the model’s self-report. Below 0.65, the verdict becomes “insufficient evidence”.

    No LLM call
  5. 05

    A person decides

    Every case lands in a review queue. Overrides need a written reason; decisions are append-only and audited.

    Streamlit · audit log
Honest noteThis is a fixed workflow: the code, not the model, decides each step. It is the evaluated baseline the agentic version was measured against.
Live demo · try itAlways on · synthetic data · no sign-in
01

See what it found

The Compliance overview, in plain language: 34 test loan agreements, what was flagged per Consumer Duty outcome, and how often it was right against known answers. Switch between the AI agent and the fixed workflow.

02

Follow one agreement

Try a sample replays a real recorded review step by step: what code decides first, what the AI looked up, each verdict with its quoted regulation, and the answer key.

03

Be the reviewer

In the review app, open a case and confirm or override each verdict. An override without a reason is refused; resolving before every item is decided is refused. The rules are enforced in code.

Open the live demo →Review app & dashboard (Streamlit) ↗Nothing you do on either calls a model or touches real data. The review app may take about 30 seconds to wake.
Agentic tool calling · live resultsRun live · 72 runs · about $9

The model chose its tools well

Over MCP it chose among search_regulation, get_account and search_policy. Every required call was made, with the right customer number every time. There were 10 unnecessary calls, all on other lenders’ agreements, and code flagged every one.

But it was worse at verdicts

On the same 15 agreements, consumer understanding fell to 0.533 accuracy against the fixed workflow’s 0.907, with 2 missed breaches against none (6 missed in total across all 34 agreements, all in consumer understanding). Its errors repeated in every run (12 of 13), so run disagreement no longer caught them.

So code now decides first

Escalation was right in 50 of 57 runs. All 7 errors were cases that can’t be decided, and 6 of them were called “no escalation”. Code now sets “cannot determine” by rule and sends it to a person, and other lenders’ agreements never get the account or policy tools.

The result: a fixed workflow for compliance verdicts, an agentic step only where judgment is needed, and code-level rules before both. Every case still goes to a person. The rules were written after seeing these failures, so they still need testing on unseen documents.

03 · Decisions

What I chose, and what I rejected

D1

A fixed workflow firstover an agent choosing its tools

The clever version needs a baseline to beat. The agentic loop was only evaluated live once the fixed workflow’s numbers existed, and it lost on verdicts, so verdicts stayed with the fixed workflow.

D2

Retrieval (RAG)over fine-tuning

Regulation changes, and every claim needs traceable evidence. Retrieval keeps the source text one click away.

D3

One workflow + a deterministic validation layerover a multi-agent swarm

Fewer moving parts to audit. The checks that matter run as plain code, not another model call.

D4

Confidence from retrieval similarityover the model’s self-reported confidence

A model saying it’s sure isn’t evidence. The routing signal is measured, and below threshold the case goes to review.

D5

Auto-approval offover skipping review for “easy” outcomes

Zero misses on 13 approved documents still leaves a 95% upper bound of 20.6%. Showing a 5% miss rate would take 59.

04 · Results

Full pass: 15 docs × 3 runs

Consumer Duty outcomeAccuracyFalse alarmsMissed breachesAbstained
Price and value0.978100
Consumer support0.933300
Products and services1.000000
Consumer understanding0.907402

How to read this. Accuracy is the judge’s verdict before the 0.65 confidence override, with abstentions excluded. A false alarm is a compliant document flagged as possibly non-compliant (8 in total). A missed breach is a planted defect the judge called compliant.

52 / 60

Unanimous pairs, and none of them wrong

Across 60 document–outcome pairs, all 3 runs agreed 52 times. Every one of the 8 wrong verdicts, and both abstentions, sat in the 8 pairs where runs disagreed.

≤ 0.0123

What didn’t work: the confidence score

Mean confidence for right and wrong verdicts differs by at most 0.0123. At 0.65 it still routes 62.5% of wrong verdicts to review, which is the safety property, and it sends half the correct verdicts to review too, so it is not a correctness detector. Disagreement between runs did better: the 3 runs disagreed on 8 of 60 document–outcome pairs, and all 8 wrong verdicts were among them. That held for the fixed workflow only; the agent’s errors repeat across runs. This is a finding from the saved runs, not yet a routing rule, and it is measured on 15 synthetic agreements.

05 · What went wrong

Failures, and what changed

Silent failure

A “successful” run of 5,540 garbage chunks

A missing dependency made the PDF reader index raw PDF bytes as text. No error was raised. I found it by opening sample chunks and reading them.

What changedDependencies fixed (558 real chunks), and ingestion now runs content checks and a retrieval smoke test before it can replace the live index.
Structured output

Parallel tool calls broke two runs

The model returned several tool calls at once, and structured calls failed with HTTP 400s.

What changedStructured calls now force a single tool call. No failures since.
Known limitation

49 judge calls came back malformed

Arguments arrived wrapped in a literal placeholder key. All 49 recovered on an automatic retry.

StatusNot fixed, and documented rather than hidden.
06 · Scope

What this does and doesn’t prove

It does show

  • Grounded claims: 540 of 542 quotes located in their cited excerpts
  • Zero missed breaches by the fixed workflow on planted defects (the AI agent missed 6, all in consumer understanding)
  • Every case reaches a person: auto-approval is off
  • Failures are found, fixed and written down

It doesn’t show

  • Performance on arbitrary real-world agreements: all 34 are synthetic
  • Coverage beyond Consumer Duty: CONC isn’t indexed
  • Any affordability judgment: not attempted
  • That review can be skipped: auto-approval stays off