Skills · Data & AI

Prompt Engineering Patterns

Unverified31/40

>- This skill should be used when the user asks to "optimize a prompt", "improve prompt performance", "design a prompt template", "write better prompts", "debug prompt issues", "use chain-of-thought", "structured prompting", "few-shot prompting", or wants to apply advanced prompt engineering patterns for production LLM applications.

Originally by wshobson · MIT

Claude CodePartialHas SKILL.md but declares no allowed-tools — Claude Code will ask for permission each time
CursorPartialPlain prose you can paste in — but no Cursor rules file
CodexPartialPlain prose you can paste in — but no AGENTS.md
Gemini CLIPartialPlain prose you can paste in
CopilotPartialPlain prose you can paste in — but no Copilot instructions file
npx agentalley add prompt-engineering-patterns

This command does not work yet — the CLI is still being built. Until then, use Raw in the reader below to take the file.

Who is stuck, and on what

>- This skill should be used when the user asks to "optimize a prompt", "improve prompt performance", "design a prompt template", "write better prompts", "debug prompt issues", "use chain-of-thought", "structured prompting", "few-shot prompting", or wants to apply advanced prompt engineering patterns for production LLM applications.

The whole source

No sign-in, no blur, nothing truncated
prompt-engineering-patterns/SKILL.md145 lines5.1 KBRawView on GitHub
Frontmatter — 2 properties
nameprompt-engineering-patterns
description>- This skill should be used when the user asks to "optimize a prompt", "improve prompt performance", "design a prompt template", "write better prompts", "debug prompt issues", "use chain-of-thought", "structured prompting", "few-shot prompting", or wants to apply advanced prompt engineering patterns for production LLM applications.
1---
2name: prompt-engineering-patterns
3description: >-
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---A5No allowed-tools declared — no way to tell what this skill may touch
9 
10# Prompt Engineering Patterns
11 
12Master 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
77from langchain_anthropic import ChatAnthropic
78from langchain_core.prompts import ChatPromptTemplate
79from pydantic import BaseModel, Field
80 
81# Define structured output schema
82class 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
88llm = ChatAnthropic(model="claude-sonnet-5")
89structured_llm = llm.with_structured_output(SQLQuery)
90 
91# Create prompt template
92prompt = 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
100chain = prompt | structured_llm
101 
102# Use
103result = await chain.ainvoke({
104 "query": "Find all users who registered in the last 30 days"
105})
106print(result.query)
107print(result.explanation)
108```
109 
110## Detailed patterns and worked examples
111 
112Detailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient.
113 
114## Best Practices
115 
1161. **Be Specific**: Vague prompts produce inconsistent results
1172. **Show, Don't Tell**: Examples are more effective than descriptions
1183. **Use Structured Outputs**: Enforce schemas with Pydantic for reliability
1194. **Test Extensively**: Evaluate on diverse, representative inputs
1205. **Iterate Rapidly**: Small changes can have large impacts
1216. **Monitor Performance**: Track metrics in production
1227. **Version Control**: Treat prompts as code with proper versioning
1238. **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 
137Track 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 

Reviews

Installed this one?Write the first review and take the Trailblazer badge.

Reviews only open after a real install, so this is empty — and we leave it empty rather than invent one.

Alternatives

Also in Data & AI