MODULE 10 OF 10 · ~30 MIN · ADVANCED · LIGHT CODE

AI Operations & Monitoring in Treasury

Building the model was the easy part. Keep it accurate, tested and auditable in production.

What you'll cover
  1. 01The AI operations cycle, 3 types of drift and 8 KPIs for treasury AI
  2. 02Automation with Power Automate, a Power BI monitoring dashboard and 6 test types
  3. 03Audit trail, retraining triggers, and Microsoft Fabric for scale
You walk away with
  • A live model monitor with a retrain trigger
  • A pytest data validation suite
  • An audit trail record script

Building the model was the easy part

An often-quoted industry estimate says most machine learning models never make it into production (87% is the number you will see). The ones that fail rarely fail because the model is bad. They fail because operations are missing.

No monitoring

Forecast error drifts from 5% to 22% over 6 months. Nobody notices until the CFO asks why the forecast is always wrong.

No retraining

The business wins a major new customer. Cash flow patterns change. The model still predicts from the old data.

No testing protocol

Someone updates a Python library. The output format changes. The Excel macro downstream breaks. The morning report fails.

No audit trail

The auditor asks: which model version produced this forecast? When was it last validated? Who approved the parameters? Silence.

The treasury AI operations cycle

1
DEPLOY
Push the model to production
2
MONITOR
Track accuracy, drift, errors
3
ALERT
Trigger when a KPI breaches
4
DIAGNOSE
Root cause: data, model or config?
5
RETRAIN
Update the model with new data
6
TEST
Validate before redeploying

This cycle runs continuously, monthly at minimum. Not once.

Model drift: when your forecast goes stale

Data drift. The input data changes.

Example: A new customer segment with different payment patterns.

DetectCompare current input distributions with the training data.

Concept drift. The relationship between inputs and outputs changes.

Example: COVID permanently changed cash flow patterns. A pre-COVID model is obsolete.

DetectTrack forecast error over time. A rising trend means concept drift.

Feature drift. A feature disappears or changes meaning.

Example: The bank changes its MT940 format. Transaction codes shift. Feature extraction breaks.

DetectMonitor null rates per feature. A sudden spike means feature drift.

All three end in retraining, but the fix is different: data drift may mean fixing the source, concept drift a new model, feature drift a repaired pipeline.

The treasury AI KPI framework

KPIWhat it measuresTargetFrequency
Forecast error (MAPE)Average error vs actuals, on receipts and payments< 10%Weekly
Forecast biasOver- or under-forecasting tendencyWithin ±2%Weekly
Data freshnessAge of the input data at forecast time< 24 hoursDaily
Model uptime% of scheduled runs completed> 99%Monthly
Exception rate% of outputs needing manual correction< 5%Weekly
Retraining frequencyHow often the model is retrainedMonthly minimumMonthly
Drift scoreStatistical distance: current vs training dataBelow your thresholdMonthly
Audit completeness% of AI outputs with a full audit trail100%Monthly

For net flow, which crosses zero, track the average error in EUR instead of MAPE (Module 9).

Automation: Power Automate for treasury AI

Four patterns. Each is a trigger and an action, built visually.

Scheduled, 8am daily

Run the Python forecast script
→ Forecast CSV saved to SharePoint

New bank file received

Parse the statement, match against the ERP, flag exceptions
→ Exception report emailed to the analyst

KPI threshold breached

Forecast error above 10% for 3 consecutive weeks
→ Alert to the Treasury Manager + retrain flag

Month end (1st business day)

Generate the reconciliation report, compile board pack data
→ Draft board pack to the Treasury Director for review

Where does the Python run? A cloud flow cannot run a script on your laptop. Host the script in an Azure Function (or Azure Automation), or run it on a machine through a Power Automate Desktop flow. Triggering a desktop flow from a cloud flow needs a premium (RPA) licence. Agree this with IT before you promise a daily run.

Power BI: the model performance dashboard

Error trend line

Weekly forecast error over the last 12 months. Green below 7%, amber 7–10%, red above 10%. Shows degradation over time.

Forecast vs actual

Predicted vs actual per week. The gap is the error. The visual for non-technical stakeholders.

Bias indicator

A gauge for over- vs under-forecasting. Centered is good. Skewed is a systematic error to correct.

Data quality scorecard

Completeness, freshness and null rates per source. Red flags fire before they hit the forecast.

The same four panels appear in the live monitor later in this module, so you can see what they tell you before you build them in Power BI.

Testing framework: what to test, when

TestWhat you checkWhenTool
UnitEach function produces the expected outputEvery code changepytest
Data validationInput passes the Module 8 quality checksEvery runpytest / Great Expectations
AccuracyError metrics within thresholdsWeeklyPython script + Power BI
RegressionThe new model version is at least as accurate as the oldBefore redeploymentBacktest (Module 9)
IntegrationEnd to end: data in > model > report outMonthlyPower Automate test flow
StressExtreme scenarios: 2x volume, missing dataQuarterlySynthetic data injection
A data validation suite in 22 lines · tested

Five checks on the Module 8 clean dataset. Save it next to the CSV and run python -m pytest test_cash_data.py (install with pip install pytest). All five pass on the clean file. Run it on a file where missing receipts were interpolated and the reconciliation test fails, which is exactly its job.

test_cash_data.py
import pandas as pd

FLOWS = ['receipts', 'supplier_payments', 'payroll', 'tax', 'intercompany', 'other']

def load(path='treasury_cash_flows_clean.csv'):
    return pd.read_csv(path, parse_dates=['date'])

def test_no_missing_values():
    assert load()[FLOWS].isnull().sum().sum() == 0

def test_no_duplicate_weeks():
    assert not load()['week_number'].duplicated().any()

def test_weeks_are_consecutive():
    assert (load()['date'].diff().dropna() == pd.Timedelta(days=7)).all()

def test_net_flow_reconciles():
    df = load()
    assert ((df[FLOWS].sum(axis=1) - df['net_flow']).abs() < 1).all()

def test_payments_are_negative():
    assert (load()['supplier_payments'] <= 0).all()

The AI audit trail: what to document

FieldExampleWhere stored
Model versioncash-forecast v1.3 (Prophet), trained 2026-03-01 on 52 weeksModel registry / SharePoint
Input data hashSHA-256 of the input CSV. Proves which data was used.Alongside the output file
Parameterschangepoint_prior_scale 0.05, regressors: payroll, taxConfig file in version control
Output summary13-week forecast, backtest error, 2 breach weeks flaggedLog database / Excel log
ValidationReviewed by the Treasury Manager (name), approved 2026-03-15 08:42Sign-off log
DeviationsManual override, week 45: +EUR 200K (new contract)Override log with justification
An audit record per run · tested

Run after the Module 9 script. It hashes the input and the output and appends one line per run to audit_log.jsonl. Reviewer and approval stay empty: a human fills them in at sign-off, never the script. No Python at hand? On Windows, Get-FileHash file.csv in PowerShell gives the same SHA-256.

m10_audit.py
import hashlib, json, os
from datetime import datetime, timezone
import pandas as pd
import prophet

def sha256(path):
    with open(path, 'rb') as f:
        return hashlib.sha256(f.read()).hexdigest()

fc = pd.read_csv('forecast_13_weeks.csv')
record = {
    'run_at': datetime.now(timezone.utc).isoformat(timespec='seconds'),
    'model_version': 'cash-forecast v1.3',
    'library': f'prophet {prophet.__version__}',
    'input_file': 'treasury_cash_flows_clean.csv',
    'input_sha256': sha256('treasury_cash_flows_clean.csv'),
    'parameters': {'changepoint_prior_scale': 0.05, 'regressors': ['is_payroll_week', 'is_tax_week'],
                   'train_weeks': 52, 'one_offs_excluded': [38]},
    'output_file': 'forecast_13_weeks.csv',
    'output_sha256': sha256('forecast_13_weeks.csv'),
    'breach_weeks': int((fc['pessimistic_status'] == 'BREACH').sum()),
    'reviewed_by': None,          # filled in at sign-off, never by the script
    'approved_at': None,
}
with open('audit_log.jsonl', 'a') as f:
    f.write(json.dumps(record) + '\n')
print(json.dumps(record, indent=2))

Retraining: when and how

Scheduled (monthly). Add the latest 4 weeks, retrain, compare the backtest with the previous version. Deploy only if it is as good or better.

Drift alert (error above 10% for 3 weeks). Investigate first: data drift or concept drift? If data, fix the source. If concept, retrain with a longer window or different features.

Business event (major customer won or lost). Add the date as a changepoint and retrain on data from before and after the event.

Annual (full refresh). Rebuild from scratch: feature selection, parameter tuning, full backtest. Document everything.

Python · a business event as a changepoint
from prophet import Prophet

# A major customer was won on 2 March 2026: tell the model the trend may change there
m = Prophet(changepoints=['2026-03-02'])

Prophet takes changepoints as a list when you create the model. There is no separate "add changepoint" method (checked on Prophet 1.1.7 and 1.4). Never set and forget: retraining is maintenance, not failure.

LIVE BUILD

Build a monitoring dashboard with vibe coding

The Module 5 method, applied to AI operations. Paste the prompt into Claude (Artifacts) or any AI tool that builds interactive apps, then refine.

Prompt · monitoring dashboard
Build me an interactive AI Model Monitoring Dashboard as a React artifact.

PURPOSE: A treasury team monitors the performance of its cash flow forecasting model.

DATA: Pre-fill 12 weeks of simulated monitoring data. Each week has: week, forecast_receipts, actual_receipts, data_age_hours, exceptions_count. Make the actuals drift away from the forecast in the last 4 weeks.

CALCULATIONS:
- Weekly error % = |actual - forecast| / actual
- Running 4-week average error
- Bias % = sum(forecast - actual) / sum(actual)
- Status per week: GREEN (error < 7%), AMBER (7-10%), RED (> 10%)

VISUAL:
- Top row: 4 KPI cards (current error, 4-week average, bias, data freshness)
- Error trend line chart with green/amber/red zones
- Forecast vs actual comparison chart
- Data quality table with status indicators
- Alert section: weeks with error > 10% or data older than 24 hours

COLOR: Teal accent. Red/amber/green for status.
EXPORT: A CSV button for the full monitoring log.
Refinement · the retrain trigger
Add a banner at the top: 'RETRAIN RECOMMENDED' in red if the error has been above 10% for 3 consecutive weeks. Otherwise 'MODEL HEALTHY' in green. Make the actual values editable so I can test the banner.

The thresholds in the prompt match the KPI framework: target below 10%, green below 7%, and the same "3 consecutive weeks above 10%" rule that Power Automate alerts on. One rule everywhere, or your dashboard and your alert will disagree.

LIVE BUILD · RESULT

The monitor, live

12 weeks of receipts forecast vs actual (EUR K). Edit any actual and watch the KPIs, statuses and banner update.

Current error
4-week average
Bias
Data age, latest
WeekForecastActualErrorAgeStatus
W18466h
W28495h
W38517h
W48546h
W585730h
W68606h
W78635h
W88666h
W98697h
W108726h
W118755h
W128776h

    What it shows: actual receipts fall from week 6 while the forecast keeps rising. That is drift, most likely a customer lost or paying later. The bias confirms it: the model over-forecasts. Diagnose before you retrain.

    Microsoft Fabric for treasury AI at scale

    When you outgrow Excel + Python + Power BI, Fabric brings it together. You do not need it today. You will when you run several models across many entities with frequent retraining.

    Data Factory. Automated pipelines that pull bank feeds and ERP data on a schedule.

    Replaces: Manual downloads + Power Query

    Lakehouse. All treasury data in one place, structured and unstructured.

    Replaces: Many Excel files on shared drives

    Notebooks. Python and SQL directly on the lakehouse data: pandas, Prophet, ML.

    Replaces: Local Python + manual data transfer

    Power BI (integrated). Dashboards connected straight to the lakehouse.

    Replaces: Separate Power BI + manual refresh

    ML models. Train, register and deploy models with versioning built in.

    Replaces: Model files on a drive, no versioning

    What you take away

    01

    Building the model is the small part of the work. Operating it is the large part.

    02

    The operations cycle: DEPLOY > MONITOR > ALERT > DIAGNOSE > RETRAIN > TEST.

    03

    3 types of drift: data, concept, feature. Monitor all three.

    04

    8 KPIs for treasury AI, with one threshold rule used everywhere.

    05

    Power Automate for scheduling and alerts; Power BI for dashboards the whole team can read.

    06

    6 test types, starting with a data validation suite that runs on every file.

    07

    An audit trail per run: model version, data hash, parameters, output, validation, deviations.

    08

    Retraining: monthly, drift-triggered, event-based, and an annual full refresh.

    09

    Microsoft Fabric when you are ready to scale.

    ✓ AI in Treasury Academy complete

    You started as a user. You finish as a builder.

    Ten modules, from where AI works in treasury to building and operating AI systems.

    M1The AI Treasury Map and Risk Matrix
    M2T.R.A.C.E. and a 20-prompt library
    M3INGEST > PROCESS > VALIDATE > OUTPUT
    M4A 5-pillar AI policy and your ROI case
    M5Vibe coding: your own treasury tools
    M6A scorecard for any AI model
    M7Inventory, 3 controls, 30-day plan
    M8Clean treasury data, 6 checks
    M9A backtested 13-week forecast
    M10Monitoring, testing, audit trail

    The only thing left is execution. Start this week.

    Built by a treasurer, for treasurers. · treasuryease.com