Prompt Engineering
A practical, interactive reference for crafting precise, context-aware, and iteratively refined prompts.
Master the art of prompt engineering β from choosing the right prompt type, to layering context, to diagnosing and fixing failure modes. Whether you're building AI agents, writing system prompts, or refining ad-hoc queries, these patterns will sharpen every interaction.
The 6 Layers of a Production Prompt
Full Layered Prompt Example
[PERSONA] You are a senior product manager with 10 years in B2B SaaS.
[TASK] Review the feature brief below and identify gaps.
[DOMAIN] Focus on enterprise security and compliance requirements.
[AUDIENCE] Output is for the engineering team lead.
[FORMAT] Bullet list: gap Β· why it matters Β· suggested resolution.
[CONSTRAINT] Max 8 bullets. Flag only P0 and P1 issues.
<brief>[paste brief here]</brief>Effect of Recurring Context on Model Behavior
| Metric | With Recurring Context | Without Context |
|---|---|---|
| Response relevance | High | Variable |
| Hallucination risk | Low | Elevated |
| Follow-up friction | Minimal | High |
| Consistency across turns | Strong | Fragile |
Write the simplest version that states the goal. Don't over-engineer first. Run it and capture the raw output.
Tag each problem: wrong format, wrong depth, wrong tone, missing info, hallucination, or scope creep. One diagnosis per problem.
Add a format spec, a role, an example, or a constraint β but only one. This tells you exactly what worked.
Run the revised prompt on at least 3 different real inputs. A prompt that works for one case but breaks on edge cases isn't done.
If the model keeps producing something wrong, show what you don't want alongside what you do. Negative examples anchor the boundary.
Save the prompt with version, purpose, example I/O, and known limitations. Treat it like code β it needs a changelog.
-
Output is prose when you needed structured data, or JSON when you needed plain text
Specify a formal schema or wrap target outputs in custom tags (e.g., [FORMAT] or <json>). Provide a 1-shot example.
-
Response misses the target expertise level β either over-simplifying or over-explaining details
Explicitly declare the AUDIENCE layer (e.g., 'expert developer') and specify a strict length/paragraph constraint.
-
Model wanders into tangential topics, outputs commentary, or over-generates beyond the task
Add negative constraints and boundary triggers: 'Only focus on X. Do not write a preamble or introduction.'
-
Technically correct but too vague, using clichΓ©s and generic guidance instead of domain-specific solutions
Supply a detailed DOMAIN rule or TECHNICAL STATE block, and assign an authoritative expert PERSONA.
-
Model invents facts, APIs, parameters, or citations when generating answers or reading files
Strictly ground the model: 'Answer using only the provided context. If the answer is not present, reply with "UNKNOWN".'
-
Model repeats instructions, restates its own points, or gets stuck in cyclical phrasing loops
Enforce positive framing constraint: 'Ensure each sentence introduces new, non-overlapping information.'
-
Model mixes up user input/data with instructions, or ignores rules due to prompt injection
Use XML tags (e.g., <data>...</data>) to isolate inputs from instructions, and explicitly tell the model not to execute commands inside the data.
-
Model outputs an incorrect final answer immediately, skipping critical intermediate reasoning steps
Request structured reasoning first (Chain-of-Thought). Use a <reasoning> block to isolate logic before the final output.
1. Select Prompt Type
Select a scenario to find the recommended prompt type:
2. Build Your Layered Prompt
Live Layered Prompt Preview
Interactive Tools
Practical tools to help you think systematically, build better AI agents, and master prompt engineering.
Problem Solver
A structured thinking space to go from raw problem β root cause β ideas β architecture decisions β concrete build plan.
Problem Statement Builder
Define what you want to build in 5 steps β then generate a ready-to-use AI coding prompt.
AI Agent Skills Builder
Design custom AI agent skills based on best practices from Claude, Gemini, OpenAI, and GitHub Copilot.
Enterprise Pattern
Design and visualize cognitive patterns for enterprise AI agents.
Trip Planner
Design a 6-phase, multi-agent AI pipeline for planning a comprehensive family trip.
Software Engineering Playbooks
Practical, End-to-End implementation guides for building Production-ready Software. Each playbook includes working code, architecture diagrams, and step-by-step instructions.
Research Agent with Gateway
Build a production-ready AI research agent using Agent Gateway for unified traffic management, authentication, and observability across LLM providers.
RAG Pipeline with Vector Database
Implement a complete Retrieval-Augmented Generation pipeline with vector embeddings, semantic search, and context injection for accurate AI responses.
Multi-Agent Orchestration
Create a coordinated multi-agent system with specialized agents, task distribution, and result synthesis for complex problem-solving.
Future References
Explore these resources for deeper learning on AI agent development, spec-driven development, and prompt engineering tools.
Spec-Driven Development
Comprehensive guide on Spec-Driven Development practices and methodologies.
Awesome Copilot
Curated list of GitHub Copilot resources, extensions, and best practices.
Promptfoo
Tool for testing, evaluating, and improving LLM prompts and applications.
Prompts.chat
Collection of prompt engineering resources and templates.
Agent Skills
Agent skills resources and documentation for building AI agent skills.
Awesome Skills
Curated list of awesome skill repositories and collections.
Agent Skills Topic
GitHub topic for discovering agent-related skills and repositories.
AI Agent Topic
Trendshift topic for discovering AI agents.
AI Skills Topic
Trendshift topic for discovering AI skills.
Agent Governance Toolkit
Agent governance toolkit.
Pattern Sources
Our patterns are curated from industry-leading sources with proper attribution and licensing compliance.
Refactoring.Guru
Classic GoF design patterns, code smells catalog, and refactoring techniques (https://refactoring.guru).
Enterprise Integration Patterns
65 messaging patterns for integrating enterprise applications by Gregor Hohpe and Bobby Woolf (CC BY 4.0).
Microservices.io
Comprehensive patterns for microservice architectures by Chris Richardson.
Agent Catalog Patterns
Patterns for agentic systems from agentpatternscatalog.org (CC BY 4.0).
OWASP Foundation
Security patterns from OWASP Top 10 for Web Applications, LLM Applications, and Agentic Applications (CC BY-SA 4.0).
Industry Research
ML/AI patterns from Microsoft, Google, Anthropic, and academic research.
AI Agent Patterns
Spec-driven development patterns from Claude, Gemini, OpenAI, and GitHub Copilot on github/spec-kit and OpenSpec.
Data Engineering Leaders
Data platform patterns from Martin Fowler (Data Mesh), Kimball Group (Dimensional Modeling), and cloud providers.
MLOps Best Practices
Data science patterns from MLflow, Great Expectations, and MLOps practitioners.
Streaming & Analytics
Real-time patterns from Confluent/Kafka, Apache projects, and serverless analytics platforms.
Academic Papers
Rigorous ML patterns from peer-reviewed research including data leakage prevention and active learning.
5-Day AI Agents Course
Intensive Vibe Coding Course With Google by Brenda Flynn et al. (2026) on Kaggle.
The Agent Loop
Foundational Agent Definition (Perceive + Act):
Russell, S. J., & Norvig, P. (1995). Artificial Intelligence: A Modern Approach. Prentice Hall. (Current edition: 4th Ed., Pearson, 2020)
Modern Iterative LLM Agent Loop:
Yao, S., Zhao, J., Yu, D., et al. (2022). ReAct: Synergizing Reasoning and Acting in Language Models. arXiv:2210.03629.
Historical Context:
Incorporating AIMA's perceive/act model, Classical robotics' Sense-Plan-Act loop (Brooks, 1986), and ReAct's ThoughtβActionβObservation cycle.