Context-Conditioned Probability Curvature for Zero-Shot Tabular Anomaly Detection

Whether a measurement is anomalous often depends on its context. A prothrombin time of 18 seconds is unremarkable in a cirrhosis ward and alarming in a routine check-up. Recent work shows that large language models can judge such cases zero-shot once a table's feature descriptions, units and normal ranges are restored. The model is simply asked for a verdict. This note proposes a different way to query the same model. Instead of asking it for an opinion, we measure how surprised it is by each observed value, given the context. We then correct that surprise by how uncertain the model expected to be at that position. The correction is the "conditional probability curvature" statistic, borrowed from machine-text detection, where it compares a token's log-probability to the log-probability the model expected on average and computes both in a single forward pass.

The bet is that this internal signal is a better anomaly score than the model's spoken verdict, for two reasons. First, verdicts drift toward "the biggest number is the anomaly" when the domain is unfamiliar. Second, a likelihood-based score never looks at labeled anomalies, so it should not lose accuracy when the test anomalies are of kinds nobody anticipated. The open-set regime, where test-time anomaly types are absent from training, is therefore where the idea is tested hardest. Supervised and semi-supervised detectors are known to break exactly there.

Core Claim

Serialize a table row as text, placing the metadata and a few normal reference rows from the same environment in the prompt as context $c$. For each feature $j$ with observed value tokens $x_j$, compute a standardized surprisal:

$$ s_j = \frac{\mu_j - \log p(x_j \mid c, x_{-j})}{\sigma_j}, $$

Here $x_{-j}$ are the row's other feature values, which the prompt places before feature $j$. The term $\log p$ is the model's summed token log-probability of the observed value. The terms $\mu_j$ and $\sigma_j$ are the mean and standard deviation of that log-probability under the model's own predictive distribution at those positions. They are computed analytically from the logits, as in Fast-DetectGPT. The row score is the maximum or the sum of the $s_j$.

The claim is that this score, computed with an open-weight model, beats the same model prompted as a judge on ReTabAD. It also beats raw conditional likelihood, most clearly on features whose values are inherently high-entropy. Finally, its accuracy on unseen anomaly types should match its accuracy on seen types, while supervised open-set detectors lose ground on unseen types. A useful by-product is that the per-feature $s_j$ names which value is surprising and under what context, which is the explanation a judge would otherwise have to generate.

Position Relative to Prior Work

The motivating result is ReTabAD. It pairs 20 tabular datasets with structured metadata and prompts GPT-4, Claude 3 and Gemini 1.5 as anomaly judges, gaining an average of +7.6% AUROC from context. It reads only parsed scalar outputs, and it reports that judges fall back on generic numeric extremeness when the metadata comes from unfamiliar domains. We keep ReTabAD's context and discard the verbal verdict.

The method comes from the curvature line of work. DetectGPT measures how log-probability drops under roughly 100 perturbed rewrites. Fast-DetectGPT replaces the rewrites with an analytic expectation, runs about 340 times faster, and notes that its statistic is an optimized mix of likelihood and entropy. NoiseGPT is the closest precedent for using curvature to find "wrong" data rather than machine text. It detects noisy image labels (AUROC above 0.92 on ILSVRC12) from unstable multimodal-LLM probabilities under feature perturbations, but it needs many forward passes and has no notion of environmental context. We move the single-pass statistic to context-dependent anomalies and ask a question none of these papers ask: whether conditioning the curvature on semantic context and same-environment normal rows turns it into a contextual detector.

The idea of adapting to a new environment from a few normal references comes from few-shot scene-adaptive video detection (Lu et al.; Meta Prototype Network). Those methods learn the adaptation by meta-training, whereas we get it from in-context conditioning.

Two strands of work constrain the design. On the open-set side, Deep SAD and Catching Both Gray and Black Swans show that known anomalies help only when they are used to tighten the boundary around normal data, not treated as a class. UBnormal establishes disjoint train/test anomaly splits as the honest evaluation. On the curvature side, the known failure modes are specific: curvature detectors raise false positives on inherently predictable text such as non-native writing, and they degrade without white-box logits (Fast-DetectGPT; D&R). This is why we commit to open-weight models and test the predictability confound directly.

Research Program

The system has three parts.

The first is serialization. A fixed template renders metadata, $k$ normal reference rows and the query row. Each feature is scored in a pass where it appears last, so that it is conditioned on all other features. This costs $d$ passes per row for $d$ features. A cheaper variant averages over a few random column orders, and we measure how much accuracy it gives up.

The second is scoring. From the logits of that pass we compute $s_j$ and aggregate it into a row score. Multi-token numeric values are scored as a unit, summing the log-probabilities and the analytic means and variances, since digit-level tokenization makes single-token scores meaningless.

The third is thresholding. We use split conformal calibration on held-out normal rows, which bounds the false-alarm rate on normal data at a chosen level. This is a modest, standard guarantee. Unlike the binary verdict setting of Judge, Retrieve, or Abstain, it attaches to a continuous score that needs no anomaly labels.

The analysis covers three questions. We ask when the correction by $\mu_j$ and $\sigma_j$ matters, predicting that it matters most for identifier-like or high-precision continuous features. We ask how many reference rows $k$ are needed before context-dependent anomalies separate. And we ask whether the per-feature attributions agree with the anomaly semantics recorded in ReTabAD's metadata.

Baselines

The naive reference is Isolation Forest on the numeric features alone. ReTabAD reports its average rank as 7.50 across the 20 datasets. Any context-aware method that does not clearly beat it has failed.

The strongest trained competitor on ReTabAD is MCM, which ReTabAD reports at average rank 3.95. The best zero-shot judge, Gemini, is reported at average rank 4.10 in ReTabAD. The file gives no per-dataset AUROC values, so we will rerun MCM with the tuning protocol it was given in ReTabAD and report per-dataset AUROC alongside ranks.

The fairest judge baseline is the same open-weight model that computes our score, prompted with ReTabAD's persona-plus-metadata template and identical context, including the same $k$ reference rows. We read its verdict two ways, as a parsed score and as the probability of the "anomalous" token. Model, context and GPU budget are then identical, and only the readout differs. Beating it means higher mean AUROC and a better average rank across the 20 datasets. For scale, we also report ReTabAD's published proprietary-judge ranks.

For the open-set regime, the strongest method is Deep SAD, given labeled anomalies of the seen types. No reported result was found on Lacuna for Deep SAD on these splits; the file lists ODDS usage without numbers. As a reference point for label efficiency, ADBench reports a 75.56% median AUCROC for semi-supervised detectors at 1% labeled anomalies, against 60.84% for supervised ones. Deep SAD gets an equal hyperparameter search budget on a validation set of seen types only. Beating it means a smaller seen-to-unseen AUROC drop at comparable seen-type AUROC.

Two ablations isolate the ingredients. One replaces $s_j$ with raw $-\log p$, which removes the curvature correction. The other removes metadata and reference rows, which removes the context.

Why not just…?

Why not just threshold the raw conditional likelihood? This is the most serious threat. The curvature statistic contains likelihood, and Fast-DetectGPT itself describes it as a combination of likelihood and entropy. The evidence against raw likelihood so far comes only from text detection, where absolute perplexity tracks topic rather than source. Tables have an analogous confound: a free-text ID or a six-digit reading is always improbable. The raw-likelihood ablation settles the matter. If it matches $s_j$ on ReTabAD, the curvature correction contributes nothing, and the contribution reduces to "context-conditioned LLM likelihood." We would then report that, and make the attribution and open-set results the main contribution.

Why not just read the judge's verdict-token probability? This uses logits too and costs one pass per row rather than $d$. However, it inherits whatever reasoning the model produces. ReTabAD documents that on unfamiliar metadata this reasoning degrades toward numeric extremeness. The decisive test splits ReTabAD's datasets by domain familiarity. If the verdict readout degrades as much as our score on unfamiliar domains, the claim that density readout escapes the familiarity bias is false.

Why not just fit a classical detector, or kNN, on LLM embeddings of the rows? This would capture semantics cheaply. But it discards the conditional structure, namely which value is surprising given the others, and that structure is what defines a contextual anomaly. Once fit on normal rows it is also one more unsupervised detector, subject to the tuning fragility ADBench documents. We include it with the same backbone, using mean-pooled hidden states with kNN, so that this is measured rather than assumed.

Proposed Experiments

The first experiment runs all methods on the 20 ReTabAD datasets using two open-weight model sizes. It reports AUROC, AUPRC and average rank, together with the context and correction ablations and the ordering-cost study.

The second experiment builds open-set splits from ADBench datasets that were derived from multi-class sources. Some anomaly classes are given to Deep SAD and the supervised baselines, and disjoint classes are held out for testing, following UBnormal's protocol. Our method never sees anomaly labels, so its only open-set risk is whether unseen types are surprising under context. The decisive check is the gap between seen-type and unseen-type AUROC for each method.

The third experiment is a controlled contextual test. We take normal rows, swap a value with one that is normal elsewhere in the dataset but inconsistent with the row's own context, for example a lab value typical of healthy patients inserted into a cirrhotic record, and ask whether $s_j$ flags the swapped feature. Context-free detectors should miss these by construction.

The fourth experiment checks the predictability confound that affects curvature detectors in text. We stratify false positives by the model's expected entropy $\mu_j$ and test whether low-entropy features are over-flagged.

The fifth experiment verifies that the conformal threshold holds its nominal false-alarm rate on normal test rows.

The proposal succeeds if the curvature score beats the same-model judge on average rank, if it beats raw likelihood on datasets with high-entropy features, and if it shows a markedly smaller seen-to-unseen drop than Deep SAD. Failing the first condition would mean the model's internal probabilities carry no more anomaly information than its stated opinion.