All skills
wshobson avatar

/prompt-engineering-patterns

@511f834
by Seth Hobsonwshobson/agents40k stars
4,281

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.

Use this Skill: https://skilld.dev/gh/wshobson/agents/prompt-engineering-patterns

This session only. Nothing lands on disk.

SKILL.md

≈90 tokens always: the name and description. ≈1.2k when used: this file. ≈17k more on demand in 8 files.

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

Source: SKILL.md on GitHub

No alerts16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    The skill is a comprehensive resource for prompt engineering patterns, including templates, documentation, and optimization utilities. It follows established best practices for LLM application development and uses standard, trusted libraries. No malicious behaviors, obfuscation, or security risks were identified.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer6mo

    2/9 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 511f834. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 3 days ago.

Activeupdated 3 months ago
  • prompt-engineering
  • llm
  • chain-of-thought
  • few-shot
  • structured-outputs
  • prompt-optimization
  • pydantic
  • langchain
  • claude

README badge

README badge for wshobson/agents/prompt-engineering-patterns

Teaches advanced prompt engineering patterns including chain-of-thought reasoning, few-shot learning, structured outputs, and prompt optimization for production LLM applications. Use this skill when optimizing prompts, designing templates, implementing reasoning patterns, or debugging inconsistent LLM outputs.

Generated from the current SKILL.md.

What prompt engineering techniques does this skill cover?
The skill covers few-shot learning, chain-of-thought reasoning, structured outputs (JSON mode and Pydantic schemas), prompt optimization and A/B testing, template systems with variable interpolation, and system prompt design for specialized assistants.
Does this skill work with specific LLM providers?
The quick start example uses Claude via langchain_anthropic, but the patterns are model-agnostic. The skill teaches prompt engineering techniques applicable to any LLM that supports structured outputs and multi-turn conversations.
Can I use this skill for debugging prompts that produce inconsistent outputs?
Yes. The skill includes iterative refinement workflows, A/B testing strategies, and guidance on measuring consistency metrics to identify and fix prompt issues in production.
Does this skill include template systems and reusable prompt components?
Yes. It covers variable interpolation, conditional prompt sections, multi-turn conversation templates, and modular prompt composition for building reusable systems.
What should I do if outputs are malformed or don't parse correctly?
Use structured outputs with Pydantic schema enforcement and JSON mode to enforce type-safe responses. The skill also documents error handling strategies and common pitfalls to avoid.

Generated from the current SKILL.md. These answers refresh after source changes.