Prompt Library
A collection of reusable, task-oriented prompt templates
This is your prompt arsenal. We've collected and organized the most practical, battle-tested prompt templates across the industry -- covering everything from basic text classification to complex code generation.
Turn this chapter's knowledge into practical skills
Enter the interactive lab and practice Prompt with real tasks. Get started in 10 minutes.
These templates aren't rigid rules. They're reusable starting points. Copy them, fill in your specific Context and Constraints, and you've got a high-quality prompt in seconds.
Why Use a Template Library?
| Advantage | Description |
|---|---|
| Save time | Skip the blank-page problem. Start with a proven framework. |
| Better quality | Templates bake in techniques that work (Chain-of-Thought, Few-Shot, etc.). |
| Standardization | Unify your team's prompt style for easier maintenance and collaboration. |
| Fewer blind spots | Good templates remind you to include context and output format requirements. |
Core Prompt Structure
A solid general-purpose prompt usually has four core elements (CRDO):
graph LR
C[Context<br>Background info] --> P[Prompt]
R[Role<br>Role assignment] --> P
T[Task<br>Specific task] --> P
O[Output<br>Output requirements] --> P
Or as a more intuitive text structure:
# Role
You are a [expert role] skilled in [core competency].
# Context
I'm facing [specific situation/problem] and need [specific goal].
# Task
Please complete the following:
1. [Step 1]
2. [Step 2]
# Constraints
- [Constraint 1, e.g., word limit]
- [Constraint 2, e.g., tone of voice]
# Output Format
Please output in [Markdown/JSON/list] format.
Template Library Navigation
We've organized prompts by task type. Click any link to jump to the template page.
📊 Classification & Analysis
For labeling, sentiment analysis, intent detection, and similar tasks.
- Classification: General text classification.
- Sentiment Analysis: Detect sentiment polarity (positive/negative/neutral).
- Few-shot Sentiment: Boost accuracy with Few-shot examples.
🧠 Reasoning & Logic
For tasks that need logical thinking, math, or complex problem-solving.
- Reasoning: General logical reasoning (CoT).
- Mathematics: Math problem solving.
- Truthfulness: Reduce hallucinations, improve factual accuracy.
📝 Generation & Creativity
For writing, brainstorming, image generation prompts, and more.
- Creativity: Creative writing templates.
- Text Summarization: Extract summaries quickly.
- Image Generation: Craft prompts for Midjourney/Stable Diffusion.
💻 Coding & Engineering
For code generation, explanation, debugging, and refactoring.
- Coding: Code generation and optimization.
- Information Extraction: Pull entities or data from unstructured text.
- Question Answering: Precise Q&A based on documents or knowledge bases.
🛡️ Safety & Evaluation
Model security, red teaming, and output quality assessment.
⚠️ Note: Adversarial prompts are for Red Teaming and security research only. Don't use them for malicious purposes.
- Evaluation: Prompts for evaluating model output quality.
- Adversarial: Common attack patterns and defenses.
- Prompt Leaking: Detecting and preventing prompt leakage.
- Jailbreaking: Jailbreak examples (research only).
How to Use These Templates
- Copy: Find a template that matches your task, copy it.
- Fill: Replace the
[variables]with your actual business content. - Test: Run the prompt, observe the output.
- Iterate: If the result isn't great, tweak the
ContextorConstraintsuntil you're happy.
🌟 Universal Starter Template
Not sure which template to use? Start here:
# Role
You are an experienced [domain expert] focused on providing high-quality solutions for [target audience].
# Task
Given the following [input content], perform [specific operation (e.g., analyze, summarize, rewrite)].
# Input Data
"""
[Paste your text/data here]
"""
# Constraints
- Keep the tone [professional/friendly/objective].
- Focus on [key point 1] and [key point 2].
- If you encounter [situation A], then [response action].
# Output
Please output the result in [specific format].
Takeaways
- Don't memorize templates: Understanding the logic behind them matters more than rote memorization.
- Context is King: No matter how good the template is, providing accurate, rich context is always the key to better results.
- Keep iterating: Prompt development is an experimental process. There's no perfect prompt -- only prompts that keep getting better.
📚 相关资源
❓ 常见问题
关于本章主题最常被搜索的问题,点击展开答案
Prompt 模板库到底是给谁用的,新手直接抄会不会出问题?
模板是可复用的起点,不是万能咒。本章用 CRDO 四要素(Context / Role / Task / Output)拼出通用骨架,你抄过去后必须把 [变量] 换成自己的业务上下文,再调 Constraints。直接套用最大的坑是 Context 没填,模型只能瞎猜,输出质量比你自己写还差。
CRDO 四要素少写一个会怎样?
Role 缺失 → 模型用「通用助手」语气,专业度不够;Context 缺失 → 模型瞎猜业务背景,幻觉飙升;Task 写得模糊 → 输出方向偏;Output Format 没定 → 每次结构不一样,下游代码解析炸。最常被偷懒省掉的是 Output Format,恰好是稳定性损失最大的那一段。
万能起始模板和分类专用模板,应该先用哪个?
不确定任务类型就先用万能模板(Role + Task + Input Data + Constraints + Output)跑通;任务清晰后再切到专用模板,比如分类用 Classification、抽取用 Information Extraction、代码用 Coding。专用模板已经把这类任务踩过的坑都嵌进去了,比通用版稳。
Prompt 模板要不要自己维护一份?放哪里合适?
团队规模过 3 人就值得维护。把模板和「核心要素 + 变量」一起放进 Git(不要塞到飞书文档),每次迭代写 changelog;生产用的 prompt 单独建仓,加版本号、负责人、A/B 数据。这样改 prompt 等于改代码,可 review、可回滚、可追踪谁动过。
为什么模板库还分了「安全与评估」类,对抗类 prompt 普通团队也要学吗?
需要。即便不做红队,产品上线后大概率会被用户尝试 prompt injection、jailbreak、prompt leaking。这一类模板的价值在于让你提前看到攻击长什么样,再回头加防御(输入分区、threat model 声明、output filtering)。本站只展示防御视角,不提供绕过安全策略的可执行 jailbreak 脚本。