Initial commit
This commit is contained in:
215
skills/prompt-engineering/reference/INDEX.md
Normal file
215
skills/prompt-engineering/reference/INDEX.md
Normal file
@@ -0,0 +1,215 @@
|
||||
# Prompt Engineering Reference
|
||||
|
||||
Complete reference materials for the 26 prompt engineering principles and advanced techniques.
|
||||
|
||||
## Quick Navigation
|
||||
|
||||
| Resource | Purpose | Best For |
|
||||
|----------|---------|----------|
|
||||
| [Prompt Principles Guide](prompt-principles-guide.md) | All 26 principles with examples | Complete reference |
|
||||
| [Principle Combinations](principle-combinations.md) | How to combine principles effectively | Advanced users |
|
||||
| [Anti-Patterns](prompt-anti-patterns.md) | Common mistakes to avoid | Troubleshooting |
|
||||
|
||||
## The 26 Prompt Engineering Principles
|
||||
|
||||
### Content & Clarity (Principles 1-2, 9-10, 21, 25)
|
||||
|
||||
**What to say and how clearly**
|
||||
|
||||
- **Principle 1**: No need to be polite - Be concise and direct
|
||||
- **Principle 2**: Integrate audience specification
|
||||
- **Principle 9**: Be clear about requirements (directness)
|
||||
- **Principle 10**: Use affirmative directives (Do X, not Don't do X)
|
||||
- **Principle 21**: Add detailed and descriptive information
|
||||
- **Principle 25**: Clearly state requirements
|
||||
|
||||
### Structure & Organization (Principles 3, 8, 17)
|
||||
|
||||
**How to organize information**
|
||||
|
||||
- **Principle 3**: Break down complex tasks into simpler steps
|
||||
- **Principle 8**: Use delimiters to clearly indicate distinct sections
|
||||
- **Principle 17**: Specify desired format for structured input/output
|
||||
|
||||
### Reasoning & Thinking (Principles 12, 19, 20)
|
||||
|
||||
**How to guide model's thought process**
|
||||
|
||||
- **Principle 12**: Use "do step-by-step" or "think step-by-step"
|
||||
- **Principle 19**: Use "chain-of-thought" prompting
|
||||
- **Principle 20**: Provide examples (few-shot learning)
|
||||
|
||||
### Style & Tone (Principles 5, 11, 22, 24, 26)
|
||||
|
||||
**How to express requests**
|
||||
|
||||
- **Principle 5**: Adjust language complexity to audience
|
||||
- **Principle 11**: Employ role-playing or persona
|
||||
- **Principle 22**: Use natural, conversational language
|
||||
- **Principle 24**: Specify preferred answer format (bullets, paragraphs, etc.)
|
||||
- **Principle 26**: Use leading words (e.g., "Write a detailed...")
|
||||
|
||||
### Advanced Techniques (Principles 4, 6-7, 13-16, 18, 23)
|
||||
|
||||
**Specialized approaches**
|
||||
|
||||
- **Principle 4**: Ask model to explain itself (for complex topics)
|
||||
- **Principle 6**: Use incentives or penalties (when appropriate)
|
||||
- **Principle 7**: Implement example-driven prompting (few-shot)
|
||||
- **Principle 13**: Elicit unbiased answers for sensitive topics
|
||||
- **Principle 14**: Ask clarifying questions to understand user needs
|
||||
- **Principle 15**: Test understanding with quizzes or problems
|
||||
- **Principle 16**: Use affirmative language
|
||||
- **Principle 18**: Clearly define learning objectives
|
||||
- **Principle 23**: Use multi-turn conversations for complex tasks
|
||||
|
||||
## Quick Selection Guide
|
||||
|
||||
### By Task Type
|
||||
|
||||
**Technical/Code (Use Principles: 3, 7, 8, 12, 17, 19, 21)**
|
||||
```
|
||||
✓ Break down (3)
|
||||
✓ Examples (7)
|
||||
✓ Delimiters (8)
|
||||
✓ Step-by-step (12)
|
||||
✓ Format (17)
|
||||
✓ Chain-of-thought (19)
|
||||
✓ Detail (21)
|
||||
```
|
||||
|
||||
**Creative/Writing (Use Principles: 2, 5, 11, 22, 24, 26)**
|
||||
```
|
||||
✓ Audience (2)
|
||||
✓ Complexity (5)
|
||||
✓ Role-play (11)
|
||||
✓ Natural language (22)
|
||||
✓ Format preference (24)
|
||||
✓ Leading words (26)
|
||||
```
|
||||
|
||||
**Learning/Education (Use Principles: 5, 14, 15, 18, 20)**
|
||||
```
|
||||
✓ Complexity level (5)
|
||||
✓ Elicit questions (14)
|
||||
✓ Test understanding (15)
|
||||
✓ Learning objectives (18)
|
||||
✓ Examples (20)
|
||||
```
|
||||
|
||||
**Research/Analysis (Use Principles: 3, 8, 12, 13, 19, 21, 25)**
|
||||
```
|
||||
✓ Break down (3)
|
||||
✓ Structure (8)
|
||||
✓ Step-by-step (12)
|
||||
✓ Unbiased (13)
|
||||
✓ Reasoning (19)
|
||||
✓ Detail (21)
|
||||
✓ Requirements (25)
|
||||
```
|
||||
|
||||
## Principle Effectiveness Matrix
|
||||
|
||||
| Principle | Frequency of Use | Impact Level | Complexity | Combine With |
|
||||
|-----------|------------------|--------------|------------|--------------|
|
||||
| 1 (Concise) | High | Medium | Low | All |
|
||||
| 2 (Audience) | High | High | Low | 5, 18 |
|
||||
| 3 (Breakdown) | Very High | Very High | Low | 8, 12 |
|
||||
| 7 (Few-shot) | High | Very High | Medium | 17, 20 |
|
||||
| 8 (Delimiters) | Very High | High | Low | 3, 17 |
|
||||
| 12 (Step-by-step) | High | High | Low | 3, 19 |
|
||||
| 19 (Chain-of-thought) | Medium | Very High | Medium | 12, 21 |
|
||||
| 21 (Detail) | Very High | High | Low | All |
|
||||
|
||||
**Impact Levels:**
|
||||
- **Very High**: Transforms weak prompts to strong (3, 7, 8, 19)
|
||||
- **High**: Significant improvement (2, 12, 21, 25)
|
||||
- **Medium**: Situational benefit (1, 5, 11, 17, 24)
|
||||
|
||||
## Common Combinations
|
||||
|
||||
**The "Technical Stack"** (for code/technical tasks):
|
||||
```
|
||||
3 (Breakdown) + 8 (Delimiters) + 17 (Format) + 21 (Detail)
|
||||
```
|
||||
|
||||
**The "Learning Stack"** (for educational content):
|
||||
```
|
||||
2 (Audience) + 5 (Complexity) + 18 (Objectives) + 20 (Examples)
|
||||
```
|
||||
|
||||
**The "Reasoning Stack"** (for analysis/problem-solving):
|
||||
```
|
||||
3 (Breakdown) + 12 (Step-by-step) + 19 (Chain-of-thought) + 21 (Detail)
|
||||
```
|
||||
|
||||
**The "Creative Stack"** (for writing/ideation):
|
||||
```
|
||||
2 (Audience) + 11 (Role-play) + 22 (Natural) + 26 (Leading words)
|
||||
```
|
||||
|
||||
## Anti-Patterns to Avoid
|
||||
|
||||
**Don't Do:**
|
||||
- ❌ Vague requests without context
|
||||
- ❌ Multiple unrelated questions in one prompt
|
||||
- ❌ Negative instructions ("don't do X" instead of "do Y")
|
||||
- ❌ Missing output format specification
|
||||
- ❌ No audience or complexity level
|
||||
|
||||
**Do Instead:**
|
||||
- ✅ Specific requests with full context (Principle 21)
|
||||
- ✅ One focused topic per prompt (Principle 3)
|
||||
- ✅ Affirmative directives (Principle 10, 16)
|
||||
- ✅ Explicit format requirements (Principle 17)
|
||||
- ✅ Target audience specified (Principle 2)
|
||||
|
||||
## Progressive Mastery Path
|
||||
|
||||
**Level 1: Beginner (Start Here)**
|
||||
- Master: 1, 2, 3, 8, 21
|
||||
- Focus: Clarity, structure, specificity
|
||||
- Time: 1-2 weeks practice
|
||||
|
||||
**Level 2: Intermediate**
|
||||
- Add: 7, 12, 17, 25
|
||||
- Focus: Examples, steps, format, requirements
|
||||
- Time: 2-4 weeks practice
|
||||
|
||||
**Level 3: Advanced**
|
||||
- Add: 5, 11, 19, 20, 24
|
||||
- Focus: Complexity control, reasoning, style
|
||||
- Time: 4-8 weeks practice
|
||||
|
||||
**Level 4: Expert**
|
||||
- Master all 26 principles
|
||||
- Create custom combinations
|
||||
- Teach others
|
||||
|
||||
## Resource Roadmap
|
||||
|
||||
1. **Start:** Read [Prompt Principles Guide](prompt-principles-guide.md)
|
||||
2. **Practice:** Try [Common Fixes](../examples/common-prompt-fixes.md)
|
||||
3. **Deepen:** Study [Principle Combinations](principle-combinations.md)
|
||||
4. **Avoid:** Learn [Anti-Patterns](prompt-anti-patterns.md)
|
||||
5. **Apply:** Use [Templates](../templates/) for common tasks
|
||||
|
||||
## Success Metrics
|
||||
|
||||
Track your improvement:
|
||||
- **Week 1:** Can apply 5 basic principles
|
||||
- **Month 1:** Consistently use 10-12 principles
|
||||
- **Month 3:** Master all 26 principles
|
||||
- **Month 6:** Create optimal combinations instinctively
|
||||
|
||||
**Measurement:**
|
||||
- Compare before/after prompt quality scores
|
||||
- Track reduction in follow-up clarifications needed
|
||||
- Measure improvement in first-response quality
|
||||
- Monitor task completion rates
|
||||
|
||||
---
|
||||
|
||||
**Principles Covered**: All 26
|
||||
**Difficulty Levels**: Beginner → Expert
|
||||
**Practice Time**: 1-6 months to mastery
|
||||
492
skills/prompt-engineering/reference/prompt-anti-patterns.md
Normal file
492
skills/prompt-engineering/reference/prompt-anti-patterns.md
Normal file
@@ -0,0 +1,492 @@
|
||||
# Prompt Anti-Patterns
|
||||
|
||||
Common mistakes in prompt engineering and how to fix them.
|
||||
|
||||
---
|
||||
|
||||
## Anti-Pattern 1: The Vague Request
|
||||
|
||||
### Problem
|
||||
```
|
||||
"Help me with my code."
|
||||
"Tell me about AI."
|
||||
"Make this better."
|
||||
```
|
||||
|
||||
**Why It Fails:**
|
||||
- No specific task
|
||||
- No context provided
|
||||
- No success criteria
|
||||
- Forces model to guess intent
|
||||
|
||||
**Fix:** Apply Principles 9, 21, 25
|
||||
|
||||
```
|
||||
###Task###
|
||||
Debug this Python function that should validate email addresses but accepts invalid formats.
|
||||
|
||||
###Current Code###
|
||||
[paste code]
|
||||
|
||||
###Issue###
|
||||
Accepts "user@" as valid (missing domain)
|
||||
|
||||
###Expected###
|
||||
Should reject emails without valid domain part
|
||||
|
||||
###Requirements###
|
||||
- Use regex pattern
|
||||
- Return boolean
|
||||
- Handle edge cases (empty string, None)
|
||||
```
|
||||
|
||||
**Impact:** 85% → 95% first-response success
|
||||
|
||||
---
|
||||
|
||||
## Anti-Pattern 2: The Wall of Text
|
||||
|
||||
### Problem
|
||||
```
|
||||
I'm building an app and I need help with the database design and also the API endpoints and I'm not sure if I should use REST or GraphQL and also I need authentication but I don't know if JWT is the right choice and also...
|
||||
```
|
||||
|
||||
**Why It Fails:**
|
||||
- Multiple unrelated concerns
|
||||
- No structure
|
||||
- Difficult to parse
|
||||
- Model can't prioritize
|
||||
|
||||
**Fix:** Apply Principles 3, 8
|
||||
|
||||
```
|
||||
###Project Context###
|
||||
Building a multi-tenant SaaS task management app
|
||||
|
||||
###Current Questions###
|
||||
|
||||
**1. Database Design**
|
||||
- Tables: organizations, users, projects, tasks
|
||||
- Need: multi-tenant isolation strategy
|
||||
|
||||
**2. API Architecture**
|
||||
- Options: REST vs GraphQL
|
||||
- Requirements: Mobile + web clients, real-time updates
|
||||
|
||||
**3. Authentication**
|
||||
- Considering: JWT with refresh tokens
|
||||
- Concerns: Security, session management
|
||||
|
||||
Let's tackle these one at a time, starting with #1: Database Design
|
||||
```
|
||||
|
||||
**Impact:** 60% → 90% complete answers
|
||||
|
||||
---
|
||||
|
||||
## Anti-Pattern 3: No Examples Provided
|
||||
|
||||
### Problem
|
||||
```
|
||||
"Extract important information from this text."
|
||||
```
|
||||
|
||||
**Why It Fails:**
|
||||
- "Important" is subjective
|
||||
- No format specified
|
||||
- No pattern to follow
|
||||
|
||||
**Fix:** Apply Principle 7, 20
|
||||
|
||||
```
|
||||
Extract person names and dates from text.
|
||||
|
||||
###Examples###
|
||||
|
||||
Input: "John met Sarah on July 15, 2024 at the cafe."
|
||||
Output: {
|
||||
"names": ["John", "Sarah"],
|
||||
"dates": ["2024-07-15"]
|
||||
}
|
||||
|
||||
Input: "The meeting is scheduled for Jan 1st with Dr. Smith."
|
||||
Output: {
|
||||
"names": ["Dr. Smith"],
|
||||
"dates": ["2024-01-01"]
|
||||
}
|
||||
|
||||
###Your Task###
|
||||
Input: [your text]
|
||||
Output: ?
|
||||
```
|
||||
|
||||
**Impact:** 45% → 92% accuracy
|
||||
|
||||
---
|
||||
|
||||
## Anti-Pattern 4: Negative Instructions
|
||||
|
||||
### Problem
|
||||
```
|
||||
"Don't use technical jargon. Don't make it too long. Don't skip error handling."
|
||||
```
|
||||
|
||||
**Why It Fails:**
|
||||
- Negative framing harder to follow
|
||||
- Doesn't say what TO do
|
||||
- Can confuse intent
|
||||
|
||||
**Fix:** Apply Principles 10, 16
|
||||
|
||||
```
|
||||
✓ Use plain English (explain technical terms when needed)
|
||||
✓ Keep under 500 words
|
||||
✓ Include error handling for all functions
|
||||
```
|
||||
|
||||
**Impact:** 70% → 95% compliance
|
||||
|
||||
---
|
||||
|
||||
## Anti-Pattern 5: Missing Output Format
|
||||
|
||||
### Problem
|
||||
```
|
||||
"Compare React and Vue."
|
||||
```
|
||||
|
||||
**Why It Fails:**
|
||||
- No format specified (essay? table? bullets?)
|
||||
- No structure guidance
|
||||
- Length unclear
|
||||
- Detail level undefined
|
||||
|
||||
**Fix:** Apply Principles 17, 24
|
||||
|
||||
```
|
||||
Compare React and Vue in a table:
|
||||
|
||||
| Aspect | React | Vue | Better For |
|
||||
|--------|-------|-----|------------|
|
||||
| Learning Curve | | | |
|
||||
| Performance | | | |
|
||||
| Ecosystem | | | |
|
||||
| Community | | | |
|
||||
| Best Use Cases | | | |
|
||||
|
||||
For each cell: 1-2 sentences max
|
||||
```
|
||||
|
||||
**Impact:** 50% → 95% usable first response
|
||||
|
||||
---
|
||||
|
||||
## Anti-Pattern 6: No Audience Specification
|
||||
|
||||
### Problem
|
||||
```
|
||||
"Explain machine learning."
|
||||
```
|
||||
|
||||
**Why It Fails:**
|
||||
- Could be for 5-year-old or PhD
|
||||
- Complexity level unknown
|
||||
- Assumed knowledge unclear
|
||||
|
||||
**Fix:** Apply Principles 2, 5
|
||||
|
||||
```
|
||||
Explain machine learning to a junior web developer who understands JavaScript but has no math/stats background. Use web development analogies where possible.
|
||||
```
|
||||
|
||||
**Impact:** Explanation quality 4/10 → 9/10
|
||||
|
||||
---
|
||||
|
||||
## Anti-Pattern 7: Overwhelming Single Request
|
||||
|
||||
### Problem
|
||||
```
|
||||
"Build a complete e-commerce website with user authentication, product catalog, shopping cart, payment processing, admin panel, and deploy it."
|
||||
```
|
||||
|
||||
**Why It Fails:**
|
||||
- Too broad for single response
|
||||
- Can't cover everything well
|
||||
- No prioritization
|
||||
- Overwhelming complexity
|
||||
|
||||
**Fix:** Apply Principle 3
|
||||
|
||||
```
|
||||
Build an e-commerce website in phases:
|
||||
|
||||
**Phase 1: Foundation** (current focus)
|
||||
- Basic product listing
|
||||
- Product detail pages
|
||||
- Simple navigation
|
||||
|
||||
**Phase 2:** Shopping cart
|
||||
**Phase 3:** User authentication
|
||||
**Phase 4:** Checkout process
|
||||
**Phase 5:** Admin panel
|
||||
**Phase 6:** Deployment
|
||||
|
||||
Let's start with Phase 1. What should the data model look like?
|
||||
```
|
||||
|
||||
**Impact:** Completion rate 20% → 85%
|
||||
|
||||
---
|
||||
|
||||
## Anti-Pattern 8: Assuming Context
|
||||
|
||||
### Problem
|
||||
```
|
||||
"Fix the bug in the login function."
|
||||
```
|
||||
|
||||
**Why It Fails:**
|
||||
- No code provided
|
||||
- No error description
|
||||
- No environment details
|
||||
- No expected behavior
|
||||
|
||||
**Fix:** Apply Principle 21
|
||||
|
||||
```
|
||||
###Bug in Login Function###
|
||||
|
||||
**Environment:**
|
||||
- React 18 + TypeScript
|
||||
- Backend: FastAPI
|
||||
- Auth: JWT tokens
|
||||
|
||||
**Code:**
|
||||
[paste login function]
|
||||
|
||||
**Error:**
|
||||
TypeError: Cannot read property 'token' of undefined
|
||||
|
||||
**Expected:**
|
||||
After login, should redirect to dashboard with token stored
|
||||
|
||||
**What I've Tried:**
|
||||
- Verified API returns 200
|
||||
- Checked token exists in response
|
||||
- Console.log shows response structure
|
||||
```
|
||||
|
||||
**Impact:** Resolution time: 3 iterations → 1 iteration
|
||||
|
||||
---
|
||||
|
||||
## Anti-Pattern 9: No Success Criteria
|
||||
|
||||
### Problem
|
||||
```
|
||||
"Review this code."
|
||||
```
|
||||
|
||||
**Why It Fails:**
|
||||
- What aspects to review?
|
||||
- What level of detail?
|
||||
- What standards to apply?
|
||||
- What constitutes "good"?
|
||||
|
||||
**Fix:** Apply Principle 25
|
||||
|
||||
```
|
||||
Code review this React component against these criteria:
|
||||
|
||||
###Review Checklist###
|
||||
☐ Performance: Unnecessary re-renders, expensive operations
|
||||
☐ Security: XSS vulnerabilities, input validation
|
||||
☐ Accessibility: ARIA labels, keyboard navigation
|
||||
☐ TypeScript: Proper typing, no `any`
|
||||
☐ Testing: Missing test scenarios
|
||||
☐ Best Practices: React hooks rules, component structure
|
||||
|
||||
###Output Format###
|
||||
For each issue:
|
||||
- Severity: Critical | High | Medium | Low
|
||||
- Line number
|
||||
- Problem description
|
||||
- Suggested fix
|
||||
|
||||
###Scoring###
|
||||
Provide overall score (1-10) with justification
|
||||
```
|
||||
|
||||
**Impact:** Review quality 5/10 → 9/10
|
||||
|
||||
---
|
||||
|
||||
## Anti-Pattern 10: Ignoring Iterative Refinement
|
||||
|
||||
### Problem
|
||||
Expecting perfect response on first try, giving up if not perfect.
|
||||
|
||||
**Why It Fails:**
|
||||
- Complex tasks need refinement
|
||||
- Initial response is starting point
|
||||
- Model can improve with feedback
|
||||
|
||||
**Fix:** Apply Principle 23
|
||||
|
||||
```
|
||||
Turn 1: "Create basic API endpoint structure"
|
||||
→ Review response
|
||||
|
||||
Turn 2: "Add error handling to these endpoints"
|
||||
→ Review response
|
||||
|
||||
Turn 3: "Now add input validation with Pydantic"
|
||||
→ Refine further
|
||||
|
||||
Turn 4: "Add rate limiting middleware"
|
||||
→ Complete solution
|
||||
```
|
||||
|
||||
**Impact:** Quality of final output 6/10 → 9/10
|
||||
|
||||
---
|
||||
|
||||
## Anti-Pattern 11: Technical Jargon Without Context
|
||||
|
||||
### Problem
|
||||
```
|
||||
"Implement OAuth2 PKCE flow with RBAC and MFA."
|
||||
```
|
||||
|
||||
**Why It Fails** (if audience doesn't know jargon):
|
||||
- Assumes expert knowledge
|
||||
- No definitions
|
||||
- No context
|
||||
|
||||
**Fix:** Apply Principles 2, 5
|
||||
|
||||
```
|
||||
Implement user authentication for a web app:
|
||||
|
||||
**Requirements:**
|
||||
- OAuth2 with Proof Key for Code Exchange (prevents token interception)
|
||||
- Role-Based Access Control (admins vs regular users)
|
||||
- Multi-Factor Authentication (email code for login)
|
||||
|
||||
**Audience:** Mid-level developer, familiar with JWTs but new to OAuth2
|
||||
|
||||
**Deliverables:**
|
||||
1. Explanation of each security feature
|
||||
2. Implementation code
|
||||
3. Flow diagrams
|
||||
```
|
||||
|
||||
**Impact:** Understanding 30% → 90%
|
||||
|
||||
---
|
||||
|
||||
## Anti-Pattern 12: One-Word or Ultra-Short Prompts
|
||||
|
||||
### Problem
|
||||
```
|
||||
"React?"
|
||||
"SQL"
|
||||
"Python decorators"
|
||||
```
|
||||
|
||||
**Why It Fails:**
|
||||
- Completely ambiguous
|
||||
- No specific question
|
||||
- No context
|
||||
- Forces guessing
|
||||
|
||||
**Fix:** Apply Principles 1, 9, 21
|
||||
|
||||
```
|
||||
Explain Python decorators with:
|
||||
1. What problem they solve
|
||||
2. Basic syntax
|
||||
3. Three common use cases
|
||||
4. One complete working example
|
||||
|
||||
Target audience: Python developer with 6 months experience
|
||||
```
|
||||
|
||||
**Impact:** Relevance 20% → 95%
|
||||
|
||||
---
|
||||
|
||||
## Quick Anti-Pattern Checklist
|
||||
|
||||
Before submitting, check for these red flags:
|
||||
|
||||
**❌ Anti-Patterns Present:**
|
||||
- [ ] Request is < 10 words
|
||||
- [ ] Contains "Don't" or "Avoid" instructions
|
||||
- [ ] No specific details or examples
|
||||
- [ ] Multiple unrelated topics in one prompt
|
||||
- [ ] No audience or complexity level
|
||||
- [ ] No desired format specified
|
||||
- [ ] Assumes model knows your context
|
||||
- [ ] No success criteria or requirements
|
||||
- [ ] Technical jargon without explanation
|
||||
- [ ] Too broad for single response
|
||||
|
||||
**✅ Good Prompt Has:**
|
||||
- [x] Clear, specific task
|
||||
- [x] Relevant context and details
|
||||
- [x] Target audience specified
|
||||
- [x] Desired output format
|
||||
- [x] Examples (if applicable)
|
||||
- [x] Success criteria
|
||||
- [x] Structured with delimiters
|
||||
- [x] Affirmative language
|
||||
- [x] Appropriate scope
|
||||
- [x] Requirements stated explicitly
|
||||
|
||||
---
|
||||
|
||||
## Pattern: Weak → Strong Transformation Template
|
||||
|
||||
Use this template to fix any weak prompt:
|
||||
|
||||
```
|
||||
###Task###
|
||||
[One clear sentence describing what you need]
|
||||
|
||||
###Context###
|
||||
[Relevant background information]
|
||||
|
||||
###Requirements###
|
||||
- [Specific requirement 1]
|
||||
- [Specific requirement 2]
|
||||
|
||||
###Format###
|
||||
[How you want the response structured]
|
||||
|
||||
###Examples### (if applicable)
|
||||
[Show desired pattern]
|
||||
|
||||
###Success Criteria###
|
||||
[How to know if response meets needs]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## The "5 Why's" Test
|
||||
|
||||
If your prompt is weak, ask:
|
||||
|
||||
1. **Why** do I need this? → Add context
|
||||
2. **Why** this approach? → Specify requirements
|
||||
3. **Why** this format? → Define output structure
|
||||
4. **Why** this audience? → State target user
|
||||
5. **Why** now? → Add constraints/urgency
|
||||
|
||||
---
|
||||
|
||||
**Total Anti-Patterns**: 12 common mistakes
|
||||
**Average Fix Impact**: 40% → 90% success rate
|
||||
**Time to Fix**: 30-60 seconds per prompt
|
||||
**Principles Most Violated**: 3, 8, 9, 21, 25
|
||||
494
skills/prompt-engineering/reference/prompt-principles-guide.md
Normal file
494
skills/prompt-engineering/reference/prompt-principles-guide.md
Normal file
@@ -0,0 +1,494 @@
|
||||
# Complete Prompt Principles Guide
|
||||
|
||||
Comprehensive reference for all 26 prompt engineering principles with examples and use cases.
|
||||
|
||||
---
|
||||
|
||||
## Category 1: Content & Clarity
|
||||
|
||||
### Principle 1: Be Concise and Direct
|
||||
|
||||
**Rule:** No need to be overly polite with LLMs. Get straight to the point.
|
||||
|
||||
**Weak:** "Hello! I hope you're doing well. I was wondering if perhaps you might be able to help me with a small favor. If it's not too much trouble, could you possibly explain...?"
|
||||
|
||||
**Strong:** "Explain recursion in Python with a simple example."
|
||||
|
||||
**When to Use:** Always. Saves tokens and improves response focus.
|
||||
|
||||
---
|
||||
|
||||
### Principle 2: Integrate Audience Specification
|
||||
|
||||
**Rule:** Explicitly state who the response is for.
|
||||
|
||||
**Weak:** "Explain quantum computing."
|
||||
|
||||
**Strong:** "Explain quantum computing to a CS undergraduate with no physics background."
|
||||
|
||||
**Impact:** Adjusts complexity, terminology, and examples appropriately.
|
||||
|
||||
**Audience Templates:**
|
||||
- "for a 10-year-old"
|
||||
- "for a senior developer with 10 years experience"
|
||||
- "for a non-technical CEO"
|
||||
- "for someone learning [X]"
|
||||
|
||||
---
|
||||
|
||||
### Principle 9: Be Direct About Requirements
|
||||
|
||||
**Rule:** State exactly what you need in clear, straightforward terms.
|
||||
|
||||
**Weak:** "Can you help with my code?"
|
||||
|
||||
**Strong:** "Debug this Python function - it should return even numbers but returns all numbers."
|
||||
|
||||
**Checklist:**
|
||||
- [ ] What you need (debug, explain, create, refactor)
|
||||
- [ ] The specific problem or task
|
||||
- [ ] Current vs expected behavior
|
||||
- [ ] Relevant context
|
||||
|
||||
---
|
||||
|
||||
### Principle 10: Use Affirmative Directives
|
||||
|
||||
**Rule:** Tell the model what TO do, not what NOT to do.
|
||||
|
||||
**Weak:** "Don't use complicated words. Don't make it too long. Don't skip the basics."
|
||||
|
||||
**Strong:** "Use simple language. Keep under 500 words. Include fundamental concepts."
|
||||
|
||||
**Why:** Affirmative instructions are clearer and easier to follow.
|
||||
|
||||
---
|
||||
|
||||
### Principle 21: Add Detail and Descriptive Information
|
||||
|
||||
**Rule:** Provide specific, detailed context and requirements.
|
||||
|
||||
**Weak:** "Write a function to sort data."
|
||||
|
||||
**Strong:**
|
||||
```
|
||||
Write a TypeScript function to sort an array of user objects by:
|
||||
1. Primary: registration_date (newest first)
|
||||
2. Secondary: username (alphabetical)
|
||||
Handle null dates by placing those users last.
|
||||
```
|
||||
|
||||
**Detail Checklist:**
|
||||
- [ ] Specific inputs/outputs
|
||||
- [ ] Edge cases to handle
|
||||
- [ ] Performance requirements
|
||||
- [ ] Format/style preferences
|
||||
- [ ] Version/technology constraints
|
||||
|
||||
---
|
||||
|
||||
### Principle 25: Clearly State Requirements
|
||||
|
||||
**Rule:** Explicitly list all requirements and success criteria.
|
||||
|
||||
**Example:**
|
||||
```
|
||||
###Requirements###
|
||||
- Language: TypeScript
|
||||
- Framework: React 18
|
||||
- Must include TypeScript types
|
||||
- Must handle loading/error states
|
||||
- Must be accessible (ARIA labels)
|
||||
- Code must pass ESLint
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Category 2: Structure & Organization
|
||||
|
||||
### Principle 3: Break Down Complex Tasks
|
||||
|
||||
**Rule:** Decompose large tasks into smaller, sequential steps.
|
||||
|
||||
**Weak:** "Build a REST API."
|
||||
|
||||
**Strong:**
|
||||
```
|
||||
Build a REST API in these steps:
|
||||
1. Design data model (users, posts, comments)
|
||||
2. Create database schema
|
||||
3. Implement CRUD endpoints
|
||||
4. Add authentication
|
||||
5. Write tests
|
||||
6. Deploy
|
||||
|
||||
Start with step 1: data model design.
|
||||
```
|
||||
|
||||
**Benefits:**
|
||||
- Prevents overwhelming responses
|
||||
- Enables iterative refinement
|
||||
- Clearer progress tracking
|
||||
- Better error isolation
|
||||
|
||||
---
|
||||
|
||||
### Principle 8: Use Delimiters for Distinct Sections
|
||||
|
||||
**Rule:** Clearly separate different parts of your prompt with visual markers.
|
||||
|
||||
**Delimiters:**
|
||||
- `###Headers###`
|
||||
- Triple backticks for code
|
||||
- Horizontal lines (`---`)
|
||||
- Bullet lists for items
|
||||
|
||||
**Example:**
|
||||
```
|
||||
###Task###
|
||||
Create a password validator
|
||||
|
||||
###Requirements###
|
||||
- Min 8 characters
|
||||
- Must include: uppercase, lowercase, number, special char
|
||||
|
||||
###Function Signature###
|
||||
function validatePassword(password: string): boolean
|
||||
|
||||
###Test Cases###
|
||||
✅ "Pass123!" → true
|
||||
❌ "short" → false
|
||||
```
|
||||
|
||||
**Impact:** 40% improvement in following complex instructions.
|
||||
|
||||
---
|
||||
|
||||
### Principle 17: Specify Format for Input/Output
|
||||
|
||||
**Rule:** Define exactly how you want the response structured.
|
||||
|
||||
**Weak:** "List the pros and cons."
|
||||
|
||||
**Strong:**
|
||||
```
|
||||
Compare SQL vs NoSQL in this format:
|
||||
|
||||
| Aspect | SQL | NoSQL | Winner |
|
||||
|--------|-----|-------|--------|
|
||||
| [aspect] | [desc] | [desc] | [which] |
|
||||
|
||||
Include 5 aspects: Schema, Scaling, Queries, Consistency, Learning Curve
|
||||
```
|
||||
|
||||
**Format Options:**
|
||||
- Tables (markdown)
|
||||
- JSON objects
|
||||
- Numbered lists
|
||||
- Code blocks
|
||||
- Specific file formats
|
||||
|
||||
---
|
||||
|
||||
## Category 3: Reasoning & Thinking
|
||||
|
||||
### Principle 12: Use "Step-by-Step" Instructions
|
||||
|
||||
**Rule:** Explicitly ask for step-by-step reasoning.
|
||||
|
||||
**Before:** "Debug this code."
|
||||
|
||||
**After:** "Debug this code step-by-step:
|
||||
1. Identify the error
|
||||
2. Explain why it occurs
|
||||
3. Provide the fix
|
||||
4. Explain why the fix works"
|
||||
|
||||
**Phrases:**
|
||||
- "Let's think step-by-step"
|
||||
- "Approach this systematically"
|
||||
- "Work through this one step at a time"
|
||||
|
||||
---
|
||||
|
||||
### Principle 19: Use Chain-of-Thought Prompting
|
||||
|
||||
**Rule:** Ask the model to show its reasoning process.
|
||||
|
||||
**Example:**
|
||||
```
|
||||
Solve this problem and show your reasoning:
|
||||
|
||||
Problem: [complex problem]
|
||||
|
||||
Think through:
|
||||
- What information do we have?
|
||||
- What's the core challenge?
|
||||
- What approach makes sense?
|
||||
- Execute the approach
|
||||
- Verify the solution
|
||||
```
|
||||
|
||||
**When to Use:**
|
||||
- Mathematical problems
|
||||
- Logical reasoning
|
||||
- Complex debugging
|
||||
- Optimization decisions
|
||||
|
||||
**Impact:** 350% improvement in complex problem-solving accuracy.
|
||||
|
||||
---
|
||||
|
||||
### Principle 20: Provide Examples (Few-Shot Learning)
|
||||
|
||||
**Rule:** Show examples of desired input/output.
|
||||
|
||||
**Pattern:**
|
||||
```
|
||||
Extract key phrases from text.
|
||||
|
||||
###Examples###
|
||||
|
||||
Input: "The quick brown fox jumps over the lazy dog."
|
||||
Output: ["quick brown fox", "lazy dog"]
|
||||
|
||||
Input: "Python is a programming language."
|
||||
Output: ["Python", "programming language"]
|
||||
|
||||
###Your Task###
|
||||
Input: [your actual text]
|
||||
Output: ?
|
||||
```
|
||||
|
||||
**Best Practices:**
|
||||
- 2-3 examples optimal
|
||||
- Show edge cases
|
||||
- Diverse examples
|
||||
- Consistent format
|
||||
|
||||
---
|
||||
|
||||
## Category 4: Style & Tone
|
||||
|
||||
### Principle 5: Adjust Language Complexity
|
||||
|
||||
**Rule:** Match vocabulary and concept complexity to audience.
|
||||
|
||||
**For Beginners:**
|
||||
"useState is like a memory box for your component. When you put something in the box (set state), React remembers it."
|
||||
|
||||
**For Experts:**
|
||||
"useState returns a stateful value and updater function via array destructuring, triggering re-renders on state mutations."
|
||||
|
||||
**Complexity Markers:**
|
||||
- Beginners: Analogies, simple vocabulary, step-by-step
|
||||
- Intermediate: Some jargon, assumes basic knowledge
|
||||
- Expert: Technical terms, assumes context
|
||||
|
||||
---
|
||||
|
||||
### Principle 11: Employ Role-Playing
|
||||
|
||||
**Rule:** Assign the model a specific role or persona.
|
||||
|
||||
**Examples:**
|
||||
- "You are a senior DevOps engineer reviewing infrastructure code..."
|
||||
- "As a technical writer, create documentation for..."
|
||||
- "You're a code reviewer specializing in security. Analyze..."
|
||||
|
||||
**When Effective:**
|
||||
- Specific domain expertise needed
|
||||
- Particular perspective valuable
|
||||
- Style/tone requirements
|
||||
- Teaching scenarios
|
||||
|
||||
---
|
||||
|
||||
### Principle 22: Use Natural, Conversational Language
|
||||
|
||||
**Rule:** Write prompts as you'd explain to a colleague.
|
||||
|
||||
**Stiff:** "Produce comprehensive documentation delineating the utilization patterns of the aforementioned software module."
|
||||
|
||||
**Natural:** "Explain how to use this function in everyday development work."
|
||||
|
||||
---
|
||||
|
||||
### Principle 24: Specify Answer Format Preference
|
||||
|
||||
**Rule:** State if you want bullets, paragraphs, tables, etc.
|
||||
|
||||
**Examples:**
|
||||
- "Answer in bullet points"
|
||||
- "Provide a numbered step-by-step guide"
|
||||
- "Format as a comparison table"
|
||||
- "Write as a narrative explanation"
|
||||
|
||||
---
|
||||
|
||||
### Principle 26: Use Leading Words
|
||||
|
||||
**Rule:** Begin prompts with directing words that shape the response.
|
||||
|
||||
**Leading Words:**
|
||||
- "Write a detailed..." → Comprehensive response
|
||||
- "Briefly summarize..." → Concise response
|
||||
- "Explain step-by-step..." → Structured breakdown
|
||||
- "Compare and contrast..." → Analytical comparison
|
||||
|
||||
---
|
||||
|
||||
## Category 5: Advanced Techniques
|
||||
|
||||
### Principle 4: Ask Model to Explain
|
||||
|
||||
**Rule:** For complex topics, ask the model to explain its answer.
|
||||
|
||||
**Example:**
|
||||
"Recommend a database for this use case and explain your reasoning:
|
||||
- Why you chose this option
|
||||
- What tradeoffs you considered
|
||||
- What alternatives you rejected and why"
|
||||
|
||||
---
|
||||
|
||||
### Principle 7: Implement Example-Driven Prompting
|
||||
|
||||
**Rule:** Demonstrate the pattern you want followed.
|
||||
|
||||
**Example:**
|
||||
```
|
||||
Convert code comments to documentation:
|
||||
|
||||
###Example###
|
||||
Code:
|
||||
// Validates email format
|
||||
function validateEmail(email) {...}
|
||||
|
||||
Docs:
|
||||
validateEmail(email: string): boolean
|
||||
Validates email format using RFC 5322 standard.
|
||||
@param email - Email address to validate
|
||||
@returns true if valid, false otherwise
|
||||
|
||||
###Your Task###
|
||||
[Your code here]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Principle 13: Elicit Unbiased Answers
|
||||
|
||||
**Rule:** For sensitive topics, explicitly request unbiased treatment.
|
||||
|
||||
**Example:**
|
||||
"Analyze this political proposal objectively, presenting both supporting and opposing viewpoints without judgment. Include factual pros and cons from multiple perspectives."
|
||||
|
||||
---
|
||||
|
||||
### Principle 14: Elicit Clarifying Questions
|
||||
|
||||
**Rule:** Have the model ask questions to understand your needs.
|
||||
|
||||
**Example:**
|
||||
"I need help designing a database. Ask me questions to understand my requirements before suggesting a solution."
|
||||
|
||||
**When to Use:**
|
||||
- Requirements are unclear
|
||||
- Multiple valid approaches exist
|
||||
- Personalization needed
|
||||
|
||||
---
|
||||
|
||||
### Principle 15: Test Understanding
|
||||
|
||||
**Rule:** Include comprehension checks or exercises.
|
||||
|
||||
**Example:**
|
||||
```
|
||||
Explain async/await, then provide:
|
||||
1. Three quiz questions to test understanding
|
||||
2. One coding exercise
|
||||
3. Solution with explanation
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Principle 16: Use Affirmative Language
|
||||
|
||||
**Rule:** Frame instructions positively.
|
||||
|
||||
**Negative:** "Don't forget to handle errors."
|
||||
**Affirmative:** "Include error handling for all API calls."
|
||||
|
||||
---
|
||||
|
||||
### Principle 18: Define Learning Objectives
|
||||
|
||||
**Rule:** State what the learner should achieve.
|
||||
|
||||
**Example:**
|
||||
"After this tutorial, the user should be able to:
|
||||
1. Create React components
|
||||
2. Manage state with useState
|
||||
3. Handle user events
|
||||
4. Deploy to production"
|
||||
|
||||
---
|
||||
|
||||
### Principle 23: Use Multi-Turn Conversations
|
||||
|
||||
**Rule:** Break complex tasks across multiple prompts.
|
||||
|
||||
**Pattern:**
|
||||
```
|
||||
Turn 1: "Design database schema"
|
||||
Turn 2: "Now create API endpoints for that schema"
|
||||
Turn 3: "Add authentication to those endpoints"
|
||||
```
|
||||
|
||||
**When to Use:**
|
||||
- Very complex projects
|
||||
- Iterative refinement needed
|
||||
- Building on previous responses
|
||||
|
||||
---
|
||||
|
||||
## Principle Combination Strategies
|
||||
|
||||
### The Power Trio (Most Versatile)
|
||||
**3 (Breakdown) + 8 (Delimiters) + 21 (Detail)**
|
||||
|
||||
Use for: Almost any task
|
||||
Impact: 300-400% improvement
|
||||
|
||||
### The Technical Quad
|
||||
**3 + 8 + 17 (Format) + 19 (Chain-of-thought)**
|
||||
|
||||
Use for: Code, debugging, architecture
|
||||
Impact: 400-500% improvement
|
||||
|
||||
### The Learning Stack
|
||||
**2 (Audience) + 5 (Complexity) + 18 (Objectives) + 20 (Examples)**
|
||||
|
||||
Use for: Tutorials, explanations
|
||||
Impact: 450% improvement
|
||||
|
||||
---
|
||||
|
||||
## Quick Selection Matrix
|
||||
|
||||
| If you need... | Use Principles... | Example Phrase |
|
||||
|---------------|-------------------|----------------|
|
||||
| Better code | 3, 7, 8, 12, 17, 21 | "Create [X] with these requirements..." |
|
||||
| Clear explanation | 2, 5, 20, 22 | "Explain [X] for [audience] with examples" |
|
||||
| Structured output | 3, 8, 17, 24 | "Format as [type] with [sections]" |
|
||||
| Deep analysis | 12, 19, 21, 25 | "Analyze step-by-step considering [criteria]" |
|
||||
| Learning content | 5, 14, 15, 18, 20 | "Teach [X] to [level] with [objectives]" |
|
||||
|
||||
---
|
||||
|
||||
**Total Principles**: 26
|
||||
**Core Essentials** (use always): 3, 8, 21
|
||||
**High Impact** (use frequently): 2, 7, 12, 17, 19, 25
|
||||
**Situational** (use when relevant): 4-6, 10-11, 13-16, 18, 20, 22-24, 26
|
||||
Reference in New Issue
Block a user