Skip to content

Sayemnyc/prompt-engineering-patterns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Prompt Engineering Patterns

Patterns License PRs Welcome Maintained

A practitioner's reference for building reliable, production-grade AI systems with LLMs.

Every pattern shows what breaks, what fixes it, and why.


🎯 Why This Exists

Most prompt engineering guides are either academic (useless) or a list of tricks (forgettable). This repo is different: it's 20 patterns I've used in production, each documented with a real failure, a real fix, and the mechanics behind why the fix works.

If you're evaluating AI engineers or building AI products, this repo answers the question: "Does this person actually understand how LLMs work, or are they just vibing with ChatGPT?"


πŸ“š Table of Contents

🧱 Foundational

Control the basics: reasoning, format, tone

# Pattern Description
πŸ”— Chain-of-Thought Force reasoning before conclusions
🎯 Few-Shot Examples Set quality bar with 2-3 examples
🎭 Role Assignment Activate domain expertise with a persona
πŸ“‹ Output Formatting Lock structure for parseable outputs
πŸͺœ Step-by-Step Decomposition Break complex tasks into subtasks

⚑ Intermediate

Handle complexity: edge cases, reliability

# Pattern Description
πŸ”„ Self-Consistency Checking Multi-framework analysis with synthesis
🚧 Constraint Setting Guardrails on length, scope, and tone
🚫 Negative Examples Show what NOT to do, with annotations
πŸ“ Context Window Management Fight the "lost in the middle" problem
🌑️ Temperature & Sampling Match randomness to task type

πŸ”¬ Advanced

Build systems: architecture, safety, scale

# Pattern Description
πŸ—οΈ System Prompt Architecture Multi-section system prompts that hold up
πŸ›‘οΈ Adversarial Guardrails Defense-in-depth against prompt injection
βœ… Chain of Verification Self-checking for factual accuracy
⛓️ Prompt Chaining Pipelines Multi-stage pipelines with code logic
🎲 Dynamic Few-Shot Selection Programmatic example retrieval

🏭 Production

Ship and maintain: monitoring, ops, rollback

# Pattern Description
πŸ“Š Evaluation-Driven Iteration Replace gut-feel with systematic scoring
πŸ§ͺ Regression Testing CI/CD for prompts
πŸ”€ Multi-Model Routing Right model for the right task
πŸ”„ Graceful Degradation Fallback hierarchy when AI fails
πŸ“¦ Prompt Versioning Track, compare, roll back like code

πŸš€ Quick Start

Tip

Short on time? Start with these three patterns. They're the highest-leverage for most real-world problems:

  1. πŸ—οΈ System Prompt Architecture (#11) β€” The difference between a demo and a product.
  2. πŸ“Š Evaluation-Driven Iteration (#16) β€” Stop tuning prompts by feel.
  3. πŸ›‘οΈ Adversarial Guardrails (#12) β€” What separates "shipping" from "shipping safely."

For a scannable one-pager, see CHEATSHEET.md. For full end-to-end system designs, see USE-CASES.md.


πŸ”¬ Before / After: What Good Prompt Engineering Looks Like

Every pattern in this repo follows this format. Here's a preview of the shape of the problem:

Caution

❌ Naive Prompt

Analyze this candidate's resume and tell me if they're a good fit
for our Senior ML Engineer role.

What breaks: Vague "yes" or "no" with surface-level reasoning. Pattern-matches on keyword overlap rather than evaluating fit signals. The output feels like a coin flip with extra words. Ask this same prompt 5 times β€” you'll get 5 different answers, each confidently wrong in its own way.

Note

βœ… Engineered Prompt

You are a senior technical recruiter evaluating ML Engineer
candidates. Analyze this candidate step by step:

1. SKILLS MATCH: List each required skill. For each, note whether
   the resume demonstrates it and at what level. Cite evidence.
2. EXPERIENCE DEPTH: Years of relevant experience, scale of
   systems built, progression of responsibility.
3. GAPS: Hard gaps (missing must-haves) vs. soft gaps (nice-to-haves).
4. CULTURE SIGNALS: Collaboration, communication, leadership
   indicators from project descriptions.
5. FINAL ASSESSMENT: Based ONLY on steps 1-4, provide a fit score
   (1-10) with your top concern and top strength.

Why it works: Chain-of-thought forces the model to generate reasoning tokens that become context for the conclusion. Explicit anchoring ("Based ONLY on steps 1-4") prevents the model from contradicting its own analysis. See full breakdown in Pattern #1.


🎬 Use Case Gallery

Five end-to-end system designs showing how patterns combine. Each pulls from real work I've done in career coaching, restaurant operations, and AI SaaS.

πŸ“„

Resume Generation Pipeline

5-stage pipeline combining extraction, analysis, and verification. Prevents fabricated experience.

🍽️

Restaurant Operations Analysis

Weekly reports for multi-location restaurant groups. Context management + self-consistency.

🎯

Job Board Scraping & Matching

Adversarial-safe scraping pipeline with dynamic few-shot matching against user profiles.

🚨

Content Moderation System

Guardrails-first classifier with layered defense and human-in-the-loop for uncertainty.

πŸ’¬

SaaS Customer Support Bot

Handles 70% of tickets autonomously with multi-model routing and graceful degradation.

πŸ§ͺ

Meta-Lessons

Patterns production AI systems share β€” and why single-pattern solutions don't work in the real world.


πŸ—οΈ Pattern Hierarchy

Pattern hierarchy showing how the four categories build on each other

The four categories aren't independent β€” each builds on the previous. You won't get much from Prompt Versioning (#20) if you haven't mastered System Prompt Architecture (#11), and Chain of Verification (#13) assumes you already know Chain-of-Thought (#1).

Progress through the tiers as your systems grow in complexity. Most indie projects need only Foundational + Intermediate. Production apps need Advanced. Anything serving real users at scale needs Production.


πŸ“– How Each Pattern Is Structured

Every pattern file in this repo follows the same template so you can scan quickly:

# Pattern Name
Category Β· Difficulty Β· Impact

## When To Use          ← Decide if this applies to your problem
## The Problem          ← Naive prompt + what goes wrong + why
## The Pattern          ← Engineered prompt with inline explanations
## Why It Works         ← Model mechanics and underlying theory
## Real-World Example   ← Concrete scenario from career/restaurant/SaaS
## Common Mistakes      ← 2-3 pitfalls people hit in practice
## Related Patterns     ← Which other patterns complement this one

Read one top-to-bottom. Then use the rest as a reference.


🎨 Color Coding

Across all visuals, categories use consistent colors:

Category Color Hex
🧱 Foundational 🟦 Blue #3B82F6
⚑ Intermediate 🟧 Amber #F59E0B
πŸ”¬ Advanced πŸŸͺ Purple #8B5CF6
🏭 Production 🟩 Green #10B981

🀝 Contributing

Found a pattern that's missing? Spotted a case where my engineered prompt fails? PRs welcome. The bar for new patterns is high:

  1. Real problem: Document an actual failure mode, not a hypothetical.
  2. Real fix: Engineered prompt must be something you'd ship.
  3. Real reasoning: Explain why it works, not just that it works.
  4. Fits the template: Follow the existing pattern file structure.

πŸ“¬ Author

Sayem Islam
Prompt Specialist & AI Evaluator

Building AI products and evaluating them for a living. Career pivoter (restaurant operations β†’ tech) who genuinely cares about why AI systems work or don't. This repo is the reference I wish existed when I started working with LLMs in production.

πŸ“§ hello@sayemislam.com
🌐 sayemislam.com
πŸ”— LinkedIn
🌐 mysecondact.io

⭐ If this helped you, star the repo. If it didn't, tell me why β€” I'll fix it.

Last updated: 2026 Β· MIT License Β· Built with attention to detail

About

A practitioner's reference: 20 production-tested prompt engineering patterns, each with naive vs engineered prompts, real-world examples, and the mechanics behind why they work.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors