Prompt Engineering Patterns
Master advanced prompt engineering techniques to maximize LLM performance, reliability, and controllability.
Do not use this skill when
- The task is unrelated to prompt engineering patterns
- You need a different domain or tool outside this scope
Instructions
- Clarify goals, constraints, and required inputs.
- Apply relevant best practices and validate outcomes.
- Provide actionable steps and verification.
- If detailed examples are required, open
resources/implementation-playbook.md.
Use this skill when
- Designing complex prompts for production LLM applications
- Optimizing prompt performance and consistency
- Implementing structured reasoning patterns (chain-of-thought, tree-of-thought)
- Building few-shot learning systems with dynamic example selection
- Creating reusable prompt templates with variable interpolation
- Debugging and refining prompts that produce inconsistent outputs
- Implementing system prompts for specialized AI assistants
Core Capabilities
1. Few-Shot Learning
- Example selection strategies (semantic similarity, diversity sampling)
- Balancing example count with context window constraints
- Constructing effective demonstrations with input-output pairs
- Dynamic example retrieval from knowledge bases
- Handling edge cases through strategic example selection
2. Chain-of-Thought Prompting
- Step-by-step reasoning elicitation
- Zero-shot CoT with "Let's think step by step"
- Few-shot CoT with reasoning traces
- Self-consistency techniques (sampling multiple reasoning paths)
- Verification and validation steps
3. Prompt Optimization
- Iterative refinement workflows
- A/B testing prompt variations
- Measuring prompt performance metrics (accuracy, consistency, latency)
- Reducing token usage while maintaining quality
- Handling edge cases and failure modes
4. Template Systems
- Variable interpolation and formatting
- Conditional prompt sections
- Multi-turn conversation templates
- Role-based prompt composition
- Modular prompt components
5. System Prompt Design
- Setting model behavior and constraints
- Defining output formats and structure
- Establishing role and expertise
- Safety guidelines and content policies
- Context setting and background information
Quick Start
from prompt_optimizer import PromptTemplate, FewShotSelector
# Define a structured prompt template
template = PromptTemplate(
system="You are an expert SQL developer. Generate efficient, secure SQL queries.",
instruction="Convert the following natural language query to SQL:\n{query}",
few_shot_examples=True,
output_format="SQL code block with explanatory comments"
)
# Configure few-shot learning
selector = FewShotSelector(
examples_db="sql_examples.jsonl",
selection_strategy="semantic_similarity",
max_examples=3
)
# Generate optimized prompt
prompt = template.render(
query="Find all users who registered in the last 30 days",
examples=selector.select(query="user registration date filter")
)
Key Patterns
Progressive Disclosure
Start with simple prompts, add complexity only when needed:
Level 1: Direct instruction
Level 2: Add constraints
- "Summarize this article in 3 bullet points, focusing on key findings"
Level 3: Add reasoning
- "Read this article, identify the main findings, then summarize in 3 bullet points"
Level 4: Add examples
- Include 2-3 example summaries with input-output pairs
Instruction Hierarchy
[System Context] → [Task Instruction] → [Examples] → [Input Data] → [Output Format]
Error Recovery
Build prompts that gracefully handle failures:
- Include fallback instructions
- Request confidence scores
- Ask for alternative interpretations when uncertain
- Specify how to indicate missing information
Best Practices
- Be Specific: Vague prompts produce inconsistent results
- Show, Don't Tell: Examples are more effective than descriptions
- Test Extensively: Evaluate on diverse, representative inputs
- Iterate Rapidly: Small changes can have large impacts
- Monitor Performance: Track metrics in production
- Version Control: Treat prompts as code with proper versioning
- Document Intent: Explain why prompts are structured as they are
Common Pitfalls
- Over-engineering: Starting with complex prompts before trying simple ones
- Example pollution: Using examples that don't match the target task
- Context overflow: Exceeding token limits with excessive examples
- Ambiguous instructions: Leaving room for multiple interpretations
- Ignoring edge cases: Not testing on unusual or boundary inputs
Integration Patterns
With RAG Systems
# Combine retrieved context with prompt engineering
prompt = f"""Given the following context:
{retrieved_context}
{few_shot_examples}
Question: {user_question}
Provide a detailed a
1---
2name: prompt-engineering-patterns
3description: Master advanced prompt engineering techniques to maximize LLM performance, reliability, and controllability.
4category: Document Processing
5source: antigravity
6tags: [python, api, ai, llm, workflow, template, design, document, rag, cro]
7url: https://github.com/sickn33/antigravity-awesome-skills/tree/main/skills/prompt-engineering-patterns
8metadata:
9 source: https://skillmd.com/skills/sickn33/prompt-engineering-patterns
10---
11
12
13# Prompt Engineering Patterns
14
15Master advanced prompt engineering techniques to maximize LLM performance, reliability, and controllability.
16
17## Do not use this skill when
18
19- The task is unrelated to prompt engineering patterns
20- You need a different domain or tool outside this scope
21
22## Instructions
23
24- Clarify goals, constraints, and required inputs.
25- Apply relevant best practices and validate outcomes.
26- Provide actionable steps and verification.
27- If detailed examples are required, open `resources/implementation-playbook.md`.
28
29## Use this skill when
30
31- Designing complex prompts for production LLM applications
32- Optimizing prompt performance and consistency
33- Implementing structured reasoning patterns (chain-of-thought, tree-of-thought)
34- Building few-shot learning systems with dynamic example selection
35- Creating reusable prompt templates with variable interpolation
36- Debugging and refining prompts that produce inconsistent outputs
37- Implementing system prompts for specialized AI assistants
38
39## Core Capabilities
40
41### 1. Few-Shot Learning
42- Example selection strategies (semantic similarity, diversity sampling)
43- Balancing example count with context window constraints
44- Constructing effective demonstrations with input-output pairs
45- Dynamic example retrieval from knowledge bases
46- Handling edge cases through strategic example selection
47
48### 2. Chain-of-Thought Prompting
49- Step-by-step reasoning elicitation
50- Zero-shot CoT with "Let's think step by step"
51- Few-shot CoT with reasoning traces
52- Self-consistency techniques (sampling multiple reasoning paths)
53- Verification and validation steps
54
55### 3. Prompt Optimization
56- Iterative refinement workflows
57- A/B testing prompt variations
58- Measuring prompt performance metrics (accuracy, consistency, latency)
59- Reducing token usage while maintaining quality
60- Handling edge cases and failure modes
61
62### 4. Template Systems
63- Variable interpolation and formatting
64- Conditional prompt sections
65- Multi-turn conversation templates
66- Role-based prompt composition
67- Modular prompt components
68
69### 5. System Prompt Design
70- Setting model behavior and constraints
71- Defining output formats and structure
72- Establishing role and expertise
73- Safety guidelines and content policies
74- Context setting and background information
75
76## Quick Start
77
78```python
79from prompt_optimizer import PromptTemplate, FewShotSelector
80
81# Define a structured prompt template
82template = PromptTemplate(
83 system="You are an expert SQL developer. Generate efficient, secure SQL queries.",
84 instruction="Convert the following natural language query to SQL:\n{query}",
85 few_shot_examples=True,
86 output_format="SQL code block with explanatory comments"
87)
88
89# Configure few-shot learning
90selector = FewShotSelector(
91 examples_db="sql_examples.jsonl",
92 selection_strategy="semantic_similarity",
93 max_examples=3
94)
95
96# Generate optimized prompt
97prompt = template.render(
98 query="Find all users who registered in the last 30 days",
99 examples=selector.select(query="user registration date filter")
100)
101```
102
103## Key Patterns
104
105### Progressive Disclosure
106Start with simple prompts, add complexity only when needed:
107
1081. **Level 1**: Direct instruction
109 - "Summarize this article"
110
1112. **Level 2**: Add constraints
112 - "Summarize this article in 3 bullet points, focusing on key findings"
113
1143. **Level 3**: Add reasoning
115 - "Read this article, identify the main findings, then summarize in 3 bullet points"
116
1174. **Level 4**: Add examples
118 - Include 2-3 example summaries with input-output pairs
119
120### Instruction Hierarchy
121```
122[System Context] → [Task Instruction] → [Examples] → [Input Data] → [Output Format]
123```
124
125### Error Recovery
126Build prompts that gracefully handle failures:
127- Include fallback instructions
128- Request confidence scores
129- Ask for alternative interpretations when uncertain
130- Specify how to indicate missing information
131
132## Best Practices
133
1341. **Be Specific**: Vague prompts produce inconsistent results
1352. **Show, Don't Tell**: Examples are more effective than descriptions
1363. **Test Extensively**: Evaluate on diverse, representative inputs
1374. **Iterate Rapidly**: Small changes can have large impacts
1385. **Monitor Performance**: Track metrics in production
1396. **Version Control**: Treat prompts as code with proper versioning
1407. **Document Intent**: Explain why prompts are structured as they are
141
142## Common Pitfalls
143
144- **Over-engineering**: Starting with complex prompts before trying simple ones
145- **Example pollution**: Using examples that don't match the target task
146- **Context overflow**: Exceeding token limits with excessive examples
147- **Ambiguous instructions**: Leaving room for multiple interpretations
148- **Ignoring edge cases**: Not testing on unusual or boundary inputs
149
150## Integration Patterns
151
152### With RAG Systems
153```python
154# Combine retrieved context with prompt engineering
155prompt = f"""Given the following context:
156{retrieved_context}
157
158{few_shot_examples}
159
160Question: {user_question}
161
162Provide a detailed a