Optimize a prompt, improve prompt performance

Prompt engineering patterns

by wshobson · MIT license · ★ 39,857 on GitHub · updated Sep 21

Prompt engineering patterns cover

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 Codenpx skills add wshobson/agents --skill prompt-engineering-patterns -g -a claude-code
Claude 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-patterns
Windows (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" -Force
Claude.ai / desktopDownload the ZIP and upload it under Settings → Capabilities → Skills.
Codex, Cursor, other agentsPoint them at SKILL.md. The other files are plain text.

Connects with Agent Alley MCP · agentalley.io/mcp

Files included

  • SKILL.md5.1 KB
  • assets/2 files · 7.3 KB
  • references/6 files · 58.0 KB
  • scripts/1 file · 9.3 KB
Read the files here
wshobson/4236bb910 files
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

  1. Be Specific: Vague prompts produce inconsistent results
  2. Show, Don't Tell: Examples are more effective than descriptions
  3. Use Structured Outputs: Enforce schemas with Pydantic for reliability
  4. Test Extensively: Evaluate on diverse, representative inputs
  5. Iterate Rapidly: Small changes can have large impacts
  6. Monitor Performance: Track metrics in production
  7. Version Control: Treat prompts as code with proper versioning
  8. 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---
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---
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 
View all files on GitHub →

Details

Updated
Sep 21, 2026
License
MIT
Stars on the repo
★ 39,857
Checked
Source
wshobson/agents ↗
Creator
wshobson · 179 listings
View creator

Similar skills

See all →
SkillCreate skills from documentation, repos, PDFs, videosSkill Builderyusufkaraaslan/Skill_Seekers · by yusufkaraaslanAutomatically detect source types and build AI skills using Skill Seekers. Use when the user wants to create skills from documentation, repos, PDFs, videos, or other knowledge sources.★ 15.1k GitHub starsSkillCreate new skills, modify and improve existing skillsSkill Creatoranthropics/skills · by anthropicsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.★ 178k GitHub starsPromptA versatile assistant to help with various administrativeGeneral assistant system promptf/prompts.chat · by Hector VerdugoA versatile assistant to help with various administrative and informational tasks, providing guidance, answers, and support across multiple domains.New listingPromptAct as an expert in AI and prompt engineeringGPT-5 | EXPERT PROMPT ENGINEER MODE (CONDENSED)f/prompts.chat · by michael.727Act as an expert in AI and prompt engineering. This prompt provides detailed insights, explanations, and practical examples related to the responsibilities of a prompt engineer. It is structured to be actionable and relevant to real-world applications.New listingPromptA prompt to create a best promptMeta promptf/prompts.chat · by Prince SharmaA prompt to create a best promptNew listingPromptRe-useable meta-prompt to have the AI generate a promptMeta prompt engineerf/prompts.chat · by magejoshRe-useable meta-prompt to have the AI generate a prompt to achieve a $(goal) Simply replace the variable with the actual goal, answer the clarifying questions it asks to give it the constraints and context required for the task, and then use the prompt the AI returns as the prompt to achieve your goal. See an example of it's use here: https://chatgpt.com/share/6947f127-1e84-8013-a360-49a89666c1afNew listing

More from wshobson

SkillMaster C/.NET backend development patterns for buildingwshobson/agents · by wshobsonMaster C#/.NET backend development patterns for building robust APIs, MCP servers, and enterprise applications. Covers async/await, dependency injection, Entity Framework Core, Dapper, configuration, caching, and testing with xUnit. Use when developing .NET backends, reviewing C# code, or designing API architectures.★ 39.9k GitHub starsSkillImplement WCAG 2.2 compliant interfaces with mobileAccessibility compliancewshobson/agents · by wshobsonImplement WCAG 2.2 compliant interfaces with mobile accessibility, inclusive design patterns, and assistive technology support. Use when auditing accessibility, implementing ARIA patterns, building for screen readers, or ensuring inclusive user experiences.★ 39.9k GitHub starsSkillMaster Material Design 3 and Jetpack Compose patternsAndroid Mobile Designwshobson/agents · by wshobsonMaster Material Design 3 and Jetpack Compose patterns for building native Android apps. Use when designing Android interfaces, implementing Compose UI, or following Google's Material Design guidelines.★ 39.9k GitHub starsSkillMigrate from AngularJS to Angular using hybrid modeAngular migrationwshobson/agents · by wshobsonMigrate from AngularJS to Angular using hybrid mode, incremental component rewriting, and dependency injection updates. Use when upgrading AngularJS applications, planning framework migrations, or modernizing legacy Angular code.★ 39.9k GitHub starsSkillUnderstand anti-reversing, obfuscationAnti reversing techniqueswshobson/agents · by wshobsonUnderstand anti-reversing, obfuscation, and protection techniques encountered during software analysis. Use this skill when analyzing malware evasion techniques, when implementing anti-debugging protections for CTF challenges, when reverse engineering packed binaries, or when building security research tools that need to detect virtualized environments.★ 39.9k GitHub starsSkillBuild production Apache Airflow DAGs with best practicesApache Airflow DAG Patternswshobson/agents · by wshobsonBuild production Apache Airflow DAGs with best practices for operators, sensors, testing, and deployment. Use when creating data pipelines, orchestrating workflows, or scheduling batch jobs.★ 39.9k GitHub stars