Master advanced prompt engineering techniques to maximize LLM performance, reliability, and controllability in production. Use when optimizing prompts, improving LLM outputs, or designing production prompt templates.
Add this skill
npx mdskills install sickn33/prompt-engineering-patternsComprehensive prompt engineering guide with patterns, examples, and optimization strategies
1---2name: prompt-engineering-patterns3description: Master advanced prompt engineering techniques to maximize LLM performance, reliability, and controllability in production. Use when optimizing prompts, improving LLM outputs, or designing production prompt templates.4---56# Prompt Engineering Patterns78Master advanced prompt engineering techniques to maximize LLM performance, reliability, and controllability.910## Do not use this skill when1112- The task is unrelated to prompt engineering patterns13- You need a different domain or tool outside this scope1415## Instructions1617- Clarify goals, constraints, and required inputs.18- Apply relevant best practices and validate outcomes.19- Provide actionable steps and verification.20- If detailed examples are required, open `resources/implementation-playbook.md`.2122## Use this skill when2324- Designing complex prompts for production LLM applications25- Optimizing prompt performance and consistency26- Implementing structured reasoning patterns (chain-of-thought, tree-of-thought)27- Building few-shot learning systems with dynamic example selection28- Creating reusable prompt templates with variable interpolation29- Debugging and refining prompts that produce inconsistent outputs30- Implementing system prompts for specialized AI assistants3132## Core Capabilities3334### 1. Few-Shot Learning35- Example selection strategies (semantic similarity, diversity sampling)36- Balancing example count with context window constraints37- Constructing effective demonstrations with input-output pairs38- Dynamic example retrieval from knowledge bases39- Handling edge cases through strategic example selection4041### 2. Chain-of-Thought Prompting42- Step-by-step reasoning elicitation43- Zero-shot CoT with "Let's think step by step"44- Few-shot CoT with reasoning traces45- Self-consistency techniques (sampling multiple reasoning paths)46- Verification and validation steps4748### 3. Prompt Optimization49- Iterative refinement workflows50- A/B testing prompt variations51- Measuring prompt performance metrics (accuracy, consistency, latency)52- Reducing token usage while maintaining quality53- Handling edge cases and failure modes5455### 4. Template Systems56- Variable interpolation and formatting57- Conditional prompt sections58- Multi-turn conversation templates59- Role-based prompt composition60- Modular prompt components6162### 5. System Prompt Design63- Setting model behavior and constraints64- Defining output formats and structure65- Establishing role and expertise66- Safety guidelines and content policies67- Context setting and background information6869## Quick Start7071```python72from prompt_optimizer import PromptTemplate, FewShotSelector7374# Define a structured prompt template75template = PromptTemplate(76 system="You are an expert SQL developer. Generate efficient, secure SQL queries.",77 instruction="Convert the following natural language query to SQL:\n{query}",78 few_shot_examples=True,79 output_format="SQL code block with explanatory comments"80)8182# Configure few-shot learning83selector = FewShotSelector(84 examples_db="sql_examples.jsonl",85 selection_strategy="semantic_similarity",86 max_examples=387)8889# Generate optimized prompt90prompt = template.render(91 query="Find all users who registered in the last 30 days",92 examples=selector.select(query="user registration date filter")93)94```9596## Key Patterns9798### Progressive Disclosure99Start with simple prompts, add complexity only when needed:1001011. **Level 1**: Direct instruction102 - "Summarize this article"1031042. **Level 2**: Add constraints105 - "Summarize this article in 3 bullet points, focusing on key findings"1061073. **Level 3**: Add reasoning108 - "Read this article, identify the main findings, then summarize in 3 bullet points"1091104. **Level 4**: Add examples111 - Include 2-3 example summaries with input-output pairs112113### Instruction Hierarchy114```115[System Context] → [Task Instruction] → [Examples] → [Input Data] → [Output Format]116```117118### Error Recovery119Build prompts that gracefully handle failures:120- Include fallback instructions121- Request confidence scores122- Ask for alternative interpretations when uncertain123- Specify how to indicate missing information124125## Best Practices1261271. **Be Specific**: Vague prompts produce inconsistent results1282. **Show, Don't Tell**: Examples are more effective than descriptions1293. **Test Extensively**: Evaluate on diverse, representative inputs1304. **Iterate Rapidly**: Small changes can have large impacts1315. **Monitor Performance**: Track metrics in production1326. **Version Control**: Treat prompts as code with proper versioning1337. **Document Intent**: Explain why prompts are structured as they are134135## Common Pitfalls136137- **Over-engineering**: Starting with complex prompts before trying simple ones138- **Example pollution**: Using examples that don't match the target task139- **Context overflow**: Exceeding token limits with excessive examples140- **Ambiguous instructions**: Leaving room for multiple interpretations141- **Ignoring edge cases**: Not testing on unusual or boundary inputs142143## Integration Patterns144145### With RAG Systems146```python147# Combine retrieved context with prompt engineering148prompt = f"""Given the following context:149{retrieved_context}150151{few_shot_examples}152153Question: {user_question}154155Provide a detailed answer based solely on the context above. If the context doesn't contain enough information, explicitly state what's missing."""156```157158### With Validation159```python160# Add self-verification step161prompt = f"""{main_task_prompt}162163After generating your response, verify it meets these criteria:1641. Answers the question directly1652. Uses only information from provided context1663. Cites specific sources1674. Acknowledges any uncertainty168169If verification fails, revise your response."""170```171172## Performance Optimization173174### Token Efficiency175- Remove redundant words and phrases176- Use abbreviations consistently after first definition177- Consolidate similar instructions178- Move stable content to system prompts179180### Latency Reduction181- Minimize prompt length without sacrificing quality182- Use streaming for long-form outputs183- Cache common prompt prefixes184- Batch similar requests when possible185186## Resources187188- **references/few-shot-learning.md**: Deep dive on example selection and construction189- **references/chain-of-thought.md**: Advanced reasoning elicitation techniques190- **references/prompt-optimization.md**: Systematic refinement workflows191- **references/prompt-templates.md**: Reusable template patterns192- **references/system-prompts.md**: System-level prompt design193- **assets/prompt-template-library.md**: Battle-tested prompt templates194- **assets/few-shot-examples.json**: Curated example datasets195- **scripts/optimize-prompt.py**: Automated prompt optimization tool196197## Success Metrics198199Track these KPIs for your prompts:200- **Accuracy**: Correctness of outputs201- **Consistency**: Reproducibility across similar inputs202- **Latency**: Response time (P50, P95, P99)203- **Token Usage**: Average tokens per request204- **Success Rate**: Percentage of valid outputs205- **User Satisfaction**: Ratings and feedback206207## Next Steps2082091. Review the prompt template library for common patterns2102. Experiment with few-shot learning for your specific use case2113. Implement prompt versioning and A/B testing2124. Set up automated evaluation pipelines2135. Document your prompt engineering decisions and learnings214
Full transparency — inspect the skill content before installing.