MAAI902 · NLP & LLMs · Solution design

Ledger

A system that reads UAE bank SMS alerts, works out what each purchase was for, knows when it isn't sure, and answers questions like "how much did I spend on food in May?" with numbers you can trace.

The data

Real messages, five banks

19,641bank SMS
11,368usable expenses
1,930distinct merchants
94%human audit agreement (κ 0.93)

Five people's SMS (ADCB, Liv, Mashreq, FAB; 2022–2025) for training and testing, plus Khalifa University's public ADIB dataset as an outside test the model never trains on. Names, card numbers, IBANs, OTPs and references were masked before any analysis. No raw data is published here; the per-user views on the dashboard are pseudonymised and password-protected.

How it works

Categorise, then answer

Architecture diagram. Stage 1: SMS are parsed, cleaned and passed through a four-tier cascade (lookup, rules, calibrated model, proposed LLM tier) with a user-review fallback, into a SQLite table. Stage 2: a question is turned into one SQL query by a local LLM, checked by a read-only guard, and answered from the table.
Tier 1

Lookup

Known merchants reuse their label, including your own corrections.

Tier 2

Rules

Brand and keyword rules for the obvious ones: ADNOC, DEWA, "…PHARMACY".

Tier 3

Calibrated model

Character n-gram TF-IDF with logistic regression, calibrated on merchants it has never seen.

Fallback

Ask once

Low confidence? Best guess plus a review flag. Your answer is remembered.

Results · macro-F1

The honest number is the low one

Random splits reuse the same merchants in training and testing, which is why they look so good. An exact-lookup baseline scores 4.1% on brand-new merchants; the model keeps 51.2%. Brand knowledge (an LLM or fine-tuned encoder) is the next tier.

Confidence you can trust

0.7–0.8 → right 95% of the time

Calibrated on unseen merchants. At a 0.60 threshold, 31% of brand-new-merchant purchases are filed automatically at 91% accuracy; the rest are asked about.

Error analysis

The McDonald's-at-ADNOC bug

132 restaurant purchases at petrol stations had been labelled as fuel. Fixing them lowered the new-merchant score from 53.3% to 51.2%, and the lower number is the honest one.

The spending assistant

Questions in, SQL out, numbers from the data

Public prototype

Try it with your own bank export

Upload a CSV and ask questions about it. Cleaning, categorising, the SQL database and the optional Qwen2.5-1.5B model all run inside your browser, so the file never leaves your device. No file handy? Use the synthetic sample household.

"How much did I spend on food and dining in May 2025?"

SELECT ROUND(SUM(amount_aed),2)
FROM expenses
WHERE user='U12'
  AND category='Food_Dining'
  AND month='2025-05'

→ 692.20 AED, read from the database, with the SQL shown.

Guard rails

A small local LLM (Qwen2.5-1.5B-Instruct) only writes one query. A guard accepts a single read-only SELECT, blocks DROP / UPDATE / PRAGMA and runs on a read-only copy with a time limit. The LLM never types a number, and messages never leave the device.

67%correct SQL on 30 gold questions
75%on category questions
50%on controls (mostly bank vs merchant mix-ups)
0queries the guard had to reject

Do categorisation errors change the answers?

30 gold questionsKnown merchantsBrand-new merchants
Questions without categories ("How much at Amazon?")100%100%
Category questions ("food in May?")55% (median error 5%)5% (median error 89%)

One large misfiled purchase can swing a whole year's total, which is why the system asks about uncertain purchases instead of guessing quietly. Every question, both SQL queries and a live, guarded SQL box are on the dashboard.

Responsible by design

Your money, your phone, your call

Privacy

Masked before analysis, local LLM, code-only repository. Designed around the UAE PDPL.

Consent

Contributors asked; their data shared with markers only on request; public dataset cited.

No invented numbers

The LLM only writes guarded SQL, and the query is shown with every answer. Advice answers showed why: next, they go through fixed analysis tools.

Over-trust

Confidence shown, review flag, and advice clearly marked as not financial advice.

Materials

Notebooks and code

sms_transactions_pipeline.ipynbParsing five bank templates, cleaning, privacy tests
expense_categoriser_train_test.ipynbFive test set-ups, calibration, confidence cascade
spending_assistant.ipynbText-to-SQL assistant with guard rails, error propagation
Try it with your dataPublic prototype: upload a CSV, get your stats and ask questions, all processed in the browser
DashboardAll results, plus per-user spending, live SQL and the assistant replay (password-protected)

Runs in Google Colab. Code repository: available to markers on request. The data stays private.