morello

Know when your data stops making sense.

Morello is a data quality monitor for tables that load in batches. It learns what normal rows look like and alerts when the rows of a new batch stop fitting together. You write no rules.

Terminal session. morello fit trains on 60 clean days of orders. morello check reports the first new day as OK and the second as ALERT with one finding: total stopped fitting unit_price and quantity in 4.2% of rows, 42 times the largest change seen before, five checks agree. Three example rows follow, each with the value the model expected for total.
Real output on a synthetic orders table. On the second day, 5% of orders carry another order's product, category and unit price. Five checks fire and the report states them as one finding. A script in the repository reproduces it.

What it catches

Rows that pass every column check and are still wrong.

The highlighted order has a real product, a normal price, a normal quantity and a plausible total. A null check, a range check and a distribution check all pass.

The total does not match the price and the quantity. Morello learns relationships like this one from the table's history, so it notices when a join starts attaching the wrong record, a unit changes, two columns swap or a code is remapped.

orderproductunit priceqtytotalrow
03-02-4P27 toys48.764195.04OK
03-02-5P20 books26.89380.67OK
03-02-6P06 toys12.57450.28OK
03-02-8P27 toys48.764122.20DOES NOT FIT

Four rows from the demo batch. 48.76 times 4 is 195.04, and the last row says 122.20.

How it works

Learn the table, check each batch, name the column.

  1. Learn

    Give Morello a history of the table that you believe is clean, at least 20 batches. It trains a model that predicts each column from the other columns in the row, and it measures how much every check normally moves from batch to batch.

  2. Check

    For each new batch it scores a sample of rows and asks how surprising they are given what it learned. It also runs per-column checks for nulls, unexpected values, distribution shift and duplicates.

  3. Alert

    A check alerts when it moves more than three times the largest change seen on any earlier clean batch. The report states each problem once, in a sentence, with example rows and the value the model expected. The alert stays open, and keeps failing the pipeline step, until a person accepts the batch or it passes a re-check.

Usage

Point it at a table from the command line, Python or a warehouse.

Morello is open source under the Apache 2.0 license. Install it with pip install git+https://github.com/zahmed333/morello.

Try it on your own history first

morello init     orders_history.parquet                          # which column defines the batches
morello backtest orders_history.parquet --batch-col order_date   # which past batches would have alerted

Command line

morello fit   orders_history.parquet --batch-col order_date --model orders.monitor
morello check orders_today.parquet   --model orders.monitor      # exit code 1 when a batch alerts

Python

import pandas as pd
from morello import Monitor

history = pd.read_parquet("orders_history.parquet")
monitor = Monitor().fit(history, batch_col="order_date")  # daily batches by default

report = monitor.check(pd.read_parquet("orders_today.parquet"))
print(report.text())
if report.alert:
    ...                                                   # stop the pipeline, page someone
monitor.save("orders.monitor")                            # history grows with every clean batch

A table in a warehouse

from morello.table import fit_table, check_table

fit_table(conn, "analytics.orders", batch_col="order_ts", store="s3://bucket/morello")
reports = check_table(conn, "s3://bucket/morello", table="analytics.orders",
                      results_table="ops.morello_results")
# the sample is taken by a query inside the warehouse, so table size does not matter

Evidence so far

Tested on simulated failures in two real public datasets.

Ten failure types at four severities were injected into every day of May 2024 in NYC taxi trips and NYC EMS dispatch records. That month was not used to design or tune anything.

77%of injected failures detected on taxi data, against 51% for standard per-column checks alone.
78%detected on EMS dispatch data, against 69% for standard per-column checks alone.
3 of 31clean days alerted on each dataset. Standard checks alone alerted on 2 of 31.
datastandard checksrow model aloneboth, as shipped
NYC taxi trips0.510.640.77
NYC EMS dispatch0.690.580.78
Wrong-record joins, taxi0.061.001.00
  • Every failure was simulated. Morello has not been tested on real incidents.
  • It has not been compared with commercial tools. NannyML's PCA method, run on the same batches, detected 0.19 on taxi and 0.34 on EMS.
  • It needs volume. On synthetic lab records, a small table with rows clustered by patient, it added almost nothing over standard checks (0.48 against 0.47).

Where it runs

What has been run, and what has only been written.

piecestatusdetail
pandas, parquet files, command lineTESTEDunit tests and the demo on this page
DuckDB tablesTESTEDincluding 13.8 million raw taxi rows
SparkTESTEDlocal session, with scoring on executors
dbtTESTEDdbt-duckdb; the build fails when a batch alerts
AirflowTESTEDAirflow 3.4; the task fails on an alert and on every retry
DagsterTESTEDDagster 1.13; the asset check fails until the batch is accepted
Scala gateTESTEDcompiled and run with spark-submit on Spark 4.3
SnowflakeNOT RUNstored procedure and SQL dialect are written
DatabricksNOT RUNsame code as the Spark test
Scala API for the modelNOT BUILTscoring runs in Python