Original Note

验证工作 - Always Verify - Read

Always provide Claude a way to verify its work

核心原则:让 Claude 有能力验证自己的产出是否正确,而非盲目提交。


三种验证策略

策略 说明
提供验证标准 在 prompt 中明确预期输出,附测试用例
UI视觉验证 截图对比,列出差异并修复
解决根本原因 不掩盖错误,定位根因并修复

Prompt 对比示例

策略 1:提供验证标准

Before After
"implement a function that validates email addresses" "write a validateEmail function. example test cases: user@example.com is true, invalid is false, user@.com is false. run the tests after implementing"

策略 2:UI视觉验证

Before After
"make the dashboard look better" "[paste screenshot] implement this design. take a screenshot of the result and compare it to the original. list differences and fix them"

策略 3:解决根本原因

Before After
"the build is failing" "the build fails with this error: [paste error]. fix it and verify the build succeeds. address the root cause, don't suppress the error"

具体命令与参数

此技巧主要通过 prompt 设计 实现,无特定 CLI 命令。

Prompt 元素 作用
example test cases: ... 提供明确的输入/输出预期
run the tests after implementing 强制执行验证步骤
take a screenshot of the result 触发视觉对比验证
address the root cause 禁止表面修复,要求深入排查

适用场景

场景 推荐策略
功能实现(如新函数) 提供测试用例 + 要求运行测试
UI改动 截图对比 + 列出差异
Bug修复 附错误日志 + 要求解决根因
API开发 提供请求/响应示例 + 要求测试调用

Prompt 模板

功能实现模板

实现 [功能名称]。

测试用例:
- 输入 A → 预期输出 B
- 输入 C → 预期输出 D

完成后运行测试并确认全部通过。

UI改动模板

[粘贴设计截图]

实现这个设计。完成后截图对比:
1. 截取实现结果
2. 列出与原设计的差异
3. 逐一修复差异

Bug修复模板

错误信息:
[粘贴完整错误日志]

修复并验证:
1. 定位根本原因(不是表面现象)
2. 修复代码
3. 运行 [构建命令] 确认成功
4. 确保不引入新问题

相关链接