PR

prompt-engineering-patterns

Guidance on optimizing LLM prompts using structured reasoning, few-shot learning, and production-ready templates.

Install

mkdir -p .claude/skills/prompt-engineering-patterns && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/5" && unzip -o skill.zip -d .claude/skills/prompt-engineering-patterns && rm skill.zip

Installs to .claude/skills/prompt-engineering-patterns

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Master advanced prompt engineering techniques to maximize LLM performance, reliability, and controllability in production. Use when optimizing prompts, improving LLM outputs, or designing production prompt templates.
216 chars · catalog description✓ has a “when” trigger
Advanced

Key capabilities

  • Implement chain-of-thought reasoning patterns
  • Enforce structured outputs using Pydantic schemas
  • Design few-shot learning systems with dynamic examples
  • Create reusable prompt templates with variable interpolation
  • Measure prompt performance metrics like accuracy and latency

How it works

The skill applies advanced engineering patterns like few-shot learning and chain-of-thought to refine model behavior and ensure reliable, type-safe outputs.

Inputs & outputs

You give it
Task description and performance requirements
You get back
Optimized prompt template or structured chain

When to use prompt-engineering-patterns

  • Optimizing prompts for inconsistent LLM output
  • Designing reusable prompt templates
  • Implementing chain-of-thought for complex reasoning tasks

About this skill

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

When not to use it

  • When simple, direct prompts are sufficient for the task
  • When the application does not require structured output parsing

Prerequisites

LangChainPydantic

Limitations

  • Risk of context window overflow with excessive examples
  • Requires careful balancing of example diversity and count

How it compares

It treats prompts as version-controlled code with rigorous testing and metrics rather than relying on informal, iterative guessing.

Compared to similar skills

prompt-engineering-patterns side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
prompt-engineering-patterns (this skill)192moReviewAdvanced
skill-creator1283moReviewAdvanced
openrouter199moReviewIntermediate
skill-development179moReviewIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

More by wshobson

View all by wshobson

You might also like

skill-creator

anthropics

Guide for creating effective skills. This skill should be used when users want to create a new skill (or update an existing skill) that extends Claude's capabilities with specialized knowledge, workflows, or tool integrations.

128200

openrouter

rawveg

OpenRouter API - Unified access to 400+ AI models through one API

19178

skill-development

anthropics

This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill content", or needs guidance on skill structure, progressive disclosure, or skill development best practices for Claude Code plugins.

17145

command-development

anthropics

This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.

16133

agent-identifier

anthropics

This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.

15122

llama-factory

zechenzhangAGI

Expert guidance for fine-tuning LLMs with LLaMA-Factory - WebUI no-code, 100+ models, 2/3/4/5/6/8-bit QLoRA, multimodal support

15112

Search skills

Search the agent skills registry