Expert guide on prompt engineering patterns, best practices, and optimization techniques. Use when user wants to improve prompts, learn prompting strategies, or debug agent behavior.
Add this skill
npx mdskills install sickn33/prompt-engineeringComprehensive prompt engineering guide with clear patterns, concrete examples, and practical best practices
1---2name: prompt-engineering3description: Expert guide on prompt engineering patterns, best practices, and optimization techniques. Use when user wants to improve prompts, learn prompting strategies, or debug agent behavior.4---56# Prompt Engineering Patterns78Advanced prompt engineering techniques to maximize LLM performance, reliability, and controllability.910## Core Capabilities1112### 1. Few-Shot Learning1314Teach the model by showing examples instead of explaining rules. Include 2-5 input-output pairs that demonstrate the desired behavior. Use when you need consistent formatting, specific reasoning patterns, or handling of edge cases. More examples improve accuracy but consume tokens—balance based on task complexity.1516**Example:**1718```markdown19Extract key information from support tickets:2021Input: "My login doesn't work and I keep getting error 403"22Output: {"issue": "authentication", "error_code": "403", "priority": "high"}2324Input: "Feature request: add dark mode to settings"25Output: {"issue": "feature_request", "error_code": null, "priority": "low"}2627Now process: "Can't upload files larger than 10MB, getting timeout"28```2930### 2. Chain-of-Thought Prompting3132Request step-by-step reasoning before the final answer. Add "Let's think step by step" (zero-shot) or include example reasoning traces (few-shot). Use for complex problems requiring multi-step logic, mathematical reasoning, or when you need to verify the model's thought process. Improves accuracy on analytical tasks by 30-50%.3334**Example:**3536```markdown37Analyze this bug report and determine root cause.3839Think step by step:40411. What is the expected behavior?422. What is the actual behavior?433. What changed recently that could cause this?444. What components are involved?455. What is the most likely root cause?4647Bug: "Users can't save drafts after the cache update deployed yesterday"48```4950### 3. Prompt Optimization5152Systematically improve prompts through testing and refinement. Start simple, measure performance (accuracy, consistency, token usage), then iterate. Test on diverse inputs including edge cases. Use A/B testing to compare variations. Critical for production prompts where consistency and cost matter.5354**Example:**5556```markdown57Version 1 (Simple): "Summarize this article"58→ Result: Inconsistent length, misses key points5960Version 2 (Add constraints): "Summarize in 3 bullet points"61→ Result: Better structure, but still misses nuance6263Version 3 (Add reasoning): "Identify the 3 main findings, then summarize each"64→ Result: Consistent, accurate, captures key information65```6667### 4. Template Systems6869Build reusable prompt structures with variables, conditional sections, and modular components. Use for multi-turn conversations, role-based interactions, or when the same pattern applies to different inputs. Reduces duplication and ensures consistency across similar tasks.7071**Example:**7273```python74# Reusable code review template75template = """76Review this {language} code for {focus_area}.7778Code:79{code_block}8081Provide feedback on:82{checklist}83"""8485# Usage86prompt = template.format(87 language="Python",88 focus_area="security vulnerabilities",89 code_block=user_code,90 checklist="1. SQL injection\n2. XSS risks\n3. Authentication"91)92```9394### 5. System Prompt Design9596Set global behavior and constraints that persist across the conversation. Define the model's role, expertise level, output format, and safety guidelines. Use system prompts for stable instructions that shouldn't change turn-to-turn, freeing up user message tokens for variable content.9798**Example:**99100```markdown101System: You are a senior backend engineer specializing in API design.102103Rules:104105- Always consider scalability and performance106- Suggest RESTful patterns by default107- Flag security concerns immediately108- Provide code examples in Python109- Use early return pattern110111Format responses as:1121131. Analysis1142. Recommendation1153. Code example1164. Trade-offs117```118119## Key Patterns120121### Progressive Disclosure122123Start with simple prompts, add complexity only when needed:1241251. **Level 1**: Direct instruction126127 - "Summarize this article"1281292. **Level 2**: Add constraints130131 - "Summarize this article in 3 bullet points, focusing on key findings"1321333. **Level 3**: Add reasoning134135 - "Read this article, identify the main findings, then summarize in 3 bullet points"1361374. **Level 4**: Add examples138 - Include 2-3 example summaries with input-output pairs139140### Instruction Hierarchy141142```143[System Context] → [Task Instruction] → [Examples] → [Input Data] → [Output Format]144```145146### Error Recovery147148Build prompts that gracefully handle failures:149150- Include fallback instructions151- Request confidence scores152- Ask for alternative interpretations when uncertain153- Specify how to indicate missing information154155## Best Practices1561571. **Be Specific**: Vague prompts produce inconsistent results1582. **Show, Don't Tell**: Examples are more effective than descriptions1593. **Test Extensively**: Evaluate on diverse, representative inputs1604. **Iterate Rapidly**: Small changes can have large impacts1615. **Monitor Performance**: Track metrics in production1626. **Version Control**: Treat prompts as code with proper versioning1637. **Document Intent**: Explain why prompts are structured as they are164165## Common Pitfalls166167- **Over-engineering**: Starting with complex prompts before trying simple ones168- **Example pollution**: Using examples that don't match the target task169- **Context overflow**: Exceeding token limits with excessive examples170- **Ambiguous instructions**: Leaving room for multiple interpretations171- **Ignoring edge cases**: Not testing on unusual or boundary inputs172
Full transparency — inspect the skill content before installing.