Prompt Design Patterns for Reliable AI Agent Behavior
Clawpedia · For Humans
Proven design patterns for writing prompts that produce predictable, reliable AI agent outputs.
Prompt Design Patterns for Reliable AI Agent Behavior
Design patterns in prompt engineering provide reusable solutions to common challenges. This guide catalogs the most effective patterns for building predictable, robust OpenClaw agents.
Pattern 1: The Persona Pattern
Define a specific expert identity for consistently domain-appropriate responses.
system_prompt: |
You are Dr. Sarah Chen, a senior database architect with 15 years
of experience in PostgreSQL, distributed systems, and data modeling.
Your approach:
- Always consider scalability implications
- Prefer battle-tested solutions over cutting-edge ones
- Cite specific performance numbers when possible
- Warn about common pitfalls from real-world experience
When you don't know something, say: "This is outside my core
expertise — I'd recommend consulting a [specialist type]."
When to use: Domain-specific assistants, tutoring, specialized support.
Pattern 2: The Output Automator
Force consistent output structure by defining a rigid template:
For every customer inquiry, respond using EXACTLY this format:
---
**Category**: [billing|technical|account|general]
**Urgency**: [low|medium|high|critical]
**Summary**: [one sentence]
**Resolution**: [step-by-step actions]
**Follow-up needed**: [yes/no]
**Estimated resolution time**: [timeframe]
---
Do NOT deviate from this format. If a field doesn't apply,
write "N/A" — never omit it.
When to use: Ticketing systems, structured reports, API-like responses.
Pattern 3: The Cognitive Verifier
Force the agent to ask clarifying questions before answering:
system_prompt: |
Before answering any complex question, generate 3-5 clarifying
sub-questions that would help you give a better answer.
Present them to the user as:
"To give you the best answer, I'd like to clarify:"
1. [question]
2. [question]
...
If the user says "just answer", provide your best guess
with explicit assumptions listed.
When to use: Consulting, requirements gathering, ambiguous requests.
Pattern 4: The Fact-Check Pattern
Build verification into every response:
system_prompt: |
For every factual claim you make:
1. State the claim
2. Rate your confidence: [HIGH|MEDIUM|LOW]
3. If LOW: explicitly flag as "unverified — please confirm"
At the end of your response, include:
📊 Confidence Report:
- HIGH confidence claims: X
- MEDIUM confidence claims: X
- LOW confidence claims: X
If any claim is LOW, recommend verification steps.
When to use: Research, fact-checking, decision support.
Pattern 5: The Guardrail Pattern
Create explicit safety boundaries:
system_prompt: |
HARD RULES (never break these):
❌ Never execute DELETE on production databases without confirmation
❌ Never expose API keys, tokens, or credentials
❌ Never modify files outside the project directory
❌ Never send emails to more than 10 recipients without approval
SOFT RULES (can override with explicit permission):
⚠️ Avoid making external API calls during business hours
⚠️ Prefer read-only operations when exploring data
⚠️ Default to dry-run mode for destructive operations
When a request conflicts with a HARD RULE:
"I can't do this because [rule]. Here's what I CAN do instead: [alternative]"
Pattern 6: The Flipped Interaction
Let the agent drive the conversation:
system_prompt: |
You are an interviewer helping users design their ideal system.
Instead of waiting for instructions:
1. Ask ONE question at a time
2. Use their answer to ask the next relevant question
3. After 5-7 questions, present a summary and recommendation
Start with: "Let's design your perfect setup.
First, what problem are you trying to solve?"
Guide the conversation toward a concrete, actionable plan.
When to use: Onboarding flows, requirements gathering, interactive tutorials.
Pattern 7: The Recipe Pattern
Structure complex tasks as step-by-step recipes:
Create a "recipe" for: [task]
Format:
🍳 RECIPE: [Task Name]
⏱️ Time: [estimated duration]
📊 Difficulty: [beginner|intermediate|advanced]
📋 Prerequisites: [what you need before starting]
INGREDIENTS (tools/resources needed):
- [ ] [item 1]
- [ ] [item 2]
STEPS:
1. [First step with specific details]
💡 Tip: [helpful hint]
2. [Second step]
⚠️ Warning: [common mistake to avoid]
EXPECTED RESULT:
[What success looks like]
TROUBLESHOOTING:
- If [problem] → [solution]
Pattern 8: The Context Manager
Handle long conversations without losing focus:
system_prompt: |
Maintain a running context summary. After every 5 exchanges,
provide a brief "Context Check":
📍 Context Check:
- Main goal: [what we're working toward]
- Completed: [what we've done]
- Current step: [where we are now]
- Next: [what's coming up]
If the user changes topic, acknowledge: "Switching focus from
[old topic] to [new topic]. I'll keep the previous context
in case we return to it."
Pattern 9: The Error Recovery Pattern
Graceful handling of failures:
system_prompt: |
When an operation fails:
1. ACKNOWLEDGE: "The operation didn't succeed."
2. DIAGNOSE: Explain what went wrong in plain language
3. RECOVER: Suggest 2-3 alternative approaches
4. PREVENT: Explain how to avoid this in the future
Never say "I can't do that" without offering alternatives.
Template:
"❌ [Operation] failed because [reason].
Options:
A) [Alternative approach 1]
B) [Alternative approach 2]
C) [Manual workaround]
Recommended: Option [X] because [reason]."
Pattern 10: The Refinement Pattern
Iterative improvement built into the workflow:
system_prompt: |
After generating any significant output:
1. Present the DRAFT
2. Rate it yourself on:
- Accuracy: X/10
- Completeness: X/10
- Clarity: X/10
3. If any score < 7, automatically revise
4. Present the IMPROVED version
5. Ask: "Should I refine further, or is this good?"
Combining Patterns
The real power comes from composing patterns:
# Production-ready agent combining multiple patterns
system_prompt: |
# Identity (Persona Pattern)
You are a senior DevOps engineer helping with infrastructure.
# Safety (Guardrail Pattern)
Never modify production without explicit confirmation.
# Quality (Fact-Check + Refinement)
Rate confidence on all claims. Self-review before responding.
# Interaction (Cognitive Verifier)
For ambiguous requests, ask 2-3 clarifying questions first.
# Recovery (Error Recovery Pattern)
Always offer alternatives when an approach fails.
Pattern Selection Guide
| Situation | Recommended Pattern |
|---|
| Need consistent format | Output Automator |
|---|
| Need domain expertise | Persona |
|---|
| Risk of errors | Fact-Check + Guardrail |
|---|
| Complex multi-step task | Recipe + Context Manager |
|---|
| User onboarding | Flipped Interaction |
|---|
| Production system | Guardrail + Error Recovery |
|---|
Choose patterns based on your specific needs, combine 2-3 for production agents, and test thoroughly before deployment.
Related Articles
- Emergent Behavior in Multi-Agent Systems — Discover how unexpected emergent behaviors arise in multi-agent systems and how to manage them.
- Agent Cost Control: Token Budgets, Prompt Caching, and Model Routing — Practical ways to control AI agent costs using token budgets, prompt caching, and model routing.
- Avoiding Prompt Injection in Your OpenClaw Skills — Protect your OpenClaw agent from prompt injection attacks with proven security techniques.
- Debugging Unwanted Behavior: When Prompts Go Wrong — Diagnose and fix unexpected agent behavior caused by ambiguous, conflicting, or poorly structured prompts.
- Prompt Engineering 101: Getting the Most from Your AI Assistant — A beginner's guide to prompt engineering principles that unlock the full potential of your AI agent.