Evaluating Security Audit Agents: Metric Design and Cost Control
Security audit agents differ from Q&A models: they must locate vulnerabilities, trace data flows, and produce reviewable reports. This article covers why dedicated evaluation is needed, four design elements (labeled cases, repeated runs, exploration budgets, isolated environments), a five-metric framework (recall, precision, false positives, unit cost, stability), a sample evaluation harness, common pitfalls, and practical team practices.
Why security-audit agents need dedicated evaluation
Security audit is not ordinary Q&A. The model must locate vulnerabilities in a codebase, trace data flows, verify exploitability, and produce a report that humans can review. These tasks usually require multi-step exploration: reading files, retrieving call graphs, forming hypotheses, and checking them. Evaluation therefore covers not only knowledge, but planning, tool-use efficiency, and result stability.
Unreliable evaluation results usually come from three sources:
- Single-run chance. Model output is stochastic; one run does not represent true capability.
- Case selection bias. Cases skew toward one vulnerability class, or come from public sources the model may have seen in training.
- Opaque cost. Reporting only hit counts, without tokens used or human review time, hides cost-effectiveness.
These issues are the starting point for evaluation design.
Four basic elements of evaluation design
2.1 Case set
Each case needs clear labels: vulnerable file, line range, and vulnerability type. Coverage should include major classes such as injection, access-control flaws, deserialization issues, sensitive-data leakage, and unsafe cryptography. More balanced categories better reflect overall capability.
Watch for data contamination. If cases come from public advisories or historical open-source commits, the model may have seen them in training and scores will be inflated. Safer options are internal code or rewritten samples, with sources stated in the report.
2.2 Repeated runs
The same model on the same case fluctuates with sampling. Run each case multiple times and report the distribution, not only the best run. Three runs is a modest starting point. Large variance across three runs means instability on that class and should be stated in the conclusions.
2.3 Exploration budget
Agent step count drives cost and quality. Different step caps make comparison meaningless. Use one max round count for all models (for example 30) and record actual rounds used. Finishing early suggests conservative stopping; always hitting the cap suggests possible looping.
2.4 Isolated environment
Disable network access during evaluation. Otherwise the model may retrieve public write-ups or ready-made fixes, which does not measure local code understanding. Offline runs also keep external conditions consistent and reproducible.
Metric system
A single metric misleads. A reasonably complete set includes five measures.
Recall: fraction of known vulnerabilities correctly found.
Recall = number of known vulnerabilities hit / total known vulnerabilities
Precision: fraction of reported items that are real vulnerabilities.
Precision = confirmed true-positive reports / all reported items
False-positive count: when precision is low, humans spend a lot of time on review. Count false positives separately, not only as a ratio.
Unit cost: tokens consumed per confirmed vulnerability.
Unit cost = total tokens / number of confirmed true vulnerabilities
Stability: consistency of hits across repeated runs on the same case. Describe it with two numbers: share of cases hit in at least one of three runs, and share hit in all three runs.
The model with the highest recall is not necessarily the best overall. High false-positive rates or much higher unit cost limit real-world usefulness.
Sample code: evaluation harness
The following sketch shows the evaluation flow. The agent interface is illustrative and should be replaced with the real system.
from dataclasses import dataclass, field@dataclassclass Case:case_id: strrepo_path: str# Each item is (file path, vuln type), used for hit matchingknown_vulns: set[tuple[str, str]] = field(default_factory=set)def match(report_item, known_vulns):# Matching should consider file path and vulnerability type.# Allow limited line-number offset to avoid format-related misses.return report_item in known_vulnsdef score(report_items, known_vulns):hits = {item for item in report_items if match(item, known_vulns)}recall = len(hits) / len(known_vulns) if known_vulns else 0.0precision = len(hits) / len(report_items) if report_items else 0.0false_positives = len(report_items) - len(hits)return recall, precision, false_positivesdef evaluate(agent, cases, runs=3, max_steps=30):results = []for case in cases:per_run = []for _ in range(runs):# agent.audit returns report items and tokens useditems, tokens_used = agent.audit(case.repo_path,max_steps=max_steps,network=False, # no network; keep conditions consistent)recall, precision, fp = score(items, case.known_vulns)per_run.append({"recall": recall,"precision": precision,"false_positives": fp,"tokens": tokens_used,})results.append((case.case_id, per_run))return results
In practice, hit matching is the easiest place to go wrong. Models may describe the same issue in different words or pin it to a neighboring function. Define matching rules clearly and spot-check edge cases so scoring stays consistent.
Common mistakes when reading results
Looking only at a single ranking. The top model may lead on recall but lag on precision or cost. Compare metrics in one table and state how weights were chosen.
Ignoring human review cost. Every false positive needs verification. If one model produces three times as many false positives, overall team effort may still be higher even with better recall.
Insufficient sample size. Few cases and few runs mean differences may be noise. Report spread; do not conclude from a one- or two-point gap.
Eval environment unlike production. Offline, tool-light, small-codebase evals differ from real audits. Keep conclusions inside the eval conditions; do not generalize to every setting.
Treating numbers as universal. Results reflect a specific case set, budget, and version. After model or tool updates, re-run the evaluation.
Practical advice for teams
- Build an internal benchmark. Collect cases from real projects covering main vulnerability classes, labeled by experienced engineers. Internal data better matches your code than public sets.
- Tie step caps to budget. Set max rounds and max tokens per audit; stop and record the reason when exceeded, to control cost.
- Keep full run logs. Record model version, prompt template, parameters, tool calls per round, and the final report. These support reproduction and debugging.
- Make human review part of the process. Agent reports should go through staged review, then into fix scheduling. High-risk items need independent verification by security engineers.
- Define usage boundaries. Audit tools should be used only on authorized repositories. Handle findings under responsible disclosure; do not publish details before a fix.
Summary
Evaluating security-audit agents depends on controlled conditions, a complete metric set, and reproducible results. Read recall, precision, false-positive count, unit cost, and stability together. Teams can build internal benchmarks from their own code and combine eval results with human review and cost budgets into an ongoing assessment loop.
