Category 1: Foundational Patterns
Prompt patterns are reusable templates for common AI tasks. Mastering 15 core patterns covers 90% of real-world use cases. Each pattern includes a purpose, template, beginner example, advanced example, and common mistake to avoid.
You know the basics of prompt engineering. Now it is time to build a pattern library — reusable templates you can apply to any task. This article covers 15 essential patterns organized into four categories, each with a purpose, template, beginner and advanced examples, and the most common mistake.
This is a companion to our Prompt Engineering Complete Tutorial. If you are new to prompting, start there. This article assumes you understand the fundamentals.
Table of Contents
- Category 1: Foundational Patterns
- Category 2: Multi-Step Patterns
- Category 3: Task-Specific Patterns
- Category 4: Quality Patterns
- Pattern Chaining
- When to Use Which Pattern
- FAQ
- Conclusion
Category 1: Foundational Patterns
These five patterns are the building blocks. Almost every effective prompt uses at least one.
Pattern 1: Role + Task + Context
Template: "You are a [ROLE]. TASK: [WHAT]. CONTEXT: [BACKGROUND]."
ADVANCED: "You are a senior security engineer reviewing a Flask API for OWASP Top 10 vulnerabilities. Focus on SQL injection and XSS. Return findings as JSON."
Pattern 2: Few-Shot
Template: "EXAMPLES:\nInput: [E1] → Output: [O1]\nInput: [E2] → Output: [O2]\nNOW: Input: [ACTUAL]"
ADVANCED: "Code review severity:\n'Unused import' → LOW\n'Missing validation on user_id' → HIGH\n'SQL injection vulnerability' → CRITICAL\n'No rate limiting on login' → ?"
Pattern 3: Zero-Shot
Template: "[Clear instruction about what to do]"
ADVANCED: "Analyze this Python code for performance bottlenecks. For each: location (line number), impact (H/M/L), and optimization suggestion."
Pattern 4: Structured Output
Template: "Return as [FORMAT]: [FIELD LIST]"
ADVANCED: "Return as JSON with keys: {severity, location, description, fix, confidence}. One object per finding. Array of findings."
Pattern 5: Delimiters
Template: "Analyze the following:\n--- BEGIN ---\n[CONTENT]\n--- END ---"
ADVANCED: "Review this code for security:\n```\n[CODE]\n```\nIgnore comments. Focus on input validation and SQL injection."
Category 2: Multi-Step Patterns
These patterns chain multiple steps to produce higher-quality output.
Pattern 6: Critic Pattern
Template: "After generating, review for: [CRITERIA]. List issues, then provide corrected version."
ADVANCED: "Generate a REST API design for user management. Then review for: RESTful compliance, error handling, pagination, authentication. List issues numbered, then provide corrected design."
Pattern 7: Generator → Reviewer
Template: "STEP 1: Create [OUTPUT].\nSTEP 2: Review for [CRITERIA]. Provide final version."
ADVANCED: "Step 1: Design a database schema for an e-commerce platform with users, products, orders, and reviews.\nStep 2: Review for normalization (3NF), indexing strategy, and scalability. Provide final schema with SQL CREATE statements."
Pattern 8: Plan → Execute
Template: "PLAN: List steps.\nEXECUTE: Carry out each step.\nVERIFY: Check against requirements."
ADVANCED: "PLAN: Implement JWT authentication with refresh tokens.\nEXECUTE: Write middleware, login/logout routes, token refresh, and tests.\nVERIFY: Check token expiry, refresh flow, CSRF protection, and error handling."
Pattern 9: Extract → Transform → Validate
Template: "EXTRACT: Pull out [FIELDS].\nTRANSFORM: Convert to [FORMAT].\nVALIDATE: Check [RULES]."
ADVANCED: "EXTRACT: PII fields (name, email, phone, SSN) from this log entry.\nTRANSFORM: Replace with redacted format (name → [REDACTED]).\nVALIDATE: All PII removed, no original values in output, format preserved."
Category 3: Task-Specific Patterns
These patterns are optimized for common task types.
Pattern 10: Classification
Template: "Classify into [CATEGORIES].\nInput: [TEXT]\nOutput: category + confidence."
ADVANCED: "Classify this code review comment by type (bug, security, performance, style, docs) and severity (LOW/MEDIUM/HIGH/CRITICAL):\n'Missing rate limiting on login endpoint — allows brute force attacks'"
Pattern 11: Summarization
Template: "Summarize [LENGTH] for [AUDIENCE]. Preserve [KEY ELEMENTS]."
ADVANCED: "Summarize this 50-page research paper in 500 words for a data scientist. Preserve: methodology, key findings, limitations, and practical implications. Exclude: related work, proofs, and appendix."
Pattern 12: Comparison
Template: "Compare [A] vs [B] for [USE CASE]. Table with: Feature, A, B, Winner."
ADVANCED: "Compare PostgreSQL vs MongoDB for a real-time analytics platform processing 10M events/day. Table columns: scalability, query performance, schema flexibility, ACID compliance, operational cost, ecosystem. Include a recommendation with reasoning."
Pattern 13: Chain Decomposition
Template: "Break into [N] steps:\n1. [STEP 1]\n2. [STEP 2]\nFor each: explanation + example."
ADVANCED: "Break 'implement CI/CD pipeline' into: linting, unit testing, integration testing, security scanning, building, deploying. For each step: recommended tools, configuration example, and common pitfalls."
Category 4: Quality Patterns
These patterns ensure correctness and completeness.
Pattern 14: Verification
Template: "After generating, verify: [CHECKLIST]. Report any issues found."
ADVANCED: "Generate a SQL query to find users who logged in in the last 30 days. Then verify: uses indexed column, no N+1 queries, handles NULL last_login, no SQL injection (parameterized), correct date arithmetic."
Pattern 15: Role Rotation
Template: "As a [ROLE 1], analyze [ASPECT 1].\nAs a [ROLE 2], analyze [ASPECT 2].\nCombine insights."
ADVANCED: "As a security engineer, review for vulnerabilities. As a performance engineer, review for bottlenecks. As a code reviewer, review for maintainability. Combine all findings into a prioritized list."
Pattern Chaining
The real power comes from combining patterns. Here is how they chain together:
Example chain for code review:
- Role: "You are a senior Python developer"
- Delimiters: "Review this code: ```[CODE]```"
- Classification: "For each issue, classify as security/performance/style"
- Structured Output: "Return as JSON: {type, severity, line, description, fix}"
- Verification: "Verify your findings are accurate before presenting"
When to Use Which Pattern
| Task Type | Recommended Pattern | Why |
|---|---|---|
| Domain-specific question | Role + Task + Context | Sets expertise level |
| Categorization | Few-Shot + Classification | Examples teach the pattern |
| Code generation | Plan → Execute → Verify | Forces completeness |
| API/JSON output | Structured Output | Predictable format |
| Processing external text | Delimiters | Prevents instruction confusion |
| Quality improvement | Critic or Generator → Reviewer | Self-evaluation loop |
| Data processing | Extract → Transform → Validate | Three-stage pipeline |
| Decision-making | Comparison | Structured side-by-side |
| Complex project | Chain Decomposition | Breaks into manageable steps |
| Ensuring correctness | Verification | Forces self-checking |
FAQ
Which pattern should I use most often?
Can I combine multiple patterns?
When should I use Few-Shot vs Zero-Shot?
Does the Critic pattern actually improve output?
Try These BestWordz Tools
- Regex Tester — Practice pattern matching, analogous to prompt patterns
- JSON Formatter — Verify structured output from prompts
- All BestWordz Tools — Explore the complete tool library
Continue Learning
- Prompt Engineering Complete Tutorial — The foundational pillar article
- Context Engineering Explained — Beyond prompts: controlling AI behavior
- How AI Coding Agents Work — Patterns in agentic workflows
- Prompt Injection Explained — Security implications of prompting
- What Is an LLM? Beginner's Guide — Foundational concepts
- RAG Architecture Explained — Using patterns with retrieval systems
Try the JSON Formatter
Put what you've learned into practice with this free BestWordz tool.
💬 Discuss this topic
Have questions or insights about Category 1: Foundational Patterns? Join the BestWordz Community.
📚 Related Articles
Introduction
Computer programming is undergoing its most significant transformation since the invention of high-…
CybersecurityWhat Is Prompt Engineering?
Key Takeaway Prompt Engineering is the skill of communicating effectively with AI models. It is not…
CybersecurityThe 10-Stage CS Learning Roadmap
A computer science education in 2026 requires more than traditional coursework. Today's students ne…
CybersecurityFrom Prompt Crafting to System Design
Key Takeaway --> 🎯 Context engineering is the skill of designing what an AI system knows, s…
CybersecurityWhat Is Vibe Coding?
Software development is shifting from writing every line of code to defining goals, designing syste…
CybersecurityPrompt Engineering vs Context Engineering
Key Takeaway Prompt engineering controls what you ask. Context engineering controls what the model …
🔧 Related Tools
Password Strength Checker
Analyze password strength, entropy, and common weaknesses - entirely in your browser.
Try it now →Regex Tester
Test regular expressions live: matches with positions, capture groups, and flag validation.
Try it now →Diffie-Hellman Demo
Educational demonstration of classic Diffie-Hellman key exchange.
Try it now →JSON Formatter
Pretty-print or minify any JSON document instantly, with clear line/column error reporting.
Try it now →💬 Discuss on BestWordz Community
Join the conversation about Python, JavaScript, Docker on the BestWordz Community forum.
Visit Forum →