How to write a good prompt
Contents
Resources
prompt
| Project | Description | Links |
|---|---|---|
| f/prompts.chat | A community-driven prompt collection, plus free-access books | Repository Community Book |
| dair-ai/Prompt-Engineering-Guide | A comprehensive prompt engineering guide covering techniques from beginner to advanced levels | Repository Website |
| x1xhlol/system-prompts-and-models | A collection of built-in system prompts from AI tools such as Cursor, Claude Code, and Gemini | Repository |
skills
| Project | Description | Links |
|---|---|---|
| anthropics/skills | Anthropic’s official Agent Skills library, including professional capabilities such as document processing and code generation | Repository |
| openai/skills | OpenAI’s skill catalog for Codex and GitHub Copilot, focused on standardized workflows for programming tasks | Repository |
| VoltAgent/awesome-agent-skills | A collection of 500+ skills from official and community sources, spanning web crawling, data analysis, cybersecurity, and more | Repository |
| K-Dense-AI/scientific-skills | Designed for researchers, with specialized skill packs for paper interpretation, data modeling, academic visualization, and more | Repository |
How to Write Better Prompts
Most of this section is based on the book The Interactive Book of Prompting: A Guide to Crafting Clear and Effective Prompts.
What Makes a Good Prompt
- Role
1 2 3"You are a [profession] with [X years] of experience in [specialty]" "Act as a [role] who is [characteristic]" "You are an expert [field] helping a [audience type]" - Context: provide background information
1I'm building a Node.js REST API using Express.js. The API handles user authentication with JWT tokens. When a user tries to access a protected route, they're getting a 403 error even with a valid token. Here's the relevant code: [code] - Task: state the objective clearly
1Edit this essay for grammar and clarity, maintaining the original tone but reducing wordiness by 20% - Constraints: length, content, style, scope, etc.
1 2 3 4"Keep your response under 200 words" "Do not include any code examples" "Use a formal, academic tone" "Only consider options available in Python 3.10+" - Format: specify output format such as list, Markdown, JSON, etc.
1 2"Return as JSON with keys: title, description, priority" "Format as a markdown table with columns: Feature, Pros, Cons" - Examples: provide reference examples for the model
1 2 3 4 5 6 7 8Classify these support tickets by urgency. Examples: "My account was hacked" → Critical "How do I change my password?" → Low "Payment failed but I was charged" → High Classify: "The app crashes when I open settings"
Practical Techniques
Role-Based Prompting
Omitted.
Chain of Thought
Chain-of-thought (CoT) prompting can significantly improve an AI model’s performance on complex reasoning tasks by explicitly providing reasoning steps.
Common usage patterns include:
- Simple trigger phrases
1 2"Let's think step by step." "Think through this carefully." - Provide explicit reasoning steps
1 2 3 4 5 6Before giving your final answer: 1. Identify what information is given 2. Determine what we need to find 3. Plan your approach 4. Execute each step, showing work 5. Verify your answer - Provide worked examples
1 2 3 4 5 6 7 8 9 10Example: Q: A baker has 24 cupcakes. She puts them equally into 4 boxes. Then she eats 2 cupcakes from one box. How many cupcakes total remain? A: Let's work through this: - Total cupcakes: 24 - Cupcakes per box: 24 ÷ 4 = 6 - After eating 2 from one box: 6 - 2 = 4 cupcakes in that box - Total remaining: (3 boxes × 6) + 4 = 18 + 4 = 22 cupcakes Now solve: xxx
Few-Shot Learning
| Method | Number of Examples |
|---|---|
| Zero-shot | 0 |
| One-shot | 1 |
| Few-shot | 2~5 |
| Many-shot | 5+ |
A typical template:
| |
For everyday code generation and optimization tasks, you can first provide existing code and ask the model to generate code with a similar style and the same interface.
Structured Output
Basic formatting techniques:
- Lists
1Format: Numbered list with a brief explanation for each. - Tables
1 2Format as a markdown table with columns: | Framework | Best For | Learning Curve | Performance | - Headings and sections
1 2 3 4 5 6Structure your response with these sections: ## Executive Summary ## Strengths ## Weaknesses ## Recommendations ## Risk Assessment - Use ALL CAPS for emphasis
1 2 3 4IMPORTANT: Keep the summary under 100 words. NEVER add information not present in the original. ALWAYS maintain the original tone and perspective. DO NOT include your own opinions or analysis.
You can also choose other machine-readable formats such as JSON, YAML, and XML.
JSON is suitable for programmatic parsing:
- API responses
- Strict type requirements
- JavaScript/Web integration
- Compact representation
YAML is suitable for human readability:
- Configuration files
- Cases where comments are needed
- DevOps/infrastructure scenarios
- Deeply nested structures
You can also freely define your own structure using delimiters like ===, ---, and [SECTION], and even assign different formats to different parts. For example:
| |
Iterative Improvement
Observe the model output, identify shortcomings in your prompt, revise it, and repeat.
You can also use a meta technique: ask the model itself to improve your prompt. For example:
| |
For convenience, you can also paste the prompt directly and write a meta-prompt based on the methods above, asking the model to optimize it.
Agents & Skills
An agent is an AI system that can plan, execute, and iterate autonomously. Its core components usually include planning, execution, observation, and adjustment. Accordingly, prompts can be categorized as:
- System prompts: the agent’s identity
- Planning prompts: how to think
- Tool prompts: how to act
- Recovery prompts: how to handle failures
A Skill is essentially a packaged set of prompts for solving a specific domain problem or task, forming a standardized, reusable, and autonomously callable capability package. It typically includes SKILL.md, reference docs, scripts and tools, configuration, etc.
In SKILL.md, you usually include the skill name, description, implementation details, reference materials, and so on.
Summary
Be clear and specific
Avoid vague expressions like
Make this betterorWrite about climate change. Describe your requirements or question as clearly as possible.Provide context
Give the model information that helps it solve the problem.
Guide, don’t just ask
Guide the model like a teacher. For complex tasks, for example, guide its reasoning process:
Think through this using the following steps: 1. xxx 2. xxx 3. xxxControl output structure
Specify the format you want the model to return.
Iterate and refine
The first prompt is often not the best one. Review the output and revise the prompt. You can also ask the model to refine your prompt.
Use reusable Skills
For high-quality prompts, you can formalize them in documentation so they can be reused directly each time.
Verify and validate
Do not blindly trust model outputs. You can verify them by:
- Asking for the model’s reasoning process
- Requiring the model to examine the issue from multiple perspectives
- Specifying what the model must check
In my view, writing a good prompt is somewhat like PUA1:
- Establish a clear role for the other party to adopt
- Express your requirements clearly
- Guide the other party toward the answer you want
- Explicitly state what is not allowed
In other words, when communicating with a model, you should keep the interaction under your direction.
Author Jinhao Xu
LastMod 2026-03-15