Calibrates anomaly scores into decisions with a stated error rate using conformal p-values. Controls FDR, FPR, or stream false-alarm probability without assuming a contamination rate.
Ships in nonconform. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
nonconform wraps an anomaly detector (scikit-learn, PyOD or your own) and turns its scores into conformal p-values by ranking them against scores of known-normal reference data. From those p-values it makes decisions with an error rate the user chooses:
None of this needs a model of what anomalies look like. It needs normal reference data from the same source as the new data.
Why bother: a detector's own cutoff (PyOD's contamination, a top-k, a z-score rule) is a guess about how many anomalies exist. When the guess is wrong, every flag shifts and nobody can say how many flags are false. Calibration replaces the guess with a number the user picked.
pip install nonconform # core: scikit-learn detectors, all decision methods
pip install "nonconform[pyod]" # adds PyOD's detectors
Other extras: [fdr] for online FDR with online-fdr, [probabilistic] for KDE-based p-values, [data] for benchmark datasets. Python 3.11 or newer.
Work out which error rate the user cares about, because it decides the API. The options are different promises, so if the request is ambiguous and you can ask, ask. If nobody is there to answer, pick the most likely reading, say at the top of the report which one you picked, and say what the other reading would have promised.
| The user wants | Error rate | Use |
|---|---|---|
| Which points in this batch to act on, with few false alarms among them | FDR: expected share of false alarms among flagged points | detector.select(x_new, alpha=...) |
| A fixed threshold to deploy, rarely firing on normal traffic | FPR: chance that a normal point is flagged | detector.fpr_bounds(confidence=...), then threshold_for(target_fpr) |
| Whether and when a stream changed | Probability of any false alarm, ever | ExchangeabilityMonitor with a martingale |
| A bound on false alarms in this exact batch, at several cutoffs | Realized false discovery proportion, with confidence | detector.fdp_bounds(x_new, confidence=...) |
Translate the user's words: "at most 10% of what we send to the fraud team should be false" is FDR with alpha=0.10. If the limit is about each list itself ("if more than 10% of today's list is wrong, they stop trusting us"), FDR alone does not promise that, because it is an average over batches; say so and add an FDP bound for the list. "Flag no more than 1% of normal sessions" is FPR with target_fpr=0.01. "Tell me when the pump starts behaving differently, and don't cry wolf" is stream monitoring with a Ville threshold of 1 / alpha.
Write the decision down before you run anything: the error rate, its level (alpha, target_fpr, confidence), the method ("bh" or "storey", the FDP envelope) and the reference data. Put it in the code or the report before the first select() call. A level set in the project's CLAUDE.md or AGENTS.md counts as fixed in advance. Changing any of these after seeing a result voids the guarantee.
Everything rests on a reference set of normal observations that looks like the normal part of the new data.
n calibration scores, the smallest possible p-value is 1 / (n + 1). For BH over m test points at level alpha, a single isolated discovery needs n + 1 >= m / alpha: 500 test points at alpha=0.05 need about 10,000 calibration points. Batches with many real anomalies need fewer, because BH's cutoffs grow with rank. For FPR certificates, 1,000 calibration scores at 95% confidence give a floor of about 3.85%; for lower targets, use more scores or conditional p-values (references/workflows.md, section 2).Batch FDR, the most common case:
import numpy as np
from pyod.models.iforest import IForest # any PyOD or scikit-learn detector works
from nonconform import ConformalDetector, Split
rng = np.random.default_rng(0)
x_reference = rng.normal(size=(5_000, 4)) # known-normal data
x_new = np.vstack([rng.normal(size=(480, 4)), rng.normal(5.0, 1.0, size=(20, 4))])
detector = ConformalDetector(
detector=IForest(),
strategy=Split(n_calib=0.5), # share (or count) of reference rows held out for calibration
seed=0,
)
detector.fit(x_reference) # trains on one part, calibrates on the held-out part
flagged = detector.select(x_new, alpha=0.05) # boolean mask; FDR controlled at 5%
print(f"flagged {flagged.sum()} of {len(x_new)}:", np.flatnonzero(flagged))
select() computes conformal p-values and applies Benjamini–Hochberg (BH). Pass method="storey" for adaptive BH when anomalies are common. detector.last_result.p_values holds the p-values from the latest call.
For everything else, references/workflows.md has a complete, tested snippet per task. Read the section you need:
ExchangeabilityMonitorcalibrate())DerandomizedSplits) and FDP boundsThe guarantees hold when these do. Check each one and tell the user about any that may fail.
alpha, the detector and its settings before looking at test results. Re-running until the flagged set looks right voids the guarantee.Split and detached calibration carry the finite-sample guarantees. CrossValidation and JackknifeBootstrap use data more efficiently but carry no finite-sample guarantee in nonconform; say so if you use them.select() controls FDR over the batch you pass. Splitting a batch into ten calls makes ten families with ten separate guarantees.ExchangeabilityMonitor, and don't refit the scorer mid-stream.Run the checks in references/guarantees.md, section 10, rather than assuming these hold. The held-out check takes a few lines and catches the most common failure: reference data that no longer matches the new normal data.
nonconform refuses combinations it cannot back with a guarantee (for example Storey's method with weights) and says why in the error. Read the message instead of working around it.
Lead with the decision, then the claim and its conditions, in this order:
references/guarantees.md.For example:
Flagged 23 of 2,000 transactions at a 10% false discovery rate. On average, at most 10% of transactions flagged this way are false alarms, provided today's legitimate transactions resemble the 5,000 reference transactions. The rate is an average over repeated batches, not a promise for this one, and it says nothing about anomalies that were not flagged.
Avoid these claims, which are wrong:
p < 0.05 "significant" without BH. With 1,000 normal points, about 50 would pass.references/guarantees.md explains each guarantee, its fine print and how to phrase it. Read it before writing up results for a stakeholder.
Each of these voids the guarantee. Treat any one as a blocker: fix it, or report that no guarantee applies. Use the same list to review nonconform code that someone else wrote.
alpha, the method, the detector or the reference window changed after someone saw a result (Step 1).select() calls and is reported as one FDR (Step 4).CrossValidation or JackknifeBootstrap results are reported with a finite-sample guarantee (Step 4).select() or an FPR certificate.IsolationForest, OneClassSVM, SGDOneClassSVM, LocalOutlierFactor(novelty=True) and EllipticEnvelope are recognized, and their score direction is handled, also as the final step of a Pipeline.fit and decision_function (get_params/set_params are optional), and must be copyable; a plain scoring function f(X) -> scores also works with calibrate(). Each row's score must not depend on the other rows in the batch. Pass score_polarity="higher_is_anomalous" or "higher_is_normal" to say which way the scores point; omitted, it defaults to higher-is-anomalous and logs a warning.nonconform adjusts some detector parameters it finds in get_params(): it sets contamination to a tiny value (the conformal rule replaces it), parallelism parameters such as n_jobs to -1 when they are still at the detector's default (a value the user set, such as n_jobs=2, is kept; PyOD's default n_jobs=1 counts as unset), and random_state (or seed) from the seed you pass. Mention this if the user expects their own values to be used.
select() flags nothing and logs a p-value floor warning: the calibration set is too small for the batch size and alpha. See Step 2.select() flags nothing and the warning says calibration size is not the limit: the batch has no anomalies the detector can separate from normal points. Check score_polarity and the detector; if a per-point false-alarm cap fits the decision, use fpr_bounds() (references/workflows.md, section 1).threshold_for() returns inf and certificate.select() flags nothing: the target is below the certificate's floor. Use more calibration scores or conditional p-values (references/workflows.md, section 2).fdp_bounds() gives a bound near 1.0 for a short list: valid but uninformative. Do not switch envelopes for this batch after seeing the bound; report that no useful bound is available. When lists will be a small share of the batch, choose method="mc_hc" before computing any bound (references/workflows.md, section 8).seed= to ConformalDetector; it also seeds the base detector's random_state.logging.getLogger("nonconform").setLevel(logging.WARNING) before fitting; warnings still show.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
/nonconform:nonconformfrom nonconform
npx claudepluginhub oliverhennhoefer/nonconform --plugin nonconformOther plugins' skills for the same job