Evaluating LLM Coding and Security Capabilities: Frameworks and Best Practices
Large language models have evolved far beyond code completion: they can now understand requirements, read across multiple files, execute commands, and refine code based on feedback — a class of tasks known as agentic coding. Because these tasks naturally expose models to builds, tests, logs, and vulnerabilities, coding ability and security ability are often discussed together. This article breaks coding capability into five core dimensions — correctness, context understanding, tool use, iterative repair, and engineering hygiene — explains how to evaluate security-related capabilities with labeled samples, and provides a reproducible evaluation framework skeleton with key metrics and practical caveats. It also clarifies the boundary between defensive and offensive uses of these capabilities.
1. Background: Why Coding and Security Capabilities Are Discussed Together
Large language models have progressed from code completion to understanding requirements, reading multiple files, executing commands, and modifying code based on feedback. These tasks are commonly referred to as agentic coding. As models perform them, they naturally encounter security-relevant contexts such as builds, tests, logs, and vulnerabilities — which is why coding and security capabilities are frequently examined side by side.
The same capability is often two-sided. A model that can locate a null pointer exception could also be used to find exploitable vulnerabilities. When discussing such capabilities, it is important to distinguish defensive uses (code review, vulnerability remediation, security configuration checks) from offensive uses (unauthorized penetration testing, writing attack payloads). The former is routine work for engineering and security teams; the latter is outside the scope of this article and should never be performed on systems without authorization.
2. Five Core Dimensions of Coding Capability
When evaluating coding capability, “can it write code” is far from sufficient. Consider the following five dimensions.
2.1 Code Correctness
Whether generated code passes predefined unit and integration tests is the most basic metric. Record both the first-pass rate (the proportion of tasks the model passes on its first output) and the final pass rate after several rounds of fixes. The larger the gap between the two, the more attention the model’s ability to leverage test feedback deserves.
2.2 Context Understanding
Real-world changes typically span multiple files. The model must trace call relationships, understand existing data structures and naming conventions, and ensure its changes do not break other modules. A good evaluation design includes tasks that require modifying three to five files simultaneously, checking whether the model misses references or introduces inconsistent interfaces.
2.3 Tool Use
Agents need to execute build commands, run tests, and read error logs in a controlled environment, then decide on next steps based on the output. This dimension measures whether the model can correctly organize commands and parse results — not just generate text.
2.4 Iterative Repair
After a first-round failure, whether the model can locate the problem from error messages and produce an effective fix is key to its real-world value. Fewer average repair rounds indicate a more efficient feedback loop. However, excessive rounds may also mean the model is repeatedly trying similar flawed approaches, which requires manual review of the logs.
2.5 Engineering Hygiene
Whether the code style matches the project, whether unnecessary dependencies are introduced, and whether the scope of changes is minimal all directly affect long-term maintenance costs. A change that passes tests but is hard to read often costs more over time in collaborative development.
3. Security-Related Capabilities: Observable Behaviors and Evaluation Points
As code understanding improves, models can typically also handle some security-related tasks — for example, identifying common weakness patterns (missing input validation, improper path concatenation, hardcoded secrets, insecure deserialization) and suggesting fixes. This capability is not a separate module; it emerges from broad understanding of code structure. Whether it is reliable, however, must be verified through testing rather than assumed from experience.
For evaluation, build a set of labeled samples containing code with known weaknesses alongside safe counterparts, then measure detection performance:
samples = [{"id": "s1", "code": 'query = "SELECT * FROM users WHERE id=" + user_id', "label": "sql_injection"},{"id": "s2", "code": 'cursor.execute("SELECT * FROM users WHERE id=%s", (user_id,))', "label": "safe"},]def score(samples, predictions):tp = fn = fp = tn = 0for s in samples:predicted_vuln = predictions.get(s["id"], "safe") != "safe"actual_vuln = s["label"] != "safe"if actual_vuln and predicted_vuln:tp += 1elif actual_vuln:fn += 1elif predicted_vuln:fp += 1else:tn += 1recall = tp / (tp + fn) if tp + fn else 0.0false_positive_rate = fp / (fp + tn) if fp + tn else 0.0return {"recall": recall, "false_positive_rate": false_positive_rate}
This code only measures whether a weakness was detected. Whether the weakness category was correctly classified requires a separate category-level accuracy check, and whether suggested fixes can be adopted as-is requires manual sampling and review.
4. Building a Reproducible Evaluation Pipeline
A reproducible evaluation depends on four prerequisites: a fixed task set, an isolated execution environment, recorded versions of the model and prompt templates, and multiple samples per task. If any one is missing, results become hard to compare.
Below is the skeleton of an evaluation framework. The functions that generate patches and run tests must be implemented by your team; the framework itself only orchestrates the loop and records results.
from dataclasses import dataclass@dataclassclass TaskResult:task_id: strpassed: boolrounds: intdef evaluate(tasks, generate_patch, run_tests, max_rounds=3):results = []for task in tasks:prompt = task["prompt"]passed, rounds = False, 0for rounds in range(1, max_rounds + 1):patch = generate_patch(prompt)ok, feedback = run_tests(task["id"], patch)if ok:passed = Truebreakprompt = f"{task['prompt']}\nPrevious test feedback: {feedback}"results.append(TaskResult(task["id"], passed, rounds))return resultsdef summarize(results):if not results:return {}n = len(results)first_pass = sum(1 for r in results if r.passed and r.rounds == 1)final_pass = sum(1 for r in results if r.passed)avg_rounds = sum(r.rounds for r in results) / nreturn {"first_pass_rate": first_pass / n,"final_pass_rate": final_pass / n,"avg_rounds": avg_rounds,}
Here, generate_patch calls the model under evaluation and returns a code patch, while run_tests applies the patch in an isolated container and returns the test results. The implementation details of these two functions determine whether the evaluation is trustworthy, so they should go through code review.
The key metrics and their caveats are summarized below:
| Metric | Meaning | Caveats |
|---|---|---|
| First-pass rate | Proportion of tasks passed on the first output | Reflects the model’s direct generation quality, independent of feedback loops |
