Agent skill

Prompt Engineering Patterns

by wshobson in wshobson/agents

Reference for designing and tuning production LLM prompts: few-shot examples, chain-of-thought, structured outputs, templates and system prompts.

MITAuto-check passedAI & LLM Engineering

Install Prompt Engineering Patterns

skills CLI
$ npx skills add wshobson/agents --skill prompt-engineering-patterns -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install wshobson/agents prompt-engineering-patterns --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/wshobson/agents.git skills-src && mkdir -p .claude/skills && cp -r skills-src/plugins/llm-application-dev/skills/prompt-engineering-patterns .claude/skills/prompt-engineering-patterns && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
prompt-engineering-patterns
GitHub stars
40k
Token cost
~1.3k tokens
SKILL.md length
439 words
Files
10 (incl. scripts, references, assets)
Skills in repo
142
Repo updated
First seen
Licence
MIT

At a glance

Reference for designing and tuning production LLM prompts: few-shot examples, chain-of-thought, structured outputs, templates and system prompts.

  • Works in 6 steps: Few-Shot Learning → Chain-of-Thought Prompting → Structured Outputs → …
  • Rewriting a prompt that gives inconsistent output
  • SKILL.md covers When to Use This Skill, Core Capabilities, Quick Start and Detailed patterns and worked…, plus 3 more sections
  • Runs Python scripts from its folder

What it does

The skill covers six areas: few-shot learning with example selection by similarity or diversity, chain-of-thought prompting including zero-shot, few-shot and self-consistency variants, structured outputs with JSON mode and Pydantic schema enforcement, prompt optimization through iterative refinement and A/B tests, template systems with variable interpolation and modular parts, and system prompt design for role, format and safety.

A quick start shows a LangChain prompt template with Anthropic and Pydantic. The folder ships reference files for each topic, a prompt template library, a few-shot examples file and `scripts/optimize-prompt.py`, and deeper material lives in `references/details.md`. Use cases include debugging prompts with inconsistent output, cutting token use and building reusable templates for production applications.

When your agent uses it

  • Rewriting a prompt that gives inconsistent output
  • Designing few-shot examples with dynamic selection
  • Adding chain-of-thought or structured JSON output to a prompt
  • Building reusable prompt templates for an LLM application

Example prompts

  • “Improve this classification prompt so the output is consistent, and add few-shot examples.”
  • “Design a system prompt for a support assistant that always answers in JSON.”
  • “Turn these three hard-coded prompts into one template with variables.”

Workflow steps

6 steps, taken from the step headings in SKILL.md.

  1. Few-Shot Learning
  2. Chain-of-Thought Prompting
  3. Structured Outputs
  4. Prompt Optimization
  5. Template Systems
  6. System Prompt Design

What it can do on your machine

Read from SKILL.md and the folder at commit 46891e7. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Ships 1 file in scripts/ (Python), which the agent can run.

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Prompt Engineering Patterns loads about 1.3k tokens when it runs, and up to ~16k if it reads all its reference files. Until then it costs about 90 tokens; SKILL.md has 439 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~90
When it runs · the whole SKILL.md, loaded when a task matches
~1.3k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~16k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); the scripts in this folder are not scanned.

SKILL.md

The full file from wshobson/agents at commit 46891e7, republished under its MIT licence (© wshobson). 439 words, ~1,304 tokens.

Download SKILL.mdSave it as .claude/skills/prompt-engineering-patterns/SKILL.md (or your agent's skills folder). This skill also uses 9 other files; get the full folder from GitHub.
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)
  • 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

python
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.

Show full SKILL.md (178 more words)Show less

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

© wshobson, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 9 other files (scripts, references, assets) in plugins/llm-application-dev/skills/prompt-engineering-patterns of wshobson/agents.

  • SKILL.md
  • assets/few-shot-examples.json
  • assets/prompt-template-library.md
  • references/chain-of-thought.md
  • references/details.md
  • references/few-shot-learning.md
  • references/prompt-optimization.md
  • references/prompt-templates.md
  • references/system-prompts.md
  • scripts/optimize-prompt.py

Open the folder on GitHubat commit 46891e7

Compare with similar skills

Prompt Engineering Patterns next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Prompt Engineering Patterns compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Prompt Engineering Patterns this skillwshobson/agents40k—~1.3kAutomated safety check: PassMIT
Langchain Middlewarelangchain-ai/langchain-skills1.3k—~2.7kAutomated safety check: PassMIT
Building Pydantic AI Agentsdocling-project/docling69k—~2.8kAutomated safety check: PassMIT
Claude Cookbooks Reference2025Emma/vibe-coding-cn23k1 repos~2.2kAutomated safety check: PassMIT
Kayba Stage 2 Domain Contextkayba-ai/agentic-context-engine2.6k—~1.9kAutomated safety check: PassApache-2.0
Outlines Structured GenerationOrchestra-Research/AI-Research-SKILLs13k9 repos~4kAutomated safety check: PassMIT

Similar skills

  • Langchain Middleware

    langchain-ai/langchain-skills

    Official

    INVOKE THIS SKILL when you need human-in-the-loop approval, custom middleware, or structured output.

    1.3k GitHub stars~2.7k tokensUpdated today
    AI & LLM EngineeringAuto-check passed
  • Building Pydantic AI Agents

    docling-project/docling

    Patterns and tested examples for building agents with Pydantic AI: tools, capabilities, structured output, dependency injection, hooks, YAML specs, streaming and testing.

    69k GitHub stars~2.8k tokensUpdated today
    AI & LLM EngineeringAuto-check passed
  • Claude Cookbooks Reference

    2025Emma/vibe-coding-cn

    Reference of Claude API examples and guides covering tool use, vision, RAG, classification, summarization, text-to-SQL, prompt caching and agent patterns.

    23k GitHub starsUsed in 1 repo~2.2k tokens
    AI & LLM EngineeringAuto-check passed
  • Kayba Stage 2 Domain Context

    kayba-ai/agentic-context-engine

    Gather domain context about the repository and agent — system prompt, tool definitions, domain docs, and behavior patterns from traces.

    2.6k GitHub stars~1.9k tokensUpdated 15 days ago
    AI & LLM EngineeringAuto-check passed
  • Outlines Structured Generation

    Orchestra-Research/AI-Research-SKILLs

    Uses the Outlines library to constrain model output to a JSON schema, Pydantic model, regex or fixed set of choices when running local models.

    13k GitHub starsUsed in 9 repos~4k tokens
    AI & LLM EngineeringAuto-check passed
  • Lintlang

    hermes-labs-ai/lintlang

    A skill your agent uses when writing or reviewing AI agent configs, system prompts, or tool definitions (JSON/YAML/Python) and you need to catch ambiguous tool descriptions, missing stop conditions…

    138 GitHub stars~719 tokensUpdated today
    AI & LLM EngineeringAuto-check passed

More from wshobson/agents

All 142 skills in this repo
  • Cuts cloud spend across AWS, Azure, GCP and OCI with cost tagging, rightsizing, commitment and spot pricing models, and architecture changes.

    40k GitHub starsUsed in 14 repos~1.7k tokens
    Auto-check passed
  • Billing Automation

    wshobson/agents

    Covers building subscription billing: billing cycles, subscription states, invoice generation, proration, tax handling and dunning for failed payments.

    40k GitHub starsUsed in 13 repos~473 tokens
    Auto-check passed
  • Profiles slow Python code with cProfile and memory profilers, then applies targeted fixes for CPU, memory, I/O and query bottlenecks.

    40k GitHub starsUsed in 13 repos~814 tokens
    Auto-check passed
  • Writes unit tests for shell scripts with Bats: error-condition tests, fixtures and mocks, cross-shell checks, parallel runs, helper files and CI integration.

    40k GitHub starsUsed in 12 repos~1.3k tokens
    Auto-check passed
  • Distributed Tracing

    wshobson/agents

    Implement distributed tracing with Jaeger and Tempo to track requests across microservices and identify performance bottlenecks.

    40k GitHub starsUsed in 12 repos~527 tokens
    Auto-check passed
  • Sets up GitOps continuous delivery for Kubernetes with ArgoCD or Flux, covering installation, repository layout, sync policies, progressive delivery and secrets.

    40k GitHub starsUsed in 12 repos~1.5k tokens
    Auto-check passed

Questions about Prompt Engineering Patterns

What does Prompt Engineering Patterns do?

Reference for designing and tuning production LLM prompts: few-shot examples, chain-of-thought, structured outputs, templates and system prompts. The skill covers six areas: few-shot learning with example selection by similarity or diversity, chain-of-thought prompting including zero-shot, few-shot and self-consistency variants, structured outputs with JSON mode and Pydantic schema enforcement, prompt optimization through iterative refinement and A/B tests, template systems with variable interpolation and modular parts, and system prompt design for role, format and safety.

When should I use Prompt Engineering Patterns?

Prompt Engineering Patterns fits situations like: rewriting a prompt that gives inconsistent output; designing few-shot examples with dynamic selection; adding chain-of-thought or structured JSON output to a prompt; building reusable prompt templates for an LLM application.

How do I install Prompt Engineering Patterns in Claude Code?

Run `npx skills add wshobson/agents --skill prompt-engineering-patterns -a claude-code`. Or copy the skill folder (plugins/llm-application-dev/skills/prompt-engineering-patterns in wshobson/agents) into .claude/skills/prompt-engineering-patterns in your project. Claude Code loads it when a task matches its description.

How do I install Prompt Engineering Patterns in Codex?

Run `npx skills add wshobson/agents --skill prompt-engineering-patterns -a codex`. Or copy the skill folder (plugins/llm-application-dev/skills/prompt-engineering-patterns in wshobson/agents) into .agents/skills/prompt-engineering-patterns in your project. Codex loads it when a task matches its description.

Can I use Prompt Engineering Patterns in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add wshobson/agents --skill prompt-engineering-patterns -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/prompt-engineering-patterns, .gemini/skills/prompt-engineering-patterns, .github/skills/prompt-engineering-patterns and .opencode/skills/prompt-engineering-patterns in your project.

What does Prompt Engineering Patterns need to run?

Going by SKILL.md and its folder, Prompt Engineering Patterns needs Python for the scripts in its folder.

Does Prompt Engineering Patterns access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Prompt Engineering Patterns safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. The check reads SKILL.md only: the scripts in the folder are not scanned, so read them before running anything.

What licence does Prompt Engineering Patterns use?

Prompt Engineering Patterns is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Prompt Engineering Patterns use?

About 1.3k tokens (SKILL.md is roughly 5.2k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 15k tokens, read only when the agent opens those files.

What are the alternatives to Prompt Engineering Patterns?

Skills that share tags, products or a category with Prompt Engineering Patterns: Langchain Middleware (langchain-ai/langchain-skills, 1.3k stars), Building Pydantic AI Agents (docling-project/docling, 69k stars), Claude Cookbooks Reference (2025Emma/vibe-coding-cn, 23k stars) and Kayba Stage 2 Domain Context (kayba-ai/agentic-context-engine, 2.6k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Prompt Engineering Patterns?

wshobson (a GitHub user) maintains it in wshobson/agents, which has 40,305 GitHub stars. The repository holds 142 skills in this directory. The repository was last updated on October 5, 2026.

Source: wshobson/agents on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.