
karpathy-system-prompt-learning
Write explicit strategy into system prompts as a learning mechanism — making LLM behavior more predictable and teachable through prompt-as-textbook approach. Use this skill when the user wants to improve an agent or LLM's performance on a specific task through system prompts, needs to encode a strategy or workflow into a prompt, wants consistent LLM behavior, or says "improve system prompt", "encode this strategy", "prompt engineering", "make agent follow this workflow", "prompt as textbook". Based on Karpathy system prompt learning post.
- Installs
- 127
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/learnprompt/andrej-karpathy-skills --skill karpathy-system-prompt-learning- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads karpathy-system-prompt-learning automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Skill 13: System Prompt Learning(系统提示学习范式)
Source: https://x.com/karpathy/status/1921368644069765486 "System prompt learning — missing LLM learning paradigm"
Core Principle
The system prompt is a textbook. Write it like one.
Karpathy's insight: there are three learning modes for LLMs (pretrain, finetune, RL) — but there's a fourth that's massively underused: system prompt learning. Explicitly encoding strategy into the system prompt is more sample-efficient than retraining and more reliable than hoping the model figures it out.
Think of it as writing a textbook for the LLM before each task. Not just instructions — strategy with reasoning.
The System Prompt Learning Framework
Good system prompts have three layers (mirroring how humans learn):
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"
Building a System Prompt from Scratch
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]"
Improving an Existing System Prompt
When your current system prompt isn't working well:
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.
Strategy Encoding Templates
For coding tasks
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
For analysis tasks
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?
For creative/writing tasks
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 Version Control
Track your system prompt iterations like code:
# [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]
The Meta-Prompt (write prompts with an 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.
Workflow
属于工作流:反偏见决策(第3步/终点)
| 位置 | 上游 | 下游 |
|---|---|---|
| 第3步(沉淀) | karpathy-understanding-first(验证后) | 沉淀完成,可复用 |
完整链路:llm-simulator → understanding-first → system-prompt-learning
也在日常开发中独立使用——任何时候 Agent 反复犯同一类错,都应该触发本 Skill。
Prompt Contract
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.
Verification Checklist
- 触发条件描述具体(不是「有时候」)
- 策略是 step-by-step 的(不是模糊建议)
- 反模式列出了具体的错误做法
- 有 before/after 对比示例
- 指令块 < 200 words,可直接粘贴
- 在新的测试 case 上验证过指令块有效
FAQ
What does the karpathy-system-prompt-learning skill do?
Write explicit strategy into system prompts as a learning mechanism — making LLM behavior more predictable and teachable through prompt-as-textbook approach. Use this skill when the user wants to improve an agent or LLM's performance on a specific task through system prompts, needs to encode a strategy or workflow into a prompt, wants consistent LLM behavior, or says "improve system prompt", "encode this strategy", "prompt engineering", "make agent follow this workflow", "prompt as textbook". Based on Karpathy system prompt learning post.
How do I install karpathy-system-prompt-learning?
Run npx skills add https://github.com/learnprompt/andrej-karpathy-skills --skill karpathy-system-prompt-learning in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/karpathy-system-prompt-learning/ (personal) or .claude/skills/karpathy-system-prompt-learning/ (project).
Which AI agents can use karpathy-system-prompt-learning?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is karpathy-system-prompt-learning safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains karpathy-system-prompt-learning?
It is published by learnprompt in learnprompt/andrej-karpathy-skills. It has 127 recorded installs.
More from learnprompt/andrej-karpathy-skills
karpathy-agentic-engineering
learnprompt/andrej-karpathy-skills
Apply Karpathy-style agentic engineering to any coding or building task. Use this skill when the user wants to set up an agent-driven workflow, needs to write a CLAUDE.md or AGENTS.md, wants to orchestrate agents with clear success criteria, or says things like "agent loop", "let the agent handle it", "agentic coding", "set up agent workflow". Includes the 7-step inner loop from Karpathy claude coding notes.
karpathy-methodology
learnprompt/andrej-karpathy-skills
Apply Andrej Karpathy AI methodology and principles from his 2023-2026 insights. Use this skill when the user wants to apply Karpathy-style thinking, needs guidance on agentic engineering, LLM knowledge bases, minimalist coding, understanding-first principles, or any of the 14 core methodologies distilled from his work. Also triggers on: "karpathy method", "karpathy approach", "karpathy way", "AK style", "like karpathy does", "karpathy principles", or when user asks how Karpathy would approach any programming or AI problem.
karpathy-minimalism
learnprompt/andrej-karpathy-skills
Apply Karpathy-style minimalism and anti-dependency principles to code and system design. Use this skill when the user wants to reduce dependencies, avoid supply chain risks, rewrite something in pure Python or minimal code, audit a project for bloat, design agent-native CLI tools, or says "too many dependencies", "minimize deps", "pure python", "yoink this", "vibe code this", "no frameworks", "agent-native design". Based on 28k-like litellm attack post and 25k-like 243-line GPT post.
karpathy-understanding-first
learnprompt/andrej-karpathy-skills
Apply the Karpathy understanding-first principle — verify what AI built, own your understanding, map the jagged capability landscape of LLMs. Use this skill when the user has used AI to build something and needs to verify it, wants to audit their own understanding, needs to know where LLMs are reliable vs unreliable, or says "verify this", "do I actually understand this", "what can I trust the AI on", "jagged capabilities", "understanding not outsourcing". Based on 46k-like quote post.
karpathy-education-first
learnprompt/andrej-karpathy-skills
Apply the education-first mindset — make everything you build teachable, create nano-project explanations, write for beginners. Use this skill when the user wants to explain a project to beginners, create a tutorial from code, write documentation that teaches (not just documents), make a concept accessible, or says "make this teachable", "explain like im a beginner", "nano project version", "teaching version", "explain from scratch", "blog post about this". Based on Karpathy 243-line GPT and Eureka Labs posts.
karpathy-llm-wiki
learnprompt/andrej-karpathy-skills
Build and maintain an LLM-powered personal knowledge base or wiki. Use this skill when the user wants to organize research notes, build a second brain, set up an Obsidian vault with LLM compilation, ingest papers or articles automatically, or mentions "personal knowledge base", "LLM wiki", "second brain", "knowledge management", "ingest papers", "obsidian + LLM". Based on Karpathy Gist and 59k-like post.
Popular ai & agents skills
google-agents-cli-publish
google/agents-cli
This skill should be used when the user wants to "publish an agent", "publish my ADK agent", "register an agent with Gemini", "publish to Gemini" (formerly Gemini Enterprise), or needs guidance on the agents-cli publish gemini command. Also use when the user wants to "manage agents in Agent Registry", "list/update/delete registered agents", or "register an MCP server". Covers ADK vs A2A registration modes, programmatic and interactive usage, flag reference, auto-detection from deployment metadata, Agent Registry fleet management, and troubleshooting. Part of the agents-cli skills suite. Do NOT use for deployment (use google-agents-cli-deploy).
google-agents-cli-eval
google/agents-cli
This skill should be used when the user wants to "run an evaluation", "evaluate my agent", "evaluate my ADK agent", "write an eval dataset", "analyze eval failures", "compare eval results", "optimize agent", or needs guidance on the Gemini platform eval methodology and the Quality Flywheel. Covers eval metrics, dataset schema, LLM-as-judge scoring, and common failure causes. Applies to any agents-cli project, whatever framework the agent is written in. Do NOT use for agent API code patterns (ADK: use google-agents-cli-adk-code), deployment (use google-agents-cli-deploy), or project scaffolding (use google-agents-cli-scaffold).
skill-creator
anthropics/skills
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.
codex-pet
prime-skills/runcomfy-agent-skills
Codex Pet generator on RunComfy. Build a Codex-compatible Codex Pet spritesheet.webp + pet.json from a single reference image, drop it into ${CODEXHOME:-$HOME/.codex}/pets/ / and Codex picks it up as a custom Codex Pet next to the 8 built-ins. This skill produces the exact Codex Pet atlas Codex expects (1536x1872 PNG/WebP, 8 cols x 9 rows, 192x208 cells, 9 animation states — idle, running-right, running-left, waving, jumping, failed, waiting, running, review). Calls OpenAI GPT Image 2 edit ONCE via the local RunComfy CLI as runcomfy run openai/gpt-image-2/edit to produce a canonical Codex Pet pose, then assembles all 9 animation rows programmatically with ImageMagick micro-transforms — no Codex Pro, no $imagegen, no OPENAIAPIKEY required, only RUNCOMFYTOKEN. Triggers on "codex pet", "create codex pet", "make codex pet", "hatch codex pet", "/hatch image", "desktop pet codex", "codex pets", "spritesheet.webp", or any explicit ask to build a custom pet for OpenAI Codex.
full-output-enforcement
leonxlnx/taste-skill
Overrides default LLM truncation behavior. Enforces complete code generation, bans placeholder patterns, and handles token-limit splits cleanly. Apply to any task requiring exhaustive, unabridged output.
executing-plans
obra/superpowers
Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available