Advanced Prompt Patterns
Prompt engineering patterns

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…
--- name: prompt-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. --- # Prompt Engineering Patterns Master advanced prompt engineering techniques to maximize LLM performance, reliability, and controllability. ## When to Use This Skill - Designing complex prompts for production LLM applications - Optimizing prompt performance and consistency - Implementing structured reasoning patterns (chain-of-thought, tree-of-thought)
Overview
Master advanced prompt engineering techniques to maximize LLM performance, reliability, and controllability.
Manual install (npx, ZIP)
Claude Code
npx skills add wshobson/agents --skill prompt-engineering-patterns -g -a claude-codeClaude Code (manual)
mkdir -p ~/.claude/skills && curl -sL https://codeload.github.com/wshobson/agents/tar.gz/4236bb91f839 \
| tar -xz -C ~/.claude/skills --strip-components=4 agents-4236bb91f839/plugins/llm-application-dev/skills/prompt-engineering-patternsWindows (PowerShell)
New-Item -ItemType Directory -Force "$HOME\.claude\skills" | Out-Null; Invoke-WebRequest "https://m.agentalley.io/zip/7cd79ce915e7d269a240/prompt-engineering-patterns.zip" -OutFile "$env:TEMP\prompt-engineering-patterns.zip"; Expand-Archive "$env:TEMP\prompt-engineering-patterns.zip" -DestinationPath "$HOME\.claude\skills" -ForceClaude.ai / desktop
Codex, Cursor, other agents
Connects with Agent Alley MCP · agentalley.io/mcp
Files included
SKILL.md5.1 KBassets/2 files · 7.3 KBreferences/6 files · 58.0 KBscripts/1 file · 9.3 KB
Read the files here
wshobson/
SKILL.md
Show the full text145 lines
Prompt Engineering Patterns
Master advanced prompt engineering techniques to maximize LLM performance, reliability, and controllability.
When to Use This Skill
- 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
- Using structured outputs (JSON mode) for reliable parsing
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. Structured Outputs
- JSON mode for reliable parsing
- Pydantic schema enforcement
- Type-safe response handling
- Error handling for malformed outputs
4. 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
5. Template Systems
- Variable interpolation and formatting
- Conditional prompt sections
- Multi-turn conversation templates
- Role-based prompt composition
- Modular prompt components
6. 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 langchain_anthropic import ChatAnthropic
from langchain_core.prompts import ChatPromptTemplate
from pydantic import BaseModel, Field
# Define structured output schema
class SQLQuery(BaseModel):
query: str = Field(description="The SQL query")
explanation: str = Field(description="Brief explanation of what the query does")
tables_used: list[str] = Field(description="List of tables referenced")
# Initialize model with structured output
llm = ChatAnthropic(model="claude-sonnet-5")
structured_llm = llm.with_structured_output(SQLQuery)
# Create prompt template
prompt = ChatPromptTemplate.from_messages([
("system", """You are an expert SQL developer. Generate efficient, secure SQL queries.
Always use parameterized queries to prevent SQL injection.
Explain your reasoning briefly."""),
("user", "Convert this to SQL: {query}")
])
# Create chain
chain = prompt | structured_llm
# Use
result = await chain.ainvoke({
"query": "Find all users who registered in the last 30 days"
})
print(result.query)
print(result.explanation)
Detailed patterns and worked examples
Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.
Best Practices
- Be Specific: Vague prompts produce inconsistent results
- Show, Don't Tell: Examples are more effective than descriptions
- Use Structured Outputs: Enforce schemas with Pydantic for reliability
- 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
- No error handling: Assuming outputs will always be well-formed
- Hardcoded values: Not parameterizing prompts for reuse
Success Metrics
Track these KPIs for your prompts:
- Accuracy: Correctness of outputs
- Consistency: Reproducibility across similar inputs
- Latency: Response time (P50, P95, P99)
- Token Usage: Average tokens per request
- Success Rate: Percentage of valid, parseable outputs
- User Satisfaction: Ratings and feedback
| 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 | |
| 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 | **Be Specific**: Vague prompts produce inconsistent results |
| 117 | **Show, Don't Tell**: Examples are more effective than descriptions |
| 118 | **Use Structured Outputs**: Enforce schemas with Pydantic for reliability |
| 119 | **Test Extensively**: Evaluate on diverse, representative inputs |
| 120 | **Iterate Rapidly**: Small changes can have large impacts |
| 121 | **Monitor Performance**: Track metrics in production |
| 122 | **Version Control**: Treat prompts as code with proper versioning |
| 123 | **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 |
Details
- Updated
- Sep 21, 2026
- License
- MIT
- Stars on the repo
- ★ 39,857
- Checked
- Source
- wshobson/agents ↗
- Creator
- wshobson · 179 listings
Similar skills
See all →
SkillSkill Builder from Sources
SkillAnthropic Skill Creator
SkillMarketing Prompt Testing
SkillPrompt Engineering Expert
AgentProduction Prompt Optimizer
SkillProgrammatic Prompt LibraryMore from wshobson
Skill.NET Backend Developer
SkillWCAG 2.2 Implementation
SkillMaterial Design 3 & Compose
SkillAngularJS to Angular Upgrade
SkillReverse Engineering Defense
SkillApache Airflow DAG Builder