karpathy-system-prompt-learning について
karpathy-system-prompt-learningは、背景知識や例、戦略を組み込んだシステムプロンプトを設計・改善するスキルです。エージェントの繰り返す失敗を再利用可能な指示に変える手順も扱います。
主な機能
- 01三層構造のプロンプト設計
- 02コーディング・分析・文章作成のテンプレート
- 03プロンプトの失敗診断
- 04プロンプトのバージョン管理
- 05失敗を指示に変換する規約
活用シーン
- 01新しいタスク向けのシステムプロンプト作成
- 02エージェントの反復的な失敗を受けた改善
- 03検証済みの戦略を記録して再利用
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ learnprompt/ andrej-karpathy-skills --skill karpathy-system-prompt-learningインストール後、Claude Code で/karpathy-system-prompt-learningを入力して読み込まれたか確認します。
詳細
スキル 13:システムプロンプト学習(システムプロンプト学習パラダイム)
出典:https://x.com/karpathy/status/1921368644069765486 「システムプロンプト学習 — 欠けているLLMの学習パラダイム」
基本原則
システムプロンプトは教科書です。教科書のように書きましょう。
Karpathyの洞察:LLMには3つの学習モード(事前学習、ファインチューニング、RL)があります。しかし、ほとんど活用されていない4つ目の方法があります。それがシステムプロンプト学習です。戦略をシステムプロンプトに明示的に組み込むほうが、再学習よりもサンプル効率が高く、モデルが自力で理解することに期待するよりも信頼性があります。
各タスクの前に、LLM向けの教科書を書くようなものだと考えてください。単なる指示ではなく、推論を伴う戦略です。
システムプロンプト学習フレームワーク
優れたシステムプロンプトには3つの層があります(人間の学習方法を反映しています)。
Layer 1: EXPOSITION (pretrain equivalent)
→ Background knowledge the model needs
→ Relevant concepts, terminology, context
→ "Here's what you need to know about [domain]"
Layer 2: WORKED EXAMPLES (SFT equivalent)
→ Step-by-step demonstration of correct behavior
→ Explicit reasoning traces
→ "Here's exactly how to handle [situation]"
Layer 3: STRATEGY (RL equivalent)
→ Explicit decision rules
→ Error patterns to avoid
→ "When you see X, do Y because Z"
ゼロからシステムプロンプトを作成する
Build a system prompt that teaches an LLM to [TASK] reliably.
Task description: [WHAT THE LLM SHOULD DO]
Current failure mode: [HOW IT CURRENTLY GOES WRONG]
Desired behavior: [EXACTLY WHAT GOOD LOOKS LIKE]
Structure the system prompt with all three learning layers:
Layer 1 — Exposition:
Write 2-3 paragraphs of background knowledge the LLM needs.
Include: key concepts, relevant context, domain vocabulary.
Layer 2 — Worked Examples:
Write 2 complete examples of the task done correctly.
Format: INPUT → [step-by-step reasoning] → OUTPUT
Show the thinking, not just the answer.
Layer 3 — Strategy:
Write explicit decision rules as IF/THEN/BECAUSE statements.
Include: common mistakes to avoid, edge cases to handle, quality checks.
End with: "Before responding, verify: [checklist of 3-5 quality checks]"
既存のシステムプロンプトを改善する
現在のシステムプロンプトがうまく機能していない場合:
Diagnose and improve this system prompt.
Current system prompt:
[PASTE CURRENT PROMPT]
Failure mode I'm seeing:
[DESCRIBE HOW IT'S GOING WRONG]
Example of bad output:
[PASTE BAD EXAMPLE]
Example of good output:
[PASTE GOOD EXAMPLE]
Analysis:
1. What's missing from the exposition layer? (background knowledge gaps)
2. What worked examples should I add?
3. What explicit rules would prevent this failure mode?
4. Is the prompt too restrictive? Too vague? Wrong framing?
Output: improved version of the system prompt with changes annotated.
戦略を組み込むテンプレート
コーディングタスク向け
SYSTEM PROMPT: [CODING TASK]
You are an expert [LANGUAGE] developer. Follow this exact strategy:
UNDERSTANDING PHASE (always do this first):
- Restate the task in your own words
- List all edge cases you can think of
- Identify the one tricky part
IMPLEMENTATION PHASE:
- Start with the simplest working version
- Add complexity only when simple version fails
- Comment every non-obvious line with WHY
VERIFICATION PHASE (always do this last):
- Trace through your code with one concrete example
- Check: does it handle empty input? Large input? Wrong type?
- Confirm: could a junior dev maintain this?
NEVER:
- Assume the input is well-formed without checking
- Add dependencies without saying why
- Write clever code when simple code works
分析タスク向け
SYSTEM PROMPT: [ANALYSIS TASK]
You are an analytical expert. Follow this strategy:
GROUNDING:
- Always cite specific evidence before making claims
- Confidence levels: CERTAIN / LIKELY / SPECULATIVE — always label which
- If you don't know something, say so explicitly
STRUCTURE:
- Lead with the conclusion, then the evidence
- One claim per paragraph
- Maximum 3 levels of nesting
QUALITY CHECKS before responding:
- [ ] Every claim has evidence?
- [ ] Confidence levels labeled?
- [ ] Would an expert in this field agree with this framing?
- [ ] Am I answering the actual question or a related easier one?
クリエイティブ/ライティングタスク向け
SYSTEM PROMPT: [WRITING TASK]
Writing strategy for this task:
VOICE:
[Describe the tone, style, what to avoid]
STRUCTURE:
[Describe the expected output format]
QUALITY STANDARD:
A response is good when [describe what success looks like].
A response is bad when [describe common failure modes].
EXAMPLE OF GOOD OUTPUT:
[Paste one example]
EXAMPLE OF BAD OUTPUT (and why):
[Paste one example with annotation]
プロンプトのバージョン管理
コードと同じように、システムプロンプトの反復を追跡します。
# [PROMPT NAME] — Version History
## v3 (current) — [DATE]
Change: Added explicit "verification phase" checklist
Reason: v2 was skipping edge case checking
Result: Failure rate dropped from ~30% to ~5%
## v2 — [DATE]
Change: Added worked examples section
Reason: v1 was too abstract; model wasn't following the strategy
Result: Moderate improvement
## v1 — [DATE]
Initial version: [PASTE]
メタプロンプト(LLMを使ってプロンプトを書く)
Help me write a system prompt for this agent.
Agent task: [WHAT IT SHOULD DO]
I'll be using this with: [CLAUDE / GPT-4 / etc.]
Critical behavior: [WHAT MUST ALWAYS HAPPEN]
Failure modes to prevent: [WHAT GOES WRONG WITHOUT GOOD PROMPTING]
Apply the three-layer system prompt learning framework:
1. Exposition (what the model needs to know)
2. Worked examples (demonstrate correct behavior)
3. Strategy rules (explicit IF/THEN/BECAUSE)
Then: suggest 3 variations I could test to find the best version.
ワークフロー
ワークフローに属する項目:偏見にとらわれない意思決定(ステップ3/終点)
| 位置 | 上流 | 下流 |
|---|---|---|
| ステップ3(定着) | karpathy-understanding-first(検証後) | 定着完了、再利用可能 |
全体の流れ:llm-simulator → understanding-first → system-prompt-learning
日常的な開発でも単独で使用します。エージェントが同じ種類の間違いを繰り返すときは、いつでもこのスキルを使うべきです。
プロンプトの契約
Extract a system prompt lesson from this failure/pattern: <DESCRIBE_THE_RECURRING_ERROR>. Produce: 1) Trigger condition — when does this error occur, 2) Correct strategy — step-by-step what the agent should do instead, 3) Anti-patterns — what specifically to avoid, 4) Worked example — a before/after showing the improvement, 5) Concise instruction block (< 200 words) ready to paste into system prompt or SKILL.md.
検証チェックリスト
- 発動条件が具体的に記述されている(「ときどき」ではない)
- 戦略が段階的に示されている(曖昧な提案ではない)
- アンチパターンに具体的な誤ったやり方が列挙されている
- before/afterの比較例がある
- 指示ブロックが200語未満で、そのまま貼り付けられる
- 新しいテストケースで指示ブロックの有効性を検証済み