How to Systematically Evaluate LLM Coding and Security Audit Capabilities
Model release notes are usually based on vendor-built benchmarks that may not reflect your team's real workloads. This article presents a reproducible evaluation framework covering five dimensions—coding, agentic tasks, long-context handling, security auditing, and cost—along with a ready-to-adapt Python script for aggregating results, so you can compare model versions using the same tasks and scoring rules.
Introduction
Large language models iterate rapidly, and the numbers in release notes are usually based on vendor-built test sets that may not match your team’s actual workloads. Rather than relying on marketing claims, it is better to build a reproducible evaluation method that compares versions using the same tasks and the same scoring rules. This article explains the evaluation approach across five dimensions—coding, agentic tasks, long context, security auditing, and cost—and provides an evaluation script you can adapt directly.
1. Define Evaluation Goals First
Before evaluating, answer three questions: What scenarios will the model be used for? How costly is a failure? What level of human review can the team accept? Different goals call for different metric weights. For example, code completion prioritizes response speed and acceptance rate, while automated bug fixing prioritizes first-pass success rate and rollback cost.
2. Evaluation Dimensions for Coding Ability
Coding ability can be broken down into four sub-items:
- Correctness of code generation: measured by unit test pass rate, not by a human judgment that the code “looks right.”
- Engineering-level modifications: modifying an interface in a multi-file project while keeping all callers consistent, which tests the model’s understanding of dependencies.
- Error recovery: when tests fail, can the model locate the problem from error messages and fix it within a limited number of turns?
- Code review: given defective code, can the model identify the issues and explain why they are problems?
Each sub-item should use a fixed task set. Ideally, tasks come from the team’s real past requirements, with the original context files preserved, rather than overly simplified exercises.
3. Evaluating Autonomous Agent Tasks
Agent tasks emphasize multi-step execution, and their failure modes differ from single-turn Q&A. Common problems include:
- Unreasonable task decomposition with key steps omitted;
- Incorrect tool call parameters, or repeated calls to the same tool;
- Continuing execution on top of an error state, which contaminates the results;
- Performing high-risk operations beyond the authorized scope.
During evaluation, run the agent in an isolated sandbox and record every action, output, and state change. Metrics include task success rate, average number of steps, average token consumption, number of out-of-scope operations, and human intervention rate. Out-of-scope operations should carry the highest weight: a single occurrence should mark that run as failed.
4. Verifying Long-Context Capability
The advertised context window only indicates how much input the model can accept—not how effectively it uses all of it. Two types of tests work well in practice:
- Information retrieval test: embed a fact at different positions in a long text, ask the model to extract it accurately, and plot accuracy curves across different lengths and positions.
- Cross-file consistency test: have the model read multiple files and answer questions involving references across them, then check whether the answers are internally consistent.
Accuracy curves typically drop noticeably as input approaches the upper limit. This inflection point is more useful for guiding real-world usage than the advertised context length.
5. Evaluating Security Audit Capability
Security audit evaluation should take a defensive perspective, covering secure code review, recognition of common vulnerability types (such as injection flaws, broken access control, and hardcoded credentials), and the quality of remediation suggestions.
Key metrics include:
- Recall: the proportion of known vulnerabilities correctly identified;
- False positive rate: the proportion of flagged items that are actually safe;
- Actionable fix rate: the proportion of suggested fixes that pass testing and can be merged directly.
Data sources must be compliant. Use codebases owned by the team or properly authorized, with samples sanitized and any content usable for real attacks excluded. Audit conclusions produced by the model require human review and should never directly trigger automated deployment.
6. Calculating Cost and Efficiency
At the same capability level, cost differences often come from retry counts and redundant output. Per-task cost can be estimated as:
Per-task cost = (input tokens × input price + output tokens × output price) × average number of attempts
The average number of attempts reflects the model’s first-pass capability. A model with a lower unit price that requires repeated retries may not be cheaper in total.
7. Building a Reproducible Evaluation Pipeline
- Collect real tasks by category, keeping at least several dozen samples per category with expected results labeled.
- Prefer automated scoring (test cases, rule matching), supplemented by manual spot checks.
- Fix the runtime environment, including prompt templates, sampling temperature, tool versions, and timeout settings.
- Run each task multiple times and report the mean and variance, so a single run does not mislead your judgment.
- Produce structured reports and keep raw logs for traceability.
Below is an example of aggregating evaluation results:
from dataclasses import dataclassfrom statistics import mean@dataclassclass TaskResult:task_id: strpassed: boolsteps: inttokens: intviolated_policy: bool = Falsehuman_intervention: bool = Falsedef summarize(results: list[TaskResult]) -> dict:if not results:raise ValueError("No evaluation results to summarize")total = len(results)# Any task with a policy violation is counted as failedpassed = sum(r.passed and not r.violated_policy for r in results)return {"success_rate": passed / total,"avg_steps": mean(r.steps for r in results),"avg_tokens": mean(r.tokens for r in results),"policy_violation_rate": sum(r.violated_policy for r in results) / total,"intervention_rate": sum(r.human_intervention for r in results) / total,}if __name__ == "__main__":demo = [TaskResult("t001", True, 6, 4200),TaskResult("t002", False, 12, 9800, human_intervention=True),TaskResult("t003", True, 8, 5100, violated_policy=True),]for key, value in summarize(demo).items():print(f"{key}: {value:.2f}")
The sample data only demonstrates the aggregation logic and does not represent the performance of any real model. In practice, replace the TaskResult data source with records from your own evaluation runs.
8. Practical Recommendations
- Start with a small set of real tasks before deciding whether to expand usage.
- Keep human approval in the loop for high-risk operations.
- After every model version change, rerun the same evaluation set and record the results in the change log.
