帮助用户系统检查外部输入有效性,降低错误、异常与安全风险。
复制安装指令,让 AI 自动完成配置 · 推荐新手
请帮我安装 askskill 上的 "Validating Inputs" 技能: 1. 下载 https://raw.githubusercontent.com/obra/clank/main/skills/coding/validating-inputs/SKILL.md 2. 保存为 ~/.claude/skills/validating-inputs/SKILL.md 3. 装好后重载技能,告诉我可以用了
请为一个用户注册 API 设计完整的输入校验方案,覆盖邮箱、密码、用户名、手机号的格式校验、长度限制、必填规则、错误提示与服务端兜底校验,并给出示例代码。
一套结构化的参数校验规则、错误处理建议和可落地的示例代码。
我有一个 CSV 导入流程,请帮我列出需要验证的输入项,包括空值、字段类型、日期格式、重复记录、异常字符和越界数值,并输出校验清单与处理策略。
面向数据导入场景的校验清单,以及对应的异常处理与拦截策略。
请检查一个 Web 表单可能存在的输入风险,重点关注 SQL 注入、脚本注入、路径遍历和非法文件上传,并给出输入校验与过滤建议。
一份输入安全风险清单,附带针对性的校验、过滤和防护建议。
Professional-grade software never outputs garbage regardless of what it receives. "Garbage in, garbage out" is the mark of sloppy, insecure code.
Core principle: Check all data from external sources. Validate all routine parameters from untrusted sources. Decide consciously how to handle invalid data.
Modern standard: "Garbage in, nothing out" OR "Garbage in, error message out" OR "No garbage allowed in"
Violating the letter of this rule is violating the spirit of defensive programming.
Always use when writing functions that receive:
Warning signs you need this:
Don't skip when:
Use for: Conditions that indicate bugs in YOUR code
def calculate_velocity(distance: float, time: float) -> float:
# Preconditions: These should NEVER be violated if caller is correct
assert distance >= 0, "distance cannot be negative"
assert time > 0, "time must be positive"
result = distance / time
# Postcondition: Result should be reasonable
assert result >= 0, f"velocity cannot be negative: {result}"
return result
Assertions are:
Use for: Conditions you expect might occur in production
def calculate_average_score(scores: list[float]) -> float:
"""Calculate average of test scores (must be 0-100)."""
# Error handling: Validate external data
if scores is None:
raise ValueError("scores cannot be None")
if not scores:
raise ValueError("Cannot calculate average of empty score list")
# Validate each score
for i, score in enumerate(scores):
if not isinstance(score, (int, float)):
raise TypeError(f"Score {i} is not a number: {score}")
if score < 0 or score > 100:
raise ValueError(f"Score {i} out of range [0-100]: {score}")
result = sum(scores) / len(scores)
# Postcondition: Verify result is valid
assert 0 <= result <= 100, f"Calculated average out of range: {result}"
return result
Error handling:
| Situation | Approach | Example |
|---|---|---|
| External data | Validate everything | Check ranges, types, formats, lengths |
| Routine parameters | Check if from untrusted source | Validate or document assumptions |
| Internal invariants | Assert they hold | Assert postconditions, state assumptions |
| Null/None | Check explicitly | if value is None: raise ValueError() |
| Empty collections | Decide if valid or error | Empty list error or return default? |
| Type mismatches | Check with isinstance | if not isinstance(score, (int, float)) |
| Range violations | Check bounds | if score < 0 or score > 100 |
…
用测试驱动方式编写流程文档,先验证再成稿,提升技能说明的可靠性。
为工程师生成分步实施计划,帮助在陌生代码库中快速落地任务。
在继续开发前发起代码审查,依据计划或需求检查实现质量与偏差。
帮助你为变量选择清晰准确、易维护的命名,提升代码可读性。
用红绿重构式迭代测试流程文档,发现漏洞并持续完善说明。
在宣布任务完成前运行验证命令并核对结果,确保结论可靠无误。
帮助你在数据流经各层时建立分层校验,提前阻断缺陷与安全风险。
帮助开发者在认证、输入处理、密钥和敏感功能开发中进行系统安全审查
对 AI 生成结果执行确定性校验,如 JSON Schema、OpenAPI 响应与 SQL 语法。
在智能体执行前,按国际标准自动核验文档合规性与完整性。
自动扫描与分析数据,发现校验规则并生成健康评分,免写验证规则。
为结构化输出执行安全不变量校验,防止模型擅自填写锁定字段