Promotes type-safe parsing over validation to enforce data invariants at the type level.
Install
mkdir -p .claude/skills/parse-dont-validate && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/16359" && unzip -o skill.zip -d .claude/skills/parse-dont-validate && rm skill.zipInstalls to .claude/skills/parse-dont-validate
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
「Parse, don't validate」原則に基づくコードレビューと設計支援。validateパターン(チェックして結果を捨てる) をparseパターン(チェック結果を型で保持)に変換し、型システムで不変式を強制する設計を促進する。 コードレビュー、新規実装、リファクタリング時にvalidation関数の改善が必要な場合に使用。 対象言語: Rust, Haskell, TypeScript, Scala, Java, Go, Python。 トリガー:「バリデーションを改善して」「型で保証したい」「shotgun parsingを直して」 「不正な状態を型で防ぎたい」「Maybeを減らしたい」といった型安全性関連リクエストで起動。Key capabilities
- →Convert validation patterns to parsing patterns
- →Promote designs that enforce invariants with type systems
- →Improve validation functions during code review
- →Refactor existing implementations to use parsing
- →Detect anti-patterns like `validate*()` returning `()`
- →Transform lists into non-empty arrays or maps
How it works
The skill transforms validation functions that discard information into parsing functions that retain information within a type, ensuring type safety.
Inputs & outputs
When to use parse-dont-validate
- →Replacing validation checks with types
- →Preventing shotgun parsing
- →Improving type safety in APIs
About this skill
Parse, Don't Validate
情報を捨てるvalidationから、情報を保持するparsingへ変換する。
核心原則
チェック結果を捨てずに型で保持する。
| アプローチ | 戻り値 | 情報 | 問題 |
|---|---|---|---|
| Validate | () / void / bool | 捨てる | 再チェック必要、型が保証しない |
| Parse | 型付き値 | 保持 | 一度のチェックで済む、型が保証 |
判断フロー
チェック関数を書こうとしている
↓
戻り値は何か?
├─ () / void / bool → Validateパターン(問題あり)
└─ 新しい型 → Parseパターン(推奨)
アンチパターン検出
以下のパターンを見つけたら変換を検討:
❌ validate*() → ()
❌ check*() → bool
❌ assert*() → ()(表明目的以外)
❌ is*() → bool(分岐後に同じ値を使う場合)
❌ "should never happen" コメント
❌ case None/null の after 正常ケース
変換パターン
1. NonEmpty変換
// ❌ Validate: 情報を捨てる
function validateNonEmpty(list: string[]): void {
if (list.length === 0) throw new Error("list cannot be empty");
}
// ✅ Parse: 情報を保持する
type NonEmptyArray<T> = [T, ...T[]];
function parseNonEmpty<T>(list: T[]): NonEmptyArray<T> {
if (list.length === 0) throw new Error("list cannot be empty");
return list as NonEmptyArray<T>;
}
2. 重複キー検出
// ❌ Validate: チェックして捨てる
function checkNoDuplicateKeys(pairs: [string, unknown][]): void {
const seen = new Set<string>();
for (const [key] of pairs) {
if (seen.has(key)) throw new Error(`duplicate key: ${key}`);
seen.add(key);
}
}
// ✅ Parse: Mapに変換して保持
function parseToMap(pairs: [string, unknown][]): Map<string, unknown> {
const result = new Map<string, unknown>();
for (const [key, value] of pairs) {
if (result.has(key)) throw new Error(`duplicate key: ${key}`);
result.set(key, value);
}
return result;
}
3. Smart Constructor
// ❌ 外部から直接構築可能
pub struct Email(String);
// ✅ Parse: Smart constructorで検証済みを保証
mod email {
pub struct Email(String); // private field
impl Email {
pub fn parse(s: &str) -> Result<Self, ParseError> {
if s.contains('@') && s.len() > 3 {
Ok(Email(s.to_string()))
} else {
Err(ParseError::InvalidEmail)
}
}
pub fn as_str(&self) -> &str { &self.0 }
}
}
Shotgun Parsing
避けるべき: 入力検証がコード全体に散らばるパターン。
❌ 処理開始 → 部分処理 → 検証失敗 → ロールバック困難
✅ 境界で完全Parse → 処理は型を信頼 → 安全
適用指針
推奨
- システム境界での入力処理(JSON, CLI引数, DB値)
- 複雑な不変式を持つドメインモデル
Maybe/Optionが頻出する箇所- "should never happen" コメントがある箇所
過剰適用を避ける
- 単一の
error "impossible"だけなら改修コスト大 - 既存APIとの互換性が必要な場合
- パフォーマンスクリティカルなホットパス
レビュー観点
コードレビュー時の確認ポイント:
- 戻り値チェック:
void/()を返す検証関数はないか - 型の精度: より精密な型で表現できないか
- 境界の明確さ: 入力パースはシステム境界で完結しているか
- shotgun: 検証ロジックがコード全体に散らばっていないか
詳細ガイドライン
言語別の実装パターン、型設計の詳細は references/patterns.md を参照。
関連スキル(併読推奨)
このスキルを使用する際は、以下のスキルも併せて参照すること:
domain-primitives-and-always-valid: スマートコンストラクタによるドメインプリミティブの設計when-to-wrap-primitives: プリミティブ型をラップすべきかの判断基準domain-building-blocks: 値オブジェクトの設計(parseパターンの適用先)
When not to use it
- →When the cost of refactoring for a single `error "impossible"` is too high
- →When compatibility with existing APIs is required
- →In performance-critical hot paths
Limitations
- →Not suitable for single `error "impossible"` cases due to high modification cost
- →Not recommended when existing API compatibility is a concern
- →Avoid in performance-critical hot paths
How it compares
This approach uses the type system to guarantee invariants, unlike manual validation which requires re-checking and does not provide type guarantees.
Compared to similar skills
parse-dont-validate side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| parse-dont-validate (this skill) | 0 | 7mo | No flags | Intermediate |
| deepwiki-rs | 25 | 11mo | Review | Intermediate |
| tldr-code | 1 | 8mo | Review | Advanced |
| harness-boundary | 0 | 4mo | No flags | Advanced |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by j5ik2o
View all by j5ik2o →You might also like
deepwiki-rs
sopaco
AI-powered Rust documentation generation engine for comprehensive codebase analysis, C4 architecture diagrams, and automated technical documentation. Use when Claude needs to analyze source code, understand software architecture, generate technical specs, or create professional documentation from any programming language.
tldr-code
parcadei
Token-efficient code analysis via 5-layer stack (AST, Call Graph, CFG, DFG, PDG). 95% token savings.
harness-boundary
zkp442910864
Harness 工程边界约束与变更评估。Use when: 评估代码变更影响范围、确认安全边界、检查工程规范合规性、审查变更风险等级。
mcp-builder
anthropics
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
ast-grep-find
parcadei
AST-based code search and refactoring via ast-grep MCP
lint-and-validate
davila7
Automatic quality control, linting, and static analysis procedures. Use after every code modification to ensure syntax correctness and project standards. Triggers onKeywords: lint, format, check, validate, types, static analysis.