Contextual anomaly detection in tabular data aims to identify objects whose behavior is unexpected under their contextual conditions. In data-engineering pipelines, this task screens table rows whose measurements violate context-dependent integrity relationships. Most existing approaches rely on either shallow conditional models with limited distributional expressiveness or localized estimators that require per-context modeling, making it difficult to capture complex conditional relationships and scale to high-dimensional settings. We propose Flow-CAD, a new framework for contextual anomaly detection based on Flow Matching. Flow-CAD learns a single global and amortized conditional generative model that flexibly represents behavioral distributions conditioned on context, without assuming simple parametric forms or retraining local models. To enable robust and interpretable anomaly scoring, we introduce a scale-normalized and truncated residual energy derived from the learned conditional flow, which stabilizes anomaly scores, mitigates domination by extreme deviations, and supports feature-wise attribution. We further provide theoretical insights showing that the proposed residual-based anomaly score is stable under velocity estimation error, and that its Monte Carlo estimator satisfies concentration bounds. Experiments on 20 benchmark datasets with 13 competitors demonstrate that Flow-CAD has the best average rank for PR AUC, ROC AUC, and P@n, highlighting its effectiveness and practicality for contextual anomaly detection in tabular data. We provide the source code at https://github.com/ZhongLIFR/FlowCAD.
Figures & tables
Fig. 1: Illustration of the training (left) and inference (right) phases of Flow-CAD. The inference panel writes t(ℓ) for t(k,ℓ) within Gaussian block k .
Dataset
#Samples
#Anomalies (Rate)
#Contextual columns
#Behavioral columns
Abalone
4177
100 (2.4%)
4
5
Airfoil
1503
70 (4.7%)
5
1
BodyFat
252
20 (7.9%)
12
2
Boston
506
40 (7.9%)
13
1
Concrete
1030
50 (4.9%)
8
1
ElNino
20000
200 (1.0%)
6
5
TABLE I: Reconstructed benchmark tables used for full-table evaluation. Column counts are reported before encoding.
Component
Fixed value
Context encoder
2 layers of width 32
Velocity network
3 hidden layers of width 64 , ReLU
Optimizer
Adam, learning rate 0.001
Batch size
128
Training epochs
1,000
Score aggregation
L1
TABLE II: Flow-CAD configuration fixed across benchmark datasets and runs.
Dataset
Flow-CAD (ours)
QCAD
LoPAD
ROCOD
CAD
Abalone
1.00 ± 0.00 (1)
0.96 ± 0.01 (3)
0.01 ± 0.00 (14)
0.55 ± 0.03 (10)
0.98 ± 0.01 (2)
Airfoil
0.44 ± 0.10 (4)
0.68 ± 0.05 (1)
0.05 ± 0.00 (14)
0.42 ± 0.04 (5)
0.49 ± 0.04 (2)
BodyFat
0.84 ± 0.08 (1)
0.63 ± 0.08 (4)
0.07 ± 0.02 (14)
0.79 ± 0.05 (3)
0.81 ± 0.12 (2)
Boston
0.60 ± 0.10 (2)
0.63 ± 0.10 (1)
0.08 ± 0.00 (13)
0.30 ± 0.06 (4)
0.32 ± 0.09 (3)
Concrete
0.67 ± 0.14 (1)
0.60 ± 0.09 (2)
0.09 ± 0.02 (9)
0.31 ± 0.06 (5)
0.30 ± 0.06 (6)
ElNino
0.81 ± 0.04 (3)
0.99 ± 0.00 (1)
0.11 ± 0.01 (8)
0.39 ± 0.05 (7)
0.96 ± 0.01 (2)
TABLE III: PR AUC on 20 datasets. Entries give mean ± standard deviation (rank). Ranks use unrounded means and average numerical ties ( 10−12 tolerance). Equal displayed means can have different ranks. Bold and underlining mark the top two distinct ranks. Each method has 140 paired cases, with seven benchmark runs per dataset.
Dataset
Flow-CAD (ours)
QCAD
LoPAD
ROCOD
CAD
Abalone
1.00 ± 0.00 (1)
1.00 ± 0.00 (4)
0.29 ± 0.03 (14)
0.98 ± 0.00 (9)
0.99 ± 0.01 (8)
Airfoil
0.81 ± 0.05 (4)
0.92 ± 0.02 (1)
0.50 ± 0.03 (13)
0.79 ± 0.02 (5)
0.82 ± 0.02 (3)
BodyFat
0.96 ± 0.03 (2)
0.93 ± 0.04 (4)
0.49 ± 0.03 (14)
0.94 ± 0.03 (3)
0.98 ± 0.01 (1)
Boston
0.89 ± 0.04 (2)
0.93 ± 0.02 (1)
0.47 ± 0.02 (13)
0.82 ± 0.04 (3)
0.78 ± 0.05 (4)
Concrete
0.91 ± 0.06 (2)
0.93 ± 0.03 (1)
0.63 ± 0.03 (7)
0.77 ± 0.03 (3)
0.74 ± 0.04 (4)
ElNino
0.99 ± 0.00 (3)
1.00 ± 0.00 (1)
0.91 ± 0.01 (7)
0.98 ± 0.00 (5)
1.00 ± 0.00 (2)
TABLE IV: ROC AUC on 20 datasets. Notation follows Table III .
Dataset
Flow-CAD (ours)
QCAD
LoPAD
ROCOD
CAD
Abalone
0.97 ± 0.02 (1)
0.91 ± 0.01 (6)
0.00 ± 0.00 (14)
0.57 ± 0.01 (10)
0.94 ± 0.01 (3)
Airfoil
0.43 ± 0.07 (3)
0.67 ± 0.03 (1)
0.03 ± 0.02 (14)
0.41 ± 0.04 (4)
0.45 ± 0.04 (2)
BodyFat
0.74 ± 0.11 (2)
0.61 ± 0.06 (4)
0.06 ± 0.06 (14)
0.70 ± 0.06 (3)
0.77 ± 0.08 (1)
Boston
0.60 ± 0.09 (2)
0.64 ± 0.07 (1)
0.08 ± 0.01 (8.5)
0.36 ± 0.04 (4)
0.39 ± 0.08 (3)
Concrete
0.61 ± 0.11 (1)
0.61 ± 0.08 (2)
0.11 ± 0.04 (7)
0.33 ± 0.05 (3)
0.31 ± 0.06 (4)
ElNino
0.73 ± 0.04 (3)
0.94 ± 0.01 (1)
0.12 ± 0.03 (7)
0.40 ± 0.05 (6)
0.91 ± 0.02 (2)
TABLE V: P@ n on 20 datasets. Notation follows Table III .
Fig. 2: Illustrative raw-score decomposition for two Energy Efficiency instances with behavioral features (Y1,Y2) . (a) Sampled intermediate states and signed velocity differences Δv ; the score uses their coordinate-wise magnitudes r=∣Δv∣ . (b) Feature contributions estimated with a separate set of Monte Carlo draws.
Fig. 3: Ablation on residual normalization and truncation across all datasets. Panels show PR AUC, ROC AUC, and P@ n (top to bottom). We compare the default configuration (MAD normalization with truncation) against variants without normalization and without truncation.
Fig. 4: Sensitivity to truncation with MAD normalization. The threshold τ varies from 2 to 100 .
Fig. 5: Residual aggregation with L1 , L2 , and L∞ norms. Panels show PR AUC, ROC AUC, and P@ n (top to bottom).
Fig. 6: Sensitivity to the number of time draws Kt per Gaussian draw with MAD normalization and truncation.
Fig. 7: Sensitivity to the number of Gaussian draws Kz with MAD normalization and truncation.
Method
Paired accuracy
Flow-CAD
100.00
Conditional-mean MLP
46.43
Coordinatewise Flow
49.98
Zero-context Flow
50.00
TABLE VI: Mean paired accuracy (%) over seven sign-parity runs.
Fig. 8: Runtime comparison between Flow-CAD and QCAD on all 20 benchmark datasets (data seed 42 , one Apple M4 CPU thread per run). Orange shows the time to compute row scores and feature contributions. Blue includes data loading and metric computation for both methods, plus the 1,000 -epoch model fit for Flow-CAD and context encoding and Gower-neighborhood construction for QCAD. Flow-CAD is shown with solid bars and QCAD with striped bars. The vertical axis is logarithmic. Bar labels show total CPU time.
Financial anomaly detection often relies on large unlabeled transaction logs, where anomalous samples may already be present during training. Such training-set contamination violates the clean-normal data assumption underlying many anomaly detection methods. Although flow matching has demonstrated strong performance in generative modeling, its robustness in unsupervised tabular anomaly detection remains underexplored. In this work, we study flow-matching-based anomaly detection under contaminated training data by comparing Time-Conditioned Contraction Matching (TCCM) with Forest-Flow and evaluating multiple anomaly scoring functions. Our results show that the choice of anomaly score is critical. The original single-step Decision score used by TCCM is sensitive to contamination, whereas trajectory-based Deviation and Reconstruction scores provide more stable anomaly signals. With these scores, Forest-Flow becomes competitive with, and in some cases outperforms, TCCM. These findings highlight the importance of anomaly scoring for flow-matching methods in financial anomaly detection under severe class imbalance.
Philip Konz, Tejaswini Medi, Margret Keuper
University of Mannheim, Germany · MPI for Informatics, Saarland Informatics Campus, Germany
Anomaly detection for tabular data has been a long-standing unsupervised learning problem that remains a major challenge for current deep learning models. Recently, in-context learning has emerged as a new paradigm that has shifted efforts from task-specific optimization to large-scale pretraining aimed at creating foundation models that generalize across diverse datasets. Although in-context models, such as TabPFN, perform well in supervised problems, their learned classification-based priors may not readily extend to anomaly detection. In this paper, we study in-context models for anomaly detection and show that the unsupervised extensions to TabPFN exhibit unstable behavior, particularly in noisy or contaminated contexts, in addition to the high computational cost. We address these challenges and introduce TACTIC, an in-context anomaly detection approach based on pretraining with anomaly-centric synthetic priors, which provides fast and data-dependent reasoning about anomalies while avoiding dataset-specific tuning. In contrast to typical score-based approaches, which produce uncalibrated anomaly scores that require post-processing (e.g. threshold selection or ranking heuristics), the proposed model is trained as a discriminative predictor, enabling unambiguous anomaly decisions in a single forward pass. Through experiments on real-world datasets, we examine the performance of TACTIC in clean and noisy contexts with varying anomaly rates and different anomaly types, as well as the impact of prior choices on detection quality. Our experiments clearly show that specialized anomaly-centric in-context models such as TACTIC are highly competitive compared to other task-specific methods.
Patryk Marszałek, Tomasz Kuśmierczyk, Marek Śmieja
Faculty of Mathematics and Computer Science, Jagiellonian University, Kraków, Poland · Doctoral School of Exact and Natural Sciences, Jagiellonian University, Kraków, Poland
Anomaly detection on tabular data is commonly studied under three supervision regimes, including one-class settings that assume access to anomaly-free training samples, fully unsupervised settings with unlabeled and potentially contaminated training data, and semi-supervised settings with limited anomaly labels. Existing deep learning approaches typically train dataset-specific models under the assumption of a single supervision regime, which limits their ability to leverage shared structures across anomaly detection tasks and to adapt to different supervision levels. We propose ICLAD, an in-context learning foundation model for tabular anomaly detection that generalizes across both datasets and supervision regimes. ICLAD is trained via meta-learning on synthetic tabular anomaly detection tasks, and at inference time, the model assigns anomaly scores by conditioning on the training set without updating model weights. Comprehensive experiments on 57 tabular datasets from ADBench show that our method achieves state-of-the-art performance across three supervision regimes, establishing a unified framework for tabular anomaly detection.
Jack Yi Wei, Narges Armanfard
Department of Electrical and Computer Engineering, McGill University, Canada · Mila - Quebec Artificial Intelligence Institute, Montreal, Canada