Anomaly detection in tabular data is challenging because abnormal samples often arise as violations of cross-feature dependencies rather than simple marginal deviations. Existing detectors rely on geometric or reconstruction signals, while prior LLM-based approaches mainly fine-tune LLMs with normal samples or generate synthetic anomalies. We propose LLM-Detector, a framework that utilizes the in-context learning capacity of LLMs for structured, prompt-conditioned scoring synthesis, enabling LLMs to derive anomaly detection logic from structured normal-state knowledge. Specifically, normal training data are converted into statistical summaries, causal dependencies, and distilled prototypes that are organized into a prompt for code generation. The resulting scoring engine evaluates statistical deviation, structural inconsistency, and density-based abnormality then computes an anomaly score for each test sample. We evaluate LLM-Detector on 24 tabular datasets, comparing against 15 SOTA baselines. Results show consistent improvements across both mixed-type and continuous-only settings. Moreover, this design eliminates the need for LLM fine-tuning or neural network training, reducing computational cost and enabling practical anomaly detection in real-world tabular systems.
Figures & tables
Figure 1: Comparison of LLM-based TAD methods across categorical handling, computational efficiency, and causal modeling.
Figure 2: Our framework LLM-Detector . It has two phases: (1) Knowledge-to-Code extracts statistical profiles, causal structure, and distilled prototypes from normal data to construct a structured prompt, and (2) Code-to-Score generates a scoring engine executed on test samples to compute anomaly scores.
Figure 3: Prototype distillation via K-Means and nearest-neighbor (NN) mapping.
Dataset
N
d
dcat
dcon
Na
ACD
10,000
4
3
1
490 (5%)
Bank
41,188
10
10
0
4,640 (11%)
CMC
1,473
8
8
0
29 (2%)
DAMRE
1,000
5
2
3
100 (10%)
Fraud
151,112
8
6
2
14,151 (9%)
Lymp
148
18
15
3
6 (4%)
Table 1: Statistics for 12 mixed-type datasets. dcat , dcon , and Na denote the numbers of categorical features, continuous features, and anomalies. Lymp (Lymphography), ACD (Cybersecurity), and Fraud (Fraud ecommerce) are from [ 22 , 5 , 7 ] while SPD (Spyware-Attacks), DAMRE (Damage-Report), OS (OS-Kernel), SMD (Smart-Meter), and Vifd (Vehicle insurance) are from Kaggle.
ACD
Bank
CMC
DAMRE
Fraud
Lymp
NHIS
OS
Seismic
SMD
SPD
Vifd
AVG
Iforest
0.5030
0.5118
0.5061
0.6901
0.4800
0.7050
0.6573
0.7716
0.7058
0.8127
0.4837
0.5067
0.6112
KNN
0.4943
0.5124
0.5779
0.9250
0.5005
0.8705
0.6748
0.9330
0.7445
0.9237
0.4919
0.5227
0.6809
PCA
0.5059
0.5152
0.5101
0.8857
0.4538
0.8560
0.6498
0.8475
0.7041
0.9340
0.4786
0.4931
0.6528
ECOD
0.5086
0.5134
0.5394
0.8442
0.4631
0.8545
0.6537
0.7686
0.6980
0.9114
0.4915
0.5028
0.6458
DeepSVDD
0.4774
0.4996
0.5715
0.9162
0.5015
0.8685
0.6626
0.7957
0.6939
0.6864
0.4848
0.4993
0.6381
GOAD
0.4969
0.5139
0.4833
0.8726
0.5001
0.8764
0.7151
0.9117
0.7193
0.1545
0.4910
0.4991
0.6028
Table 2: AUC-ROC scores for all methods on 12 mixed-type datasets. Bold and underline indicate the best and second-best methods. Standard deviations are reported in Appendix 2 .
Figure 4: AUC-ROC comparison on 12 continuous datasets across all 15 methods. The color scheme is: yellow (proximity-based), green (distribution-based), blue (boundary-based), purple (reconstruction/generation-based), navy (LLM-based), red (ours).
Figure 5: Ablation study of three types of knowledge in the description component on 12 mixed-type datasets.
Figure 6: Sensitivity to three LLM backbones (DeepSeek, GPT, and Gemini) over 12 mixed-type datasets.
Figure 7: Sensitivity to the number of distilled samples over 12 mixed-type datasets.
Figure 8: Sensitivity to causal discovery methods over 12 mixed-type datasets.
Figure 9: Computational efficiency comparison across all 24 datasets.
Appendix figures & tables4 assets
Supplementary material from the paper’s appendix.
Appendix
Dataset
N
d
dcat
dcon
Na
Annthyroid
7,200
6
0
6
534 (7%)
BreastW
699
9
0
9
241 (34%)
Ecoli
336
7
0
7
9 (3%)
Shuttle
49,097
9
0
9
3,511 (7%)
Thyroid
3,772
6
0
6
93 (2%)
Wine
130
13
0
13
71 (55%)
Appendix
Table 3: Statistics for 12 continuous-only datasets.
Dataset
Iforest
PCA
KNN
ECOD
DeepSVDD
RCA
SLAD
GOAD
NeuTral
ICL
DTE
REPEN
AnoGAN
AnoLLM
LLM-DAS
LLM-Detector
Annthyroid
0.9074 (0.011)
0.8298 (0.024)
0.8088 (0.003)
0.7883 (0.002)
0.7335 (0.014)
0.7160 (0.001)
0.7538 (0.008)
0.5521 (0.002)
0.7766 (0.022)
0.8396 (0.019)
0.9763 (0.002)
0.7316 (0.016)
0.6361 (0.155)
0.9153 (0.001)
0.8330 (0.016)
0.9117 (0.013)
BreastW
0.9926 (0.002)
0.9912 (0.003)
0.9930 (0.003)
0.9894 (0.002)
0.9719 (0.004)
0.9889 (0.003)
0.9896 (0.004)
0.9932 (0.002)
0.9848 (0.003)
0.9915 (0.003)
0.9879 (0.005)
0.9520 (0.021)
0.9283 (0.090)
0.9911 (0.002)
0.9845 (0.002)
0.9673 (0.018)
Ecoli
0.8126 (0.005)
0.8358 (0.008)
0.8785 (0.002)
0.7514 (0.006)
0.8525 (0.016)
0.8844 (0.028)
0.7755 (0.010)
0.8153 (0.006)
0.8645 (0.007)
0.8925 (0.020)
0.8182 (0.005)
0.8424 (0.044)
0.7650 (0.023)
0.8570 (0.013)
0.8241 (0.015)
0.8787 (0.012)
Shuttle
0.9962 (0.000)
0.9936 (0.001)
0.9989 (0.000)
0.9930 (0.000)
0.9949 (0.000)
0.9954 (0.000)
0.9981 (0.000)
0.9883 (0.001)
0.9977 (0.002)
0.9995 (0.000)
0.9976 (0.000)
0.9938 (0.002)
0.9906 (0.002)
0.9984 (0.000)
0.9952 (0.001)
0.9915 (0.001)
Thyroid
0.9903 (0.001)
0.9839 (0.000)
0.9761 (0.001)
0.9787 (0.001)
0.8501 (0.006)
0.9712 (0.001)
0.9485 (0.011)
0.6844 (0.024)
0.8459 (0.017)
0.9827 (0.009)
0.9909 (0.001)
0.9295 (0.017)
0.9606 (0.021)
0.9890 (0.001)
0.9776 (0.002)
0.9617 (0.017)
Wine
0.9355 (0.013)
0.9972 (0.000)
0.9931 (0.002)
0.7437 (0.009)
0.9665 (0.023)
0.9551 (0.007)
0.9917 (0.011)
0.9955 (0.000)
0.9937 (0.001)
0.9660 (0.036)
0.9922 (0.004)
0.3094 (0.067)
0.9890 (0.005)
0.9955 (0.003)
0.9925 (0.001)
0.9853 (0.020)
Appendix
Table 4: AUC-ROC (standard deviation) on each dataset ( higher is better ).
Dataset
Iforest
PCA
KNN
ECOD
DeepSVDD
RCA
SLAD
GOAD
NeuTral
ICL
DTE
REPEN
AnoGAN
AnoLLM
LLM-DAS
LLM-Detector
Annthyroid
0.5512 (0.016)
0.4794 (0.025)
0.4394 (0.005)
0.3882 (0.001)
0.4288 (0.025)
0.3733 (0.006)
0.4051 (0.003)
0.2303 (0.003)
0.4244 (0.013)
0.5568 (0.023)
0.7840 (0.011)
0.3377 (0.014)
0.2903 (0.109)
0.6036 (0.002)
0.4644 (0.017)
0.4819 (0.096)
BreastW
0.9627 (0.006)
0.9599 (0.010)
0.9655 (0.008)
0.9461 (0.012)
0.9336 (0.009)
0.9599 (0.007)
0.9571 (0.010)
0.9641 (0.007)
0.9613 (0.009)
0.9558 (0.002)
0.9585 (0.009)
0.9170 (0.036)
0.8880 (0.106)
0.9613 (0.004)
0.9557 (0.010)
0.9392 (0.019)
Ecoli
0.7037 (0.052)
0.7778 (0.000)
0.7408 (0.052)
0.3703 (0.052)
0.7778 (0.000)
0.5926 (0.052)
0.4444 (0.091)
0.5556 (0.091)
0.6667 (0.091)
0.6297 (0.105)
0.7408 (0.052)
0.5926 (0.262)
0.2592 (0.139)
0.7778 (0.000)
0.4815 (0.210)
0.6667 (0.157)
Shuttle
0.9707 (0.003)
0.9572 (0.000)
0.9766 (0.001)
0.9169 (0.001)
0.9786 (0.003)
0.9694 (0.001)
0.9747 (0.000)
0.9625 (0.001)
0.9840 (0.001)
0.9801 (0.002)
0.9736 (0.001)
0.9677 (0.001)
0.9546 (0.005)
0.9809 (0.000)
0.9777 (0.000)
0.9569 (0.003)
Thyroid
0.8100 (0.018)
0.7383 (0.013)
0.6380 (0.005)
0.6344 (0.000)
0.4982 (0.071)
0.6129 (0.009)
0.6416 (0.052)
0.4158 (0.018)
0.2796 (0.046)
0.7240 (0.020)
0.8100 (0.010)
0.3764 (0.040)
0.5950 (0.106)
0.7957 (0.000)
0.6237 (0.018)
0.6308 (0.082)
Wine
0.9155 (0.020)
0.9812 (0.007)
0.9765 (0.007)
0.8169 (0.020)
0.9342 (0.033)
0.9530 (0.007)
0.9812 (0.018)
0.9718 (0.000)
0.9718 (0.000)
0.9436 (0.042)
0.9671 (0.007)
0.6291 (0.027)
0.9671 (0.018)
0.9812 (0.007)
0.9577 (0.012)
0.9765 (0.013)
Appendix
Table 5: F1-score (standard deviation) on each dataset ( higher is better ).
Figure 10: Full code-generation prompt template used in the Knowledge-to-Code stage. The prompt includes role definition, dataset context, task description, analytical instructions, and expected output format, while replacing full-dataset injection with three compact normal-state knowledge components: feature distributions, causal knowledge, and distilled samples. The distilled sample block is truncated for space efficiency; the actual setup uses 100 distilled samples.
Faculty of Mathematics and Computer Science, Jagiellonian University, Kraków, Poland · Doctoral School of Exact and Natural Sciences, Jagiellonian University, Kraków, Poland