Prompt Engineering Patterns

Prompt Engineering Patterns

Teaches advanced prompt engineering patterns such as few-shot, chain-of-thought, templates and system prompts, with references and a script for optimizing prompts in production LLM apps.

Skill files10 files

assets/

references/

scripts/

SKILL.md145 lines
1
---
2
name: prompt-engineering-patterns
3
description: >-
4
This skill should be used when the user asks to "optimize a prompt", "improve prompt
5
performance", "design a prompt template", "write better prompts", "debug prompt issues", "use
6
chain-of-thought", "structured prompting", "few-shot prompting", or wants to apply advanced
7
prompt engineering patterns for production LLM applications.
8
---
9
10
# Prompt Engineering Patterns
11
12
Master advanced prompt engineering techniques to maximize LLM performance, reliability, and controllability.
13
14
## When to Use This Skill
15
16
- Designing complex prompts for production LLM applications
17
- Optimizing prompt performance and consistency
18
- Implementing structured reasoning patterns (chain-of-thought, tree-of-thought)
19
- Building few-shot learning systems with dynamic example selection
20
- Creating reusable prompt templates with variable interpolation
21
- Debugging and refining prompts that produce inconsistent outputs
22
- Implementing system prompts for specialized AI assistants
23
- Using structured outputs (JSON mode) for reliable parsing
24
25
## Core Capabilities
26
27
### 1. Few-Shot Learning
28
29
- Example selection strategies (semantic similarity, diversity sampling)
30
- Balancing example count with context window constraints
31
- Constructing effective demonstrations with input-output pairs
32
- Dynamic example retrieval from knowledge bases
33
- Handling edge cases through strategic example selection
34
35
### 2. Chain-of-Thought Prompting
36
37
- Step-by-step reasoning elicitation
38
- Zero-shot CoT with "Let's think step by step"
39
- Few-shot CoT with reasoning traces
40
- Self-consistency techniques (sampling multiple reasoning paths)
41
- Verification and validation steps
42
43
### 3. Structured Outputs
44
45
- JSON mode for reliable parsing
46
- Pydantic schema enforcement
47
- Type-safe response handling
48
- Error handling for malformed outputs
49
50
### 4. Prompt Optimization
51
52
- Iterative refinement workflows
53
- A/B testing prompt variations
54
- Measuring prompt performance metrics (accuracy, consistency, latency)
55
- Reducing token usage while maintaining quality
56
- Handling edge cases and failure modes
57
58
### 5. Template Systems
59
60
- Variable interpolation and formatting
61
- Conditional prompt sections
62
- Multi-turn conversation templates
63
- Role-based prompt composition
64
- Modular prompt components
65
66
### 6. System Prompt Design
67
68
- Setting model behavior and constraints
69
- Defining output formats and structure
70
- Establishing role and expertise
71
- Safety guidelines and content policies
72
- Context setting and background information
73
74
## Quick Start
75
76
```python
77
from langchain_anthropic import ChatAnthropic
78
from langchain_core.prompts import ChatPromptTemplate
79
from pydantic import BaseModel, Field
80
81
# Define structured output schema
82
class SQLQuery(BaseModel):
83
query: str = Field(description="The SQL query")
84
explanation: str = Field(description="Brief explanation of what the query does")
85
tables_used: list[str] = Field(description="List of tables referenced")
86
87
# Initialize model with structured output
88
llm = ChatAnthropic(model="claude-sonnet-5")
89
structured_llm = llm.with_structured_output(SQLQuery)
90
91
# Create prompt template
92
prompt = ChatPromptTemplate.from_messages([
93
("system", """You are an expert SQL developer. Generate efficient, secure SQL queries.
94
Always use parameterized queries to prevent SQL injection.
95
Explain your reasoning briefly."""),
96
("user", "Convert this to SQL: {query}")
97
])
98
99
# Create chain
100
chain = prompt | structured_llm
101
102
# Use
103
result = await chain.ainvoke({
104
"query": "Find all users who registered in the last 30 days"
105
})
106
print(result.query)
107
print(result.explanation)
108
```
109
110
## Detailed patterns and worked examples
111
112
Detailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient.
113
114
## Best Practices
115
116
1. **Be Specific**: Vague prompts produce inconsistent results
117
2. **Show, Don't Tell**: Examples are more effective than descriptions
118
3. **Use Structured Outputs**: Enforce schemas with Pydantic for reliability
119
4. **Test Extensively**: Evaluate on diverse, representative inputs
120
5. **Iterate Rapidly**: Small changes can have large impacts
121
6. **Monitor Performance**: Track metrics in production
122
7. **Version Control**: Treat prompts as code with proper versioning
123
8. **Document Intent**: Explain why prompts are structured as they are
124
125
## Common Pitfalls
126
127
- **Over-engineering**: Starting with complex prompts before trying simple ones
128
- **Example pollution**: Using examples that don't match the target task
129
- **Context overflow**: Exceeding token limits with excessive examples
130
- **Ambiguous instructions**: Leaving room for multiple interpretations
131
- **Ignoring edge cases**: Not testing on unusual or boundary inputs
132
- **No error handling**: Assuming outputs will always be well-formed
133
- **Hardcoded values**: Not parameterizing prompts for reuse
134
135
## Success Metrics
136
137
Track these KPIs for your prompts:
138
139
- **Accuracy**: Correctness of outputs
140
- **Consistency**: Reproducibility across similar inputs
141
- **Latency**: Response time (P50, P95, P99)
142
- **Token Usage**: Average tokens per request
143
- **Success Rate**: Percentage of valid, parseable outputs
144
- **User Satisfaction**: Ratings and feedback
145

© Seth Hobson · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…