用 Promptfoo 检查提示词改动是否把账单工单错分给技术支持
用 Promptfoo 对比两版工单分类提示词,通过三个合成工单识别账单误分与输出大小写不符。本文提供实际运行的 APIBox 配置、断言和测试结果,说明如何区分模型分类错误、格式错误与接口故障,并明确小样本回归测试的适用范围,帮助团队在上线前检查提示词变更。
通过使用合成工单设置负面控制(Negative Control),在正式发布前有效捕获路由错误。
候选提示词中的错误规则是故意加入的反例,不是客户事故。
配置验证环境
首先,确保安装 promptfoo 0.125.1 版本。测试的核心在于通过 promptfooconfig.yaml 明确定义基准(Baseline)和候选(Candidate)逻辑,并设置严格的断言检查。
请将 API 密钥存储在环境变量 APIBOX_API_KEY 中,并在 .gitignore 中忽略密钥文件和包含敏感数据的测试结果文件。以下是我们的测试配置:
description: Ticket routing regression example
prompts:
- id: baseline
raw: 'Classify the ticket as billing or technical. Payment, invoices and refunds are billing. Crashes and connectivity are technical. Return only the label. Ticket: {{ticket}}'
- id: candidate
raw: 'Classify the ticket as billing or technical. If it mentions API, choose technical even for an invoice dispute; otherwise payment and refunds are billing. Return only the label. Ticket: {{ticket}}'
providers:
- id: openai:chat:gemini-3.8-flash
config:
apiBaseUrl: https://api.apibox.cc/v1
apiKeyEnvar: APIBOX_API_KEY
temperature: 0
max_tokens: 256
timeout: 30000
maxRetries: 0
tests:
- vars:
ticket: 'I was charged twice for my API subscription. Please refund the duplicate payment.'
assert:
- type: equals
value: billing
- vars:
ticket: 'The API endpoint returns connection refused.'
assert:
- type: equals
value: technical
- vars:
ticket: 'Please send me an invoice for last month.'
assert:
- type: equals
value: billing
执行测试
使用以下命令运行测试,禁用缓存以实际重新请求模型,并将并发数限制为 1 以便进行逐条调试:
npx --yes promptfoo@0.125.1 eval --no-cache --max-concurrency 1 -o results.json
结果分析
针对Promptfoo 0.125.1进行的6次APIBox gemini-3.8-flash推断评估显示:Baseline处理重复收费工单返回了“Billing”(大写),因与“billing”不匹配而失败;Candidate对同工单返回“technical”,因语义分类错误而失败。其余4次评估通过,错误数为0。系统因断言失败而非提供商故障返回exit 100。
小样本无法证明生产环境的准确性或模型输出的确定性,即使在temperature 0且不使用缓存的情况下也是如此;—no-cache仅确保请求新鲜;归一化处理需视下游业务合同而定,建议单独评估。
后续应加入匿名化的边界工单,分别查看每个标签的失败案例,并重复执行验证。
可在 APIBox 控制台 获取密钥,费用以价格页与实际账单为准。
参考文档: OpenAI-compatible provider · Assertions · APIBox model directory
立即体验,注册后即可使用 30+ 模型,一个 Key 全搞定
免费注册 →