Prompt Engineering 101: Getting the Most from Your AI Assistant
Clawpedia · For Humans
A beginner's guide to prompt engineering principles that unlock the full potential of your AI agent.
Overview
Prompt engineering is the art of crafting effective instructions for AI models. Whether you're chatting with your OpenClaw agent directly or writing system prompts for skills, the quality of your prompts directly determines the quality of responses. This guide teaches you the core techniques — from basic structure to advanced strategies.
Why Prompts Matter
AI models are powerful but literal. They do exactly what you ask — not what you mean. A vague prompt produces vague results. A precise, well-structured prompt produces precise, useful answers.
Consider the difference:
| Prompt | Result Quality |
|---|
| "Tell me about Python" | Generic Wikipedia-style overview |
|---|
| "Explain Python list comprehensions with 3 practical examples for data processing" | Focused, actionable, copy-paste-ready |
|---|
Every effective prompt contains these elements:
1. Role (Who should the AI be?)
You are a senior DevOps engineer with 10 years of experience in Kubernetes.
Setting a role primes the model to respond with the appropriate expertise level and vocabulary.
2. Context (What does the AI need to know?)
I have a 3-node Kubernetes cluster running on AWS EKS with Kubernetes 1.28.
My application is a Python Flask API with a PostgreSQL database.
Provide relevant background. The more context the model has, the more tailored the response.
3. Task (What should the AI do?)
Create a Kubernetes deployment manifest for my Flask API with:
- 3 replicas
- Resource limits (256Mi memory, 500m CPU)
- Health checks on /health
- Environment variables from a ConfigMap
Be specific about the expected output format, constraints, and requirements.
4. Output Format (How should the response look?)
Respond with:
1. The YAML manifest
2. A brief explanation of each section
3. Any security recommendations
Core Techniques
Be Specific, Not Vague
| ❌ Vague | ✅ Specific |
|---|
| "Help me with my code" | "Find the bug in this Python function that causes an IndexError on empty lists" |
|---|
| "Write a good email" | "Write a professional 3-paragraph follow-up email to a client who missed a project deadline" |
|---|
| "Explain databases" | "Compare PostgreSQL and MongoDB for a real-time analytics workload with 10M events/day" |
|---|
Show the model what you want by providing examples:
Convert these natural language descriptions to SQL queries.
Example 1:
Input: "Show all users who signed up this month"
Output: SELECT * FROM users WHERE created_at >= DATE_TRUNC('month', CURRENT_DATE)
Example 2:
Input: "Count orders by status"
Output: SELECT status, COUNT(*) FROM orders GROUP BY status
Now convert:
Input: "Find the top 5 customers by total spending"
Few-shot prompting is one of the most reliable techniques for consistent formatting.
Chain of Thought (Step-by-Step Reasoning)
For complex problems, ask the model to think step by step:
Analyze this database query for performance issues.
Think step by step:
1. First, identify which tables are involved
2. Then, check for missing indexes
3. Next, look for N+1 query patterns
4. Finally, suggest optimizations with expected impact
This produces more thorough and accurate responses than asking for the answer directly.
Constraints and Boundaries
Tell the model what NOT to do:
Explain Kubernetes pods to a junior developer.
- Use simple language, no jargon without explanation
- Do NOT mention implementation details of container runtimes
- Keep the explanation under 200 words
- Include one real-world analogy
Persona Prompting
Combine role and constraints for consistent behavior:
You are a concise technical writer.
Rules:
- Maximum 3 sentences per explanation
- Always include a code example
- Use bullet points for lists
- Never start a sentence with "In order to"
OpenClaw-Specific Prompt Techniques
System Prompts
Your agent's system prompt is the persistent instruction that shapes all interactions:
# config.yaml
agent:
system_prompt: |
You are a helpful personal assistant named Claw.
You have access to the user's calendar, email, and task list.
Always be concise. If a task requires multiple steps, list them as a numbered plan.
When you're unsure, say so instead of guessing.
Current date: {{date}}
User timezone: {{timezone}}
Tip: OpenClaw supports template variables like
{{date}}and{{timezone}}that are automatically replaced at runtime.
Skill-Level Prompts
Each skill can have its own prompt that specializes the model for that task:
# skills/code-review/manifest.yaml
name: code-review
prompt: |
You are a code reviewer. Analyze the given code for:
1. Bugs and logical errors
2. Security vulnerabilities
3. Performance issues
4. Readability improvements
Format your review as a list with severity labels: [CRITICAL], [WARNING], [SUGGESTION].
Dynamic Prompts with Context
Inject real-time data into prompts:
agent:
system_prompt: |
You are assisting {{user_name}}.
Their upcoming events: {{calendar_events}}
Their open tasks: {{task_list}}
Prioritize time-sensitive items.
Advanced Strategies
Structured Output
Force the model to respond in a specific format:
Analyze the sentiment of each review. Respond ONLY in this JSON format:
{
"reviews": [
{"text": "...", "sentiment": "positive|negative|neutral", "confidence": 0.0-1.0}
]
}
Iterative Refinement
Don't settle for the first response. Refine:
- Start with a broad prompt.
- Review the output.
- Add constraints to fix issues.
- Repeat until satisfied.
Example refinement chain:
V1: "Write a product description"
V2: "Write a 50-word product description for a mechanical keyboard"
V3: "Write a 50-word product description for the CyberBoard R3 mechanical keyboard, targeting gamers, emphasizing low latency and RGB customization"
Meta-Prompting
Ask the AI to help you write better prompts:
I want to create a prompt that makes an AI agent summarize meeting transcripts.
The summary should include: decisions, action items, and open questions.
Help me write the optimal prompt for this task.
Common Mistakes
| Mistake | Problem | Fix |
|---|
| Too vague | Generic responses | Add specifics, constraints, examples |
|---|
| Too long | Model loses focus | Break into steps, prioritize key instructions |
|---|
| Contradictory | Confused output | Review for conflicting requirements |
|---|
| No examples | Inconsistent format | Add 2-3 few-shot examples |
|---|
| No output format | Unpredictable structure | Specify exact format (JSON, Markdown, list) |
|---|
Add explicit length constraints: "Respond in 3 sentences" or "Maximum 100 words."
Model Ignores Instructions
Move the most important instructions to the beginning or end of the prompt — models pay the most attention to these positions.
Inconsistent Output Format
Provide 2-3 examples of the exact format you want. Few-shot prompting is the most reliable way to enforce formatting.
Model Hallucinates Facts
Add: "If you don't know the answer, say 'I don't know' instead of guessing. Only cite information you're confident about."
Next Steps
- Apply prompts to OpenClaw skills in Using Prompts Inside Skills: Tips and Techniques.
- Configure system prompts in Using System Prompts and User Prompts in OpenClaw.
- Explore model selection in Setting Your OpenClaw AI Model and Provider.
Related Articles
- Avoiding Prompt Injection in Your OpenClaw Skills — Protect your OpenClaw agent from prompt injection attacks with proven security techniques.
- Integrating OpenClaw with Google Assistant (Step-by-Step) — Connect OpenClaw to Google Assistant for voice-activated AI agent control in your smart home.
- 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.
- Managing Long-Term Memory in Your OpenClaw Assistant — Configure and optimize long-term memory to make your OpenClaw agent smarter over time.
- Prompt Design Patterns for Reliable AI Agent Behavior — Proven design patterns for writing prompts that produce predictable, reliable AI agent outputs.