GitHub 分享 LLM 上线前评估实践:从原型到生产
How to evaluate LLMs before production
做 LLM 应用评估的同学必看,GitHub 这套从产品决策到离线评估的实践非常可落地,特别是把指标分成结果、约束、护栏三层,赶紧对照你的评估流程检查一遍。
A language model can perform well on a clean benchmark and still struggle with the cases that matter in production.
语言模型在干净的基准测试中可能表现良好,但在实际生产中遇到的关键案例上却可能挣扎。
Benchmarks and curated datasets are useful when prototyping an LLM-based system. They help teams compare models, test an initial prompt, and determine whether an idea is technically plausible.
在原型设计基于LLM的系统时,基准测试和精选数据集很有用。它们帮助团队比较模型、测试初始提示,并确定一个想法在技术上是否可行。
But as a system moves closer to production, the evaluation problem changes.
但随着系统接近生产环境,评估问题发生了变化。
Real inputs are often ambiguous. Labels may be inconsistent. Important context may be missing or truncated. The evaluation set may not reflect the production distribution. Edge cases that rarely appear in benchmarks can become common sources of failure. Even when offline metrics improve, those results may not translate cleanly into production behavior.
真实输入往往模糊不清。标签可能不一致。重要上下文可能缺失或被截断。评估集可能无法反映生产分布。基准测试中很少出现的边缘情况可能成为常见的失败源。即使离线指标有所改善,这些结果也可能无法直接转化为生产行为。
We encountered these challenges while evaluating an LLM-based system designed to reduce false positives in GitHub secret scanning.
在评估一个旨在减少GitHub秘密扫描中误报的基于LLM的系统时,我们遇到了这些挑战。
Secret scanning identifies credentials such as tokens and keys that may have been committed to a repository. Because some candidate strings resemble secrets, but don’t actually represent real credentials, developers may spend time investigating alerts that don’t require remediation.
秘密扫描识别可能已提交到仓库的凭据,如令牌和密钥。由于一些候选字符串看起来像秘密,但实际上并不代表真实凭据,开发者可能会花费时间调查不需要修复的警报。
Rather than determine whether an LLM could classify a string correctly, we needed to understand whether the system could reduce noisy alerts while preserving enough recall to remain safe for a security workflow.
我们不仅需要确定LLM能否正确分类字符串,还需要了解系统能否在保持足够召回率以确保安全工作流安全的同时减少噪音警报。
In this post, we share the practices that helped us move from promising prototype results to production. The lessons apply broadly to LLM-powered systems in code analysis, developer tools, security, data analysis, and other production workflows.
在这篇文章中,我们分享了帮助我们从有前景的原型结果走向生产环境的实践。这些经验广泛适用于代码分析、开发者工具、安全、数据分析及其他生产工作流中的LLM驱动系统。
1. Start with the product decision, not the model
1. 从产品决策开始,而非模型
When an LLM system doesn’t perform as expected, the first instinct is often to adjust its technical components.
当LLM系统表现不如预期时,第一反应往往是调整其技术组件。
Teams may rewrite the prompt, add context, introduce another reasoning step, adjust the surrounding pipeline, or switch models. Before making any of these changes, they should define the decision the evaluation is meant to support.
团队可能会重写提示、添加上下文、引入另一个推理步骤、调整周围管道或更换模型。在进行任何这些更改之前,他们应该定义评估旨在支持的决策。
For our secret-scanning work, we asked:
对于我们的秘密扫描工作,我们问:
Can the system reduce false positives while preserving enough recall to be safe in a production security workflow?
系统能否在减少误报的同时保持足够的召回率,以确保在生产安全工作流中的安全性?
To answer this question, teams must decide which mistakes are acceptable, which metrics should drive the product decision, and which guardrails must remain within their defined thresholds.
为了回答这个问题,团队必须决定哪些错误是可以接受的,哪些指标应驱动产品决策,以及哪些护栏必须保持在定义的阈值内。
In secret scanning, incorrectly suppressing a real credential can be more consequential than asking a developer to review an additional alert. We therefore did not treat precision and recall as equally interchangeable metrics.
在秘密扫描中,错误地抑制一个真实的凭据可能比要求开发者审查额外警报的后果更严重。因此,我们没有将精确率和召回率视为同等可互换的指标。
Our primary objective was to reduce false positives and improve precision. Recall served as a safety constraint: an experiment could advance only if any decrease remained within a predefined acceptable range. This gave us a clear way to evaluate tradeoffs. We selected the configuration that achieved the strongest false-positive reduction while satisfying the recall requirement and meeting our operational guardrails.
我们的主要目标是减少误报并提高精确率。召回率作为安全约束:只有当任何下降保持在预定义的可接受范围内时,实验才能推进。这为我们评估权衡提供了清晰的方式。我们选择了在满足召回率要求和操作护栏的前提下,实现最强误报减少的配置。
We organized the evaluation criteria into three levels:
我们将评估标准分为三个层级:
Primary outcome
主要结果
This measured the user benefit we were trying to improve:
这衡量了我们试图改进的用户利益:
- False-positive reduction
- Precision
- 误报减少
- 精确率
Safety constraint
安全约束
This prevented an apparent improvement from introducing unacceptable security risk:
这防止了表面上的改进引入不可接受的安全风险:
- Recall
- 召回率
Operational guardrails
操作护栏
These determined whether the result was practical to deploy:
这些决定了结果是否实际可部署:
- Latency
- Cost
- Reliability
- Production compatibility
- 延迟
- 成本
- 可靠性
- 生产兼容性
This distinction prevented us from treating every metric as interchangeable. A change that reduced false positives but significantly lowered recall wasn’t automatically an improvement. Neither was a change that improved quality while making the system too slow, expensive, or difficult to integrate.
这种区分防止我们将每个指标视为可互换的。一个减少误报但显著降低召回率的变化并不自动是改进。同样,一个提高质量但使系统过慢、过贵或难以集成的变化也不是改进。
Consider two hypothetical experiment results:
考虑两个假设的实验结果:
| Experiment | Precision | Recall | Latency | Decision |
|---|---|---|---|---|
| Experiment A | Large improvement | Falls below the safety guardrail | Acceptable | Don’t advance |
| Experiment B | Moderate improvement | Remains within the guardrail | Acceptable | Continue testing |
| 实验 | 精确率 | 召回率 | 延迟 | 决策 |
|---|---|---|---|---|
| 实验A | 大幅改进 | 低于安全护栏 | 可接受 | 不推进 |
| 实验B | 中等改进 | 保持在护栏内 | 可接受 | 继续测试 |
Experiment A may look stronger if precision is viewed in isolation. Experiment B is more aligned with the product goal because it improves the developer experience without violating the recall guardrail.
如果孤立地看精确率,实验A可能看起来更强。实验B更符合产品目标,因为它改善了开发者体验,同时没有违反召回率护栏。
Before evaluating an LLM system, decide what success means for the user and which guardrails the system must respect. We want to generate evidence that supports a product decision.
在评估LLM系统之前,决定对用户而言成功意味着什么,以及系统必须遵守哪些护栏。我们希望生成支持产品决策的证据。
2. Treat offline evaluation like integration testing
2. 将离线评估视为集成测试
An LLM-based system continues to change after its first successful evaluation, so evaluation should not be a one-time exercise. Teams revise prompts, adopt new models, change how inputs and context are constructed, and refine the surrounding business logic.
基于LLM的系统在首次成功评估后仍会继续变化,因此评估不应是一次性的活动。团队会修改提示词、采用新模型、改变输入和上下文的构建方式,并优化周围的业务逻辑。
Any of these changes can improve the system, introduce a regression, or shift its behavior in an unexpected way.
这些变化中的任何一个都可能改进系统、引入回归,或以意想不到的方式改变其行为。
For that reason, we treated offline evaluation similarly to an end-to-end integration test. We reran it whenever we made a meaningful change to the prompt, model, input construction, or broader system logic.
因此,我们将离线评估视为端到端集成测试。每当对提示词、模型、输入构建或更广泛的系统逻辑做出有意义的更改时,我们都会重新运行它。
The evaluation also needed to be repeatable enough that each new result could be compared against a known baseline. For every run, we recorded the prompt, model, dataset version, and system configuration.
评估还需要具备足够的可重复性,以便每次新结果都能与已知基线进行比较。每次运行,我们都会记录提示词、模型、数据集版本和系统配置。
This made it possible to answer questions such as:
这使得回答以下问题成为可能:
- Did the new prompt improve precision without reducing recall?
- Did the model upgrade help across the dataset or only within certain categories?
- Did a change to the input or context fix one error pattern while introducing another?
- Did a change to the surrounding logic improve the result consistently, or simply shift where errors appeared?
- 新的提示词是否在不降低召回率的情况下提高了精确度?
- 模型升级是否在数据集整体上有所帮助,还是仅在某些类别中有效?
- 对输入或上下文的更改是否修复了一种错误模式,同时引入了另一种?
- 对周围逻辑的更改是否一致地改善了结果,还是仅仅转移了错误出现的位置?
Without this discipline, teams can easily compare results generated under different conditions and attribute an improvement to the wrong change.
没有这种纪律,团队很容易在不同条件下比较结果,并将改进错误地归因于错误的更改。
Change one major variable at a time
一次只更改一个主要变量
Repeatability alone is not enough. Experiments also need to be designed so that the cause of a result is clear.
仅靠可重复性是不够的。实验设计还需要确保结果的原因清晰明确。
We changed one major variable at a time and compared each run against a known baseline. For example, we evaluated a prompt revision separately from a model upgrade before testing the two together.
我们一次只更改一个主要变量,并将每次运行与已知基线进行比较。例如,我们分别评估了提示词修订和模型升级,然后再将两者一起测试。
This mattered because even small prompt changes could shift model behavior, while a model upgrade could affect quality, cost, latency, or output consistency. If both changed in the same experiment, we would not know which one caused the improvement or regression.
这很重要,因为即使是微小的提示词更改也可能改变模型行为,而模型升级可能影响质量、成本、延迟或输出一致性。如果在同一实验中两者都发生变化,我们就无法知道是哪一个导致了改进或退化。
We treated prompts and evaluation configurations like code. We versioned them, recorded what changed, kept previous configurations reproducible, and made rollback possible.
我们将提示词和评估配置视为代码。我们对它们进行版本控制,记录更改内容,保持先前配置的可复现性,并支持回滚。
| Run ID | Prompt version | Model version | Precision | Recall | Latency | Notes |
|---|---|---|---|---|---|---|
| R-001 | v1 | Model A | 0.71 | 0.78 | 1.2s | Baseline |
| R-002 | v2 | Model A | 0.75 | 0.77 | 1.2s | Prompt-only change |
| R-003 | v1 | Model B | 0.74 | 0.80 | 1.0s | Model-only change |
| 运行ID | 提示词版本 | 模型版本 | 精确度 | 召回率 | 延迟 | 备注 |
|---|---|---|---|---|---|---|
| R-001 | v1 | 模型A | 0.71 | 0.78 | 1.2秒 | 基线 |
| R-002 | v2 | 模型A | 0.75 | 0.77 | 1.2秒 | 仅提示词更改 |
| R-003 | v1 | 模型B | 0.74 | 0.80 | 1.0秒 | 仅模型更改 |
The values in the evaluation run tracking table above shown are hypothetical and included only to illustrate how evaluation runs can be tracked and compared.
上述评估运行跟踪表中的数值是假设性的,仅用于说明如何跟踪和比较评估运行。
Test model upgrades regularly
定期测试模型升级
When an LLM system underperforms, developers often respond by adding more instructions to the prompt. Sometimes that helps, but not always. For example, the prompt may be carrying complexity that comes from the model itself.
当LLM系统表现不佳时,开发者通常会在提示词中添加更多指令。有时这有帮助,但并非总是如此。例如,提示词可能承载了来自模型本身的复杂性。
A stronger model may perform better with a simpler prompt than an older model does with extensive tuning. Simpler prompts are also easier to understand, test, and maintain.
更强的模型可能用更简单的提示词就能比旧模型经过大量调优表现更好。简单的提示词也更容易理解、测试和维护。
Model upgrades still need careful evaluation. A new model may improve performance in one category while introducing regressions elsewhere. It may also affect cost, latency, output formatting, or compatibility with the existing pipeline.
模型升级仍需仔细评估。新模型可能在某一类别上提升性能,却可能在其他地方引入回退。它还可能影响成本、延迟、输出格式,或与现有管道的兼容性。
The evaluation process should be inexpensive and repeatable enough that testing a new model becomes routine. Any meaningful change to the prompt, model, or pipeline should go through offline evaluation before reaching production.
评估过程应足够廉价且可重复,使测试新模型成为常规操作。对提示词、模型或管道的任何有意义的更改,都应先经过离线评估,再进入生产环境。
3. Keep offline evaluation close to production
3. 让离线评估贴近生产环境
原文超出正文长度上限,此处截断——上游还有内容,完整版见上方「原文 ↗」。
更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力