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.