How to Evaluate Recall for LLM Security Detection

    In security work, missed findings often cost more than false positives. This article explains why recall is the core metric for LLM security evaluation, how to define tasks and hit rules, and how to report single-run, union, and stable (intersection) recall together with cost, reproducibility, and engineering practice.

    Why security cares more about recall than sounding smart

    In code audit, vulnerability hunting, and alert triage, a miss is usually worse than a false positive. An undetected issue may be a real, exploitable point on production assets; false positives can still be filtered by rules, human review, and downstream pipelines. For security-oriented LLM evaluation, the core metric is therefore recall: whether the model finds as many of the issues it should find as possible on a given sample set.

    Recall is not a single number. Running the same set once, three times, taking the union of hits, or counting only items hit every time can yield very different conclusions. A common pattern is high aggregated hit rate but low stable hits: the model can sometimes reach the answer, but repeatability is weak. For teams that need audit trails and automated gates, stability is the real deployment bottleneck.

    The rest of this article turns evaluation from a scoreboard story into a workable method: task definition, metric breakdown, experiment design, cost and engineering support, and how to read results.

    Pin the task: samples, labels, and hit rules

    The easiest way security evals go wrong is the test set, not the model. At least lock down four things.

    Sample source and coverage. Cover common defect classes (injection, auth bypass, deserialization, sensitive-data exposure, unsafe dependencies, misconfiguration, and similar) and diversity of languages and frameworks. A narrow set means high recall only shows the model can solve those few items.

    Gold standard. Each sample should have a verifiable vulnerability or security conclusion, not an open-ended essay. Hit rules must be executable: for example, naming a specific file, function, and defect type, or giving the key points of a reproducible exploit path. Vague “there might be risk” should usually not count as a hit.

    Allowed context. Snippet-only vs. full dependencies and build notes; tool use or not; multi-round retrieval or not. If context changes, recall is not comparable.

    How failures are counted. Timeouts, refusals, format errors, and hallucinated files that do not exist should be tracked separately so they are not all lumped into “no recall” and hide engineering issues.

    A written evaluation spec matters more than arguing after the fact whether something “counts as found.”

    Three kinds of recall: single-run, union, and stable hits

    On the same items and prompt, run multiple times and report at least three complementary metrics.

    Single-run recall. Hits on the first (or a random) run divided by the number of issues that should be found. This is closest to a real “call once” production experience and is most hurt by randomness. If security review only runs once, this is the capability users actually get.

    Union (aggregated) recall. Take the union across runs: if any run found it, the sample is covered. This is an upper bound on capability: whether the model “knows what this class of issue looks like.” High union and low single-run usually means temperature, decoding, or reasoning path is unstable and only sometimes takes the correct branch.

    Stable hits (intersection). Samples found on every run. This is deployability. Automated pipelines, compliance audit, and customer reports need similar inputs to produce similar outputs. If stable hits are low, do not promise capability using union recall.

    A common misread is treating a three-run union as the model having “crossed a capability line.” Union rewards variance. A more rigorous report includes single-run mean and variance, union, intersection, and a breakdown by defect class so a strong total does not hide misses on critical classes.

    Where inconsistency usually comes from

    This is engineering, not mysticism.

    Decoding and temperature. Security tasks usually fit lower temperature and structured output (fixed fields such as location, type, evidence, confidence). Higher temperature inflates union and suppresses intersection.

    Prompts that do not reward completeness. If the prompt asks for “the most likely single issue,” the model stops early. Audits need explicit enumeration of candidates, evidence per item, and permission to output “none found” with what was checked.

    Context window and retrieval. Large repos cannot be stuffed in one pass. Chunking, ranking, and reread strategy change recall. Fix chunk size, overlap, ranking features, and max read rounds in the eval.

    Whether tools are in scope. If static scan, dependency checks, or test execution are agent steps, the model is more of an orchestrator. Report LLM-only and model + tools separately so you can tell whether gains come from reasoning or from scanners.

    Eval leakage and style fit. Public problems, blog cases, and textbook vuln patterns are easy for models that have seen similar write-ups. Compare private, variant, and obfuscated samples and watch how much recall drops to estimate generalization.

    Put cost on the same table as recall

    Security teams rarely buy “highest score” alone. Cost per unit recall, latency, concurrency, and failure rate decide whether something enters a pipeline.

    Record at least: average input/output length per sample, average rounds, timeout rate, unit cost (a generic billing estimate is enough; do not bind to one vendor’s price), and how many repeats are needed to reach a target recall. If you need a three-run union to approach the target, real cost is near 3× a single run, plus dedup and human check.

    Sometimes a setup with slightly fewer hits but clearly lower cost is better for full-repo scans: a cheaper model for broad coverage, a stronger model for second-pass confirmation. That is cascading, not a single champion.

    Do not invent unverified percentages or absolute scores. External communication should use numbers from your own experiments; rumor scores are at most a signal that someone compared union metrics, not a selection basis.

    Turn the experiment into a reproducible pipeline with generic cloud primitives

    Reproducibility beats a one-off high score. A vendor-neutral pattern:

    Object storage for repo snapshots, prompt versions, raw model outputs, and score sheets so results can be audited later.

    A message queue to evaluate samples in parallel, control concurrency, and keep rate limits and timeouts from being scored as “the model is bad.”

    A container platform to pin the eval image: dependency versions, decoding parameters, parse scripts, so results stay comparable across machines.

    Logging for latency, token volume, and tool-call traces so you can replay failures.

    Monitoring and alerts on failure rate, timeouts, and parse failures. When those worsen, recall numbers go with them and are often misread as model regression.

    Score as programmatically as possible: structured output plus rule matching, with humans only sampling disputed cases. Full manual scoring is expensive and unstable.

    Illustrative hit logic (not a vendor API):

    1. for each sample:
    2. outputs = [run(model, sample, seed_i) for i in 1..N]
    3. hit_i = parse_and_match(outputs[i], gold)
    4. union_hit = any(hit_i)
    5. stable_hit = all(hit_i)

    Also define in advance how type-correct but location-wrong findings score: partial credit or zero, and report confusion by vuln type.

    How to read results: one line each for engineering, security, and procurement

    Engineering. If union is high and intersection is low, tighten decoding and prompts before swapping models. Raise stable hits first so automation can hold.

    Security. Watch whether misses land on high-severity surfaces (auth, injection, supply chain). If totals are close but high-severity classes differ, go by high-severity.

    Procurement and architecture. Look at cascading: cheaper models for coverage, stronger models for review; keep evidence in storage and logs for audit, not a one-time ranking.

    Practice checklist: from a one-off event to an ongoing capability

    1. Version the item set; separate a public control set from a private internal set.
    2. Publish single-run, union, intersection, and per-class results together.
    3. Freeze temperature, max rounds, and tool on/off.
    4. Put cost and latency on the same report as recall.
    5. Version prompt or chunking changes separately from model upgrades so you can attribute.
    6. Sample production misses back into the set so the eval does not go stale.

    Closing

    Security LLM evaluation answers three questions: can it find them all, does it find them stably, and is the cost of completeness acceptable. Split recall into single-run, union, and stable hits, and pair that with reproducible storage, queues, containers, and logs, so discussion moves from rumor scores to engineering decisions. Numbers will change; the method should be reusable. What can enter production is what holds on both intersection recall and the cost curve.