Prompt Patterns and Templates
Why Patterns Matter
When you are building AI-powered products and workflows, you will find yourself writing similar types of prompts over and over. A customer support system needs to classify emails. A content tool needs to rewrite text in a specific tone. A data pipeline needs to extract structured information from unstructured documents.
Prompt patterns are reusable templates and structural strategies that solve these recurring problems reliably. Learning them is like learning design patterns in software engineering -- once you know them, you can apply them quickly and confidently across different projects.
Pattern 1: The Persona Pattern
What it does: Assigns the model a specific expert role to improve the relevance and quality of its outputs.
Structure:
You are [specific expert role with relevant context].
[Task or question]
Example: "You are a senior cybersecurity analyst with 15 years of experience in enterprise security. You communicate complex technical risks in plain language for non-technical executives. Review the following incident report and summarise the business impact in three bullet points."
Why it works: The persona pattern activates relevant knowledge, sets the appropriate communication style, and anchors the model's perspective. A cybersecurity analyst will give a different (and more useful) response than a generic assistant.
When to use it: Whenever you need domain-specific expertise, a particular communication style, or a professional perspective.
Pattern 2: The Output Specification Pattern
What it does: Defines exactly what format, structure, and constraints the output must follow.
Structure:
[Task]
Respond in the following format:
[Exact format specification]
Example: "Extract the key information from the following job posting. Respond in JSON format with these exact fields:
- job_title (string)
- company (string)
- location (string)
- salary_range (string or null)
- required_skills (array of strings)
- experience_level (one of: junior, mid, senior, not_specified)
Return only the JSON object. No additional text."
Why it works: When you explicitly define the output format, the model does not have to guess what you want. This is essential for production systems where the output feeds into downstream code that expects a specific structure.
When to use it: Any time the output will be parsed by code, stored in a database, or used in a structured workflow.
Pattern 3: The Instruction Decomposition Pattern
What it does: Breaks a complex multi-step task into numbered instructions the model follows sequentially.
Structure:
Complete the following task by following these steps in order:
1. [Step 1]
2. [Step 2]
3. [Step 3]
[Input]
Example: "Analyse the following customer feedback and complete these steps in order:
- Identify the main complaint or compliment in one sentence.
- Rate the overall sentiment as Positive, Negative, or Mixed.
- Identify any specific product features mentioned.
- Suggest one concrete action the product team should take based on this feedback.
Customer feedback: 'I love how fast the checkout process is, but the cart keeps losing my items when I leave the browser. I have abandoned my purchase twice because of this.'"
Why it works: Multi-step instructions prevent the model from conflating steps, skipping steps, or prioritising the wrong part of the task. Each numbered step becomes a clear checkpoint.
When to use it: Document analysis, content generation pipelines, code review workflows, or any task with multiple distinct phases.
Pattern 4: The Constraint Pattern
What it does: Sets explicit boundaries on what the model can and cannot do.
Structure:
[Role and context]
[Task]
Constraints:
- [Constraint 1]
- [Constraint 2]
- [Constraint 3]
Example: "You are a customer support assistant for HealthTrack, a fitness app. Answer the customer's question based only on the information in the knowledge base provided. Constraints:
- Do not speculate or invent information not in the knowledge base.
- Do not discuss competitor products.
- If the answer is not in the knowledge base, say 'I do not have that information -- please contact our support team at support@healthtrack.com.'
- Keep all responses under 100 words.
- Always end with 'Is there anything else I can help you with?'"
Why it works: Constraints prevent the model from drifting outside the boundaries appropriate for your use case. This is critical for customer-facing AI where consistency and accuracy are non-negotiable.
When to use it: Customer-facing applications, compliance-sensitive environments, brand voice enforcement, or any system where specific guardrails are required.
Pattern 5: The Template Fill Pattern
What it does: Provides a template with placeholders that the model fills in based on input data.
Structure:
Using the following information, fill in this template exactly:
[Template with {{PLACEHOLDER}} markers]
Information:
[Input data]
Example: "Using the following candidate information, fill in this email template exactly. Replace each placeholder with the relevant information. Do not change any other text.
Template:
Dear {{CANDIDATE_NAME}},
Thank you for applying for the {{JOB_TITLE}} role at {{COMPANY_NAME}}. We reviewed your application and are pleased to invite you to an interview on {{INTERVIEW_DATE}} at {{INTERVIEW_TIME}}.
Please confirm your availability by replying to this email.
Best regards, The {{COMPANY_NAME}} Recruitment Team
Information: Candidate: Sarah Okonkwo Role: Senior Data Analyst Company: NovaPay Interview date: Tuesday 5 September Time: 10:00 AM WAT"
Why it works: Template filling is one of the most reliable uses of LLMs. The model only has to identify the right value for each placeholder -- it does not have to make structural decisions.
When to use it: Email generation, document drafting, report generation, any workflow that produces documents from a standard template.
Pattern 6: The Reflection Pattern
What it does: Asks the model to review and critique its own output before finalising it.
Structure:
[Task]
After writing your response, review it against these criteria:
- [Criterion 1]
- [Criterion 2]
If your response does not meet these criteria, revise it.
Example: "Write a product description for these wireless headphones. After writing it, review it against these criteria:
- Does it mention the three key features: 40-hour battery, active noise cancellation, and multipoint pairing?
- Is it under 80 words?
- Does it use engaging, benefit-focused language rather than dry technical specs? If any criterion is not met, revise the description."
Why it works: By asking the model to self-review, you add a quality control step without needing to run a second API call with a separate reviewer prompt. The model catches many of its own omissions and errors.
When to use it: Content generation, long-form writing, any task where you need the model to self-check quality.
Building a Prompt Template Library
As you build more AI systems, maintain a library of reusable prompt templates. Organise them by:
- Task type (classification, extraction, generation, summarisation)
- Domain (customer support, legal, sales, HR)
- Output format (JSON, markdown, plain text, bullets)
Version your templates using a naming convention like v1_customer_classify_prompt.txt and track changes as you refine them. Teams that maintain good prompt libraries move significantly faster when building new AI features.
Practice Exercise
Combine two or more patterns to write a prompt that:
- Assigns the persona of a professional financial advisor
- Specifies JSON output format
- Sets constraints (no speculation, flag if information is missing)
Task: Extract structured information from a loan application description.
Key Takeaways
- Prompt patterns are reusable structural strategies that solve recurring prompt engineering challenges.
- The six core patterns are: Persona, Output Specification, Instruction Decomposition, Constraint, Template Fill, and Reflection.
- Combining multiple patterns in a single prompt (persona + output specification + constraints) is common in production systems.
- Maintaining a prompt template library speeds up AI development across projects.
- Output specification patterns are essential when AI outputs will be parsed by code or stored in structured databases.
Try it yourself
Key Takeaways
- Prompt patterns are reusable structural strategies that solve recurring prompt engineering challenges reliably.
- The six core patterns -- Persona, Output Specification, Instruction Decomposition, Constraint, Template Fill, and Reflection -- cover most production AI use cases.
- Combining patterns in a single prompt (such as persona + output specification + constraints) is standard practice in production systems.
- The Output Specification Pattern is essential whenever AI output will be parsed by code or stored in a structured database.
- Maintaining a versioned prompt template library is a professional practice that accelerates AI development across projects.
Quick Quiz
1.What is the purpose of the Output Specification Pattern?
2.Why is the Constraint Pattern particularly important for customer-facing AI applications?
3.What does the Reflection Pattern ask the model to do?
4.Why should AI teams maintain a prompt template library?
Ready to go further?
CareerEx gives you structured 12-week training, live classes every Saturday and Sunday, real tutor feedback, and a certificate. Join the next cohort.
Join CareerEx