
Prompt Engineering Patterns
Improve production LLM prompts with few-shot, chain-of-thought, templates, and structured outputs when agent answers are inconsistent.
Overview
Prompt Engineering Patterns is a journey-wide agent skill that maximizes LLM performance and controllability—usable whenever a solo builder needs to design or refine production prompts before shipping AI features.
Install
npx skills add https://github.com/wshobson/agents --skill prompt-engineering-patternsWhat is this skill?
- Few-shot learning with semantic similarity and diversity sampling under context limits
- Chain-of-thought: zero-shot, few-shot traces, and self-consistency sampling
- Reusable templates with variable interpolation and JSON-mode structured outputs
- Debugging inconsistent outputs and production system-prompt design
- 8 explicit When-to-Use trigger scenarios in SKILL.md
- 4 core capability areas: few-shot, CoT, templates/debugging, structured outputs
Adoption & trust: 15.2k installs on skills.sh; 36.5k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
Your LLM prompts work in demo but fail in production with inconsistent reasoning, parsing errors, or wasted context.
Who is it for?
Indie builders optimizing agent workflows, copilots, or batch LLM pipelines who need repeatable prompt architecture.
Skip if: One-off casual chat with no production surface, or teams that only need basic single-shot prompts without parsing guarantees.
When should I use this skill?
Optimizing prompts, improving LLM outputs, designing production prompt templates, or implementing structured reasoning and JSON-mode parsing.
What do I get? / Deliverables
You apply structured patterns—few-shot, CoT, templates, JSON mode—to steadier outputs and faster prompt iteration.
- Production prompt templates with variable slots
- Reasoning and few-shot patterns documented for target tasks
- Structured output schemas aligned to parsers
Recommended Skills
Journey fit
Useful at every journey phase - explore requirements and options before committing to a direction.
Where it fits
Design system prompts and JSON schemas for a Codex or Claude Code tool loop.
Stabilize eval prompts with self-consistency before release gates.
Tune assistant phrasing for AI-search and in-product help without hallucination drift.
Scale few-shot examples for lifecycle emails or support draft generation.
Prototype prompt templates to judge feasibility before full agent build.
How it compares
Pattern library for prompt design—not a model host, fine-tuning guide, or RAG ingestion skill.
Common Questions / FAQ
Who is prompt-engineering-patterns for?
Solo and small-team developers building agentic or LLM-backed products who own prompt quality in Claude Code, Cursor, or similar environments.
When should I use prompt-engineering-patterns?
During Build when designing agent-tooling prompts; during Ship when debugging flaky test or review prompts; during Launch/Grow when tuning user-facing assistants; whenever optimizing prompts or structured outputs for production.
Is prompt-engineering-patterns safe to install?
It is documentation-style procedural knowledge; check Security Audits on this Prism page for the package source and avoid embedding secrets in prompt templates.
SKILL.md
READMESKILL.md - Prompt Engineering Patterns
# 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-4-6") 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) ``` ## Key Patterns ### Pattern 1: Structured Output with Pydantic ```python from anthropic import Anthropic from pydantic import BaseModel, Field from typing import Literal import json class SentimentAnalysis(BaseModel): sentiment: Literal["positive", "negative", "neutral"] confidence: float = Field(ge=0, le=1) key_phrases: list[str] reasoning: str async def analyze_sentiment(text: str) -> SentimentAnalysis: """Analyze sentiment with structured output.""" client = Anthr