Calibration Check

Accuracy on held-out cases next to the model's own calibrated confidence, per field, with the individual cases behind each number. The snapshot a calibration monitor tracks over time.

Calibration Check: screenshot from the Accounting demo
🧾 Accounting_evaluateCross-vertical
In shortLive _evaluate on held-out invoices: accuracy and calibrated confidence side by side, with every test case inspectable.

The problem

Calibration drift is the silent failure mode of confidence-tiered automation. The system worked fine for months; the team got comfortable; usage grew; nobody noticed that the 95% confidence tier started producing errors at 5% instead of 1%. The first signal is usually a customer complaint, a tax filing correction, or an audit finding. By then the bad predictions are weeks old.

The remedy is monitoring the calibration over time, not just at one snapshot. ECE tracked weekly tells you whether 95% confidence still means 95% accuracy — and surfaces an alert before the tier degrades to where the team would notice.

How it works

The accounting demo's Prediction Quality view is one snapshot: _evaluate on held-out invoices (100 by default) of one tenant, returning accuracy against the base rate, the geometric-mean confidence, and every test case. Monitoring repeats that snapshot over time.

Calibration monitoring runs _evaluate on rolling windows (last 7, 30, 90 days) and tracks ECE per field over time. The system computes the moving average and the standard deviation; when the current week's ECE exceeds the historical average by N standard deviations, an alert fires.

Two failure modes get caught. Slow drift (data distribution shifts gradually, calibration degrades over weeks) shows up as a steady ECE rise; sudden drift (a chart-of-accounts reorganisation, a vendor migration, a product launch) shows up as a one-week spike. Both surface in the same dashboard; both warrant different remediation. Slow drift usually means re-tune thresholds; sudden drift usually means pause auto-process on affected fields until the new pattern accumulates.

{
  "testSource": {
    "from": "invoices",
    "where": {
      "customer_id": "CUST-0000"
    },
    "limit": 100
  },
  "evaluate": {
    "from": "invoices",
    "where": {
      "customer_id": "CUST-0000",
      "vendor": {
        "$get": "vendor"
      },
      "amount": {
        "$get": "amount"
      },
      "category": {
        "$get": "category"
      }
    },
    "predict": "gl_code"
  },
  "select": [
    "accuracy",
    "baseAccuracy",
    "accuracyGain",
    "meanRank",
    "geomMeanP",
    "testSamples",
    "trainSamples",
    "cases"
  ]
}

For the full architecture, see the technology overview. For the broader narrative across multiple use cases, read The Predictive Application. For the whole picture, see predictive accounting.

See it live

This use case runs in the 🧾 Accounting demo today. Click through to the live application and inspect the queries that produce the result.

Open the live demo →

Build it with Claude Code

Paste this prompt into Claude Code, or another coding agent, in your own codebase. It runs Aito locally from the Docker image, reads the API docs written for agents, and follows a working reference implementation.

Calibration check: a prompt for Claude Code
Add calibration check to this codebase using Aito, a predictive database. The feature: compare accuracy on held-out records with the predictions' own confidence, per field and per confidence band, with the individual cases behind each number.

1. Run Aito locally: `docker pull ghcr.io/aitohq/aito`, then follow https://aito.ai/docker/ to start it with your own API keys (keep them in the environment, never in code).
2. Read https://aito.ai/docs/api/llms.txt for the v2 query shapes before writing any query.
3. Read the use-case guide: https://aito.ai/use-cases/calibration-monitoring/
4. Use this reference implementation as the pattern (schema, data load and queries): https://github.com/AitoDotAI/aito-accounting-demo/blob/main/src/evaluation_service.py and https://github.com/AitoDotAI/aito-erp-demo/blob/main/src/overview_service.py and https://github.com/AitoDotAI/aito-accounting-demo/blob/main/src/data_loader.py
5. Find the matching tables in this codebase, design the Aito schema for them (links between tables where we have foreign keys), and load a sample.
6. Check the numbers before building the view: compare a few of them against a direct count over the same rows (SQL or a short script), and report any that differ.
7. In the UI, show the evidence behind each number (the counts, the interval or $why), and leave out patterns with too little data behind them.

Ask me before changing anything outside the new feature.

Frequently asked

What ECE threshold should trigger an alert?

Practical thresholds: ECE > 0.05 on the >95% confidence bucket is the warning level; ECE > 0.10 is the action level. These vary by field and stakes — high-stakes fields (GL coding, regulatory tags) warrant tighter thresholds than low-stakes fields (tag prediction).

How does this compare to standard ML model-drift monitoring (Evidently, WhyLabs)?

Standard model-drift tools monitor input-feature distributions and output distributions. Calibration monitoring is narrower: just calibration, just on the predictions you care about for automation. The two are complementary; teams that use both get input-drift early-warning AND output-calibration safety together.

Can we monitor calibration per customer in multi-tenant deployments?

Yes. ECE per customer_id, tracked over time. Useful when a single tenant's calibration breaks while the rest are fine — usually means tenant-specific data shift (chart-of-accounts change, vendor migration) that needs attention.

What happens when a calibration alert fires?

The application acts on the alert. Default behaviour: lower the auto-process threshold for the affected field by 5-10 percentage points. Manual review absorbs the uncertainty until the calibration recovers or the team investigates the root cause.

How quickly does calibration recover after a data-pattern shift?

Calibration recovery follows the same data-density curve as initial calibration. How quickly depends on how consistent the pattern is; watch the calibration curve for that slice rather than trusting a fixed count. Recovery time depends on transaction volume — high-volume tenants recover within days, low-volume tenants over weeks.