New to Claude Skills? Learn how to install them →

wshobson on GitHub

Prompt Engineering Patterns

Free

Enhance LLM prompts for better performance and reliability.

by wshobson38.7k stars on wshobson/agents
2 views
Updated Jul 18, 2026
Get this skill

Free · Opens the source repo

What Prompt Engineering Patterns does

Prompt Engineering Patterns is a skill designed to help developers and designers optimize their interactions with large language models (LLMs). This skill provides a comprehensive set of techniques for crafting effective prompts, ensuring that the generated outputs are consistent, accurate, and aligned with user expectations. By utilizing advanced prompt engineering patterns, users can significantly improve the performance of their LLM applications, making them more reliable and controllable.

The skill encompasses various methodologies, including few-shot learning and chain-of-thought prompting. Few-shot learning allows users to dynamically select examples that best illustrate the task at hand, balancing the need for context with the constraints of the model's input size. Chain-of-thought prompting encourages structured reasoning, enabling the model to break down complex tasks into manageable steps, which can lead to more coherent and logical outputs.

In addition to these techniques, the skill also emphasizes the importance of structured outputs, allowing for reliable parsing and error handling. Users can define schemas for their outputs using Pydantic, ensuring that the responses from the model adhere to expected formats. This is particularly useful in production environments where consistent data structures are crucial for downstream processing.

Overall, Prompt Engineering Patterns is an essential tool for anyone looking to leverage LLMs effectively, whether in building chatbots, automated content generation systems, or any application that requires nuanced understanding and generation of human-like text.

When to use it

Use this skill when designing complex prompts for production applications, optimizing prompt performance, or debugging prompt issues.

When not to use it

This skill may not be suitable for simple prompt tasks or when working with models that do not require advanced prompt engineering techniques.

What you can build with it

Designing Complex Prompts

When creating prompts for sophisticated LLM applications, this skill provides the necessary frameworks and techniques to ensure clarity and effectiveness.

Optimizing Existing Prompts

If you have prompts that yield inconsistent results, this skill offers strategies for refining and optimizing them to achieve better performance.

Implementing Structured Outputs

For applications requiring reliable data formats, this skill helps you define and enforce structured outputs, ensuring that responses are consistently formatted.

How to install Prompt Engineering Patterns

View source

1. Install with the skills CLI

npx skills add wshobson/agents/prompt-engineering-patterns --agent claude-code

2. Or install it manually

Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.

Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs

Inside SKILL.md

Written by wshobson

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

Frequently asked questions about Prompt Engineering Patterns

Similar skills