← Back to learning path

This chapter has not been reviewed in English; the original Simplified Chinese is shown.

Chapter · Published

AI 应用测试:事实、行为与安全三层回归 (original language)

建立固定样本和程序断言,持续发现答案、工具轨迹和权限回归。

Source: knowledge/p24-c/collection_0587a2bfc47ea3584d1b1c59/tutorials/ai-app-evaluation-and-tests.mdAI application development
Chapter progress 0%Learning path progress 0% · 0/10 chapters completedContinue learning path →

AI 应用测试不能只看字符串相似度。应分别测试事实依据、输出格式、工具轨迹、拒答边界、延迟和成本。

核心概念

金丝雀样本用于事实和引用,程序断言用于 schema、工具和权限,人工抽查用于难以自动判断的质量。每次评测记录模型、提示、检索器和数据版本。

可运行示例

def assert_response(response: dict) -> None:
    assert set(response) >= {'answer', 'sources'}
    assert isinstance(response['sources'], list)
    assert response.get('tool_calls', []).count('delete_record') == 0
    if response.get('answer') == '':
        raise AssertionError('empty answer')

assert_response({'answer': 'ok', 'sources': [], 'tool_calls': []})

操作步骤

  1. 从脱敏真实任务中建立正常、边界、攻击和无结果样本。
  2. 写 schema、权限、工具次数和引用存在性的硬断言。
  3. 固定模型与检索版本运行回归,保存失败输入和轨迹摘要。
  4. 将高风险失败加入下一轮回归集,并由人工确认修复。

Use cases

适合迭代频繁、需要审计或有高错误代价的 AI 应用。

常见问题

LLM 评分可以替代程序断言吗? 不能,安全和副作用必须用程序断言。

测试样本能含客户隐私吗? 应脱敏、最小化并限制访问。

官方参考

OpenAI Evals;Google ML test score。

最后核对日期:2026-11-16。版本、接口和安全边界以链接的官方资料为准;本文不虚构性能或费用结论。

Product Hub Demo · V0.3