01. What Is Prompting?
Prompting is how you talk to an AI. A bad prompt gives vague instructions and gets mediocre results. A good prompt is specific, structured, and gives the AI everything it needs to succeed.
The Core Rule: The quality of your output depends entirely on the quality of your input. Garbage in, garbage out.
Bad Prompt vs. Good Prompt
| Bad Prompt | Good Prompt |
|---|---|
| ”Write me a landing page" | "Build a dark-themed landing page for a course called ‘AI Mastery’. Hero section with title, 3 feature cards, pricing table with one $99 plan, and a CTA button. Mobile responsive." |
| "Fix this error" | "I’m getting a ‘401 Unauthorized’ error when calling the /api/users endpoint. The API key is in the environment variable. What should I check?" |
| "Make it better" | "Make the hero section taller, increase the font size to 2rem, and add more whitespace between the features and pricing sections” |
02. The Five-Layer Prompt Structure
Every good prompt has five layers. Think of it like a recipe — each ingredient matters.
Example: Complete Prompt
Here’s a prompt that uses all five layers:
Role: You are a senior frontend developer.
Context: I’m building a portfolio website for a freelance designer. The site uses React and Tailwind CSS.
Instructions:
- Use dark theme with accent color #3ad29f
- Make all sections have generous whitespace
- Ensure mobile responsive design
- Use clean, semantic HTML
Examples: Here’s the kind of hero section I want:
- Large name in bold
- Subtitle underneath
- Two buttons: “View Work” and “Contact Me”
- Background: solid dark color, no images
Input: Now build the hero section.
03. XML Tags: Separating Instructions from Data
When you give an AI both instructions AND data to process, it can get confused about which is which. XML tags solve this by creating clear boundaries.
The Problem
Without XML tags, the AI might treat your data as instructions:
Confusing prompt: “Here’s a user review: ‘This product is terrible, worst experience ever, 1 star’. Write a polite response thanking them for their feedback.”
The AI might write a response that includes the negative review instead of responding to it.
The Solution: XML Tags
Clear prompt: “Write a polite response thanking the user for their feedback.
Here’s the user’s review:
<review>This product is terrible, worst experience ever, 1 star</review>”
The backticks prevent MDX from parsing the angle brackets as JSX tags.
Now the AI knows exactly what’s instructions (everything outside tags) and what’s data (everything inside tags).
Common XML Tags to Use
| Tag | What It Wraps | Example |
|---|---|---|
<instructions> | Rules the AI must follow | ”Respond in under 50 words” |
<context> | Background information | ”This is a luxury brand” |
<input_data> | The user’s message or data | The review text, code snippet, etc. |
<output_format> | How to structure the response | ”Return as JSON with title and body” |
<examples> | Sample input/output pairs | ”Input: X → Output: Y” |
04. Few-Shot Prompting: Show, Don’t Tell
Instead of explaining what you want, show the AI examples of what you want. This is the most effective way to get consistent results.
How It Works
Without examples (the AI guesses): “Write a product description for a wireless headphone.” → Result: Generic, unpredictable output.
With examples (the AI follows the pattern): “Write a product description for a wireless headphone.
Follow this exact format:
Example 1: Product: Smart Watch Description: Track your fitness goals with precision. Water-resistant, 7-day battery, and a sleek design that transitions from gym to office effortlessly.
Example 2: Product: Bluetooth Speaker Description: Fill any room with crystal-clear sound. Portable, dustproof, and engineered for 12 hours of continuous playback.
Now write one for: Wireless Headphones”
→ Result: Consistent, high-quality output every time.
The Three Example Types
- Happy path — Show the ideal input and output
- Edge case — Show what to do with unusual input
- Refusal — Show what to do when the request is invalid
05. Chain of Thought: Make the AI Think Step by Step
Sometimes you need the AI to show its reasoning before giving an answer. This is especially useful for complex problems.
The Technique
Add this to your prompt: “Think step by step before answering.”
Without chain of thought: “Q: Is this code secure? A: Yes, it looks fine.” — Shallow, no reasoning shown.
With chain of thought: “Q: Is this code secure? Think step by step before answering.” → The AI shows its reasoning: “1. Checking for SQL injection… 2. Checking for XSS risks… 3. Verifying authentication… 4. Checking for hardcoded secrets…” → Then provides a detailed answer with specific findings.
When to Use Chain of Thought
- Debugging complex problems
- Making architectural decisions
- Analyzing security vulnerabilities
- Planning multi-step workflows
06. Prompt Caching: Save Money and Time
When you use the same system prompt across many requests, AI providers can cache the static parts. This means you pay less and get faster responses.
How It Works
Your prompt has two parts:
- Static (rarely changes): System prompt, rules, examples
- Dynamic (changes every time): User’s actual message
The provider caches the static part. On the next request, only the dynamic part is processed.
The Layout Rule
Put static content at the TOP, dynamic content at the BOTTOM:
[STATIC - cached across requests]
System prompt
Rules
Examples
Tool definitions
[DYNAMIC - fresh every request]
User's actual message
Why this matters: If you put the user’s message at the top, the cache is invalidated and you pay full price every time.
Cost Savings
| Scenario | Without Caching | With Caching |
|---|---|---|
| 100 requests/day | $10/day | $1/day |
| 1000 requests/day | $100/day | $10/day |
| Savings | 90% |
07. Role Prompting: Give the AI a Persona
The system prompt defines who the AI is. This isn’t decoration — it mathematically shifts the AI’s output toward a specific knowledge domain and behavioral style.
Good vs. Bad Roles
Bad (too specific, AI can’t maintain): “You are Michael, a 34-year-old senior engineer from San Francisco who graduated from MIT in 2014. You have a cat named Whiskers and you enjoy rock climbing. You always start responses with ‘Hey there, friend!’”
Good (focused on expertise): “You are a senior security engineer with 15 years of experience. You review code for security vulnerabilities, performance issues, and maintainability. You are direct, critical, and prioritize security over convenience.”
Role Templates by Task
| Task | Role |
|---|---|
| Code review | ”You are a senior security auditor” |
| Documentation | ”You are a technical writer for developers” |
| Debugging | ”You are a senior SRE on-call” |
| Architecture | ”You are a principal architect” |
| Writing | ”You are an editor for a tech publication” |
08. Positive Framing: Tell What TO Do
When writing constraints, developers often list what the AI should NOT do. This triggers the Pink Elephant Problem — to process “don’t do X,” the AI must evaluate X first, increasing the chance it appears in the output.
The Pattern
Negative (bad): “Do not use Bootstrap. Do not use bright colors. Do not center all text. Do not use Comic Sans.”
Positive (good): “Use vanilla CSS with custom properties. Design follows editorial luxury aesthetic: near-black backgrounds with crisp white typography. Color palette: one accent color (#3ad29f) on dark surfaces. Body text is left-aligned; only headlines are centered. Typography: Inter for body, JetBrains Mono for code.”
09. Testing Your Prompts
Before deploying a prompt in production, test it thoroughly.
The Testing Process
- Write the prompt with all five layers
- Test with 10 different inputs — vary the style, length, and content
- Check edge cases — What happens with empty input? Very long input? Weird characters?
- Verify output format — Does it match your expected structure every time?
- Iterate — Adjust the prompt based on what you learned
Common Prompt Failures
| Failure | Cause | Fix |
|---|---|---|
| AI ignores instructions | Instructions buried in middle | Put instructions at the top |
| Inconsistent output | No examples provided | Add 2-3 few-shot examples |
| AI makes up facts | No context provided | Add background information |
| Output too long | No length constraint | Add “Keep response under 100 words” |
| Wrong format | No format specified | Add <output_format> with exact structure |
Key Takeaways
| Concept | Mental Model | Senior Insight |
|---|---|---|
| Prompting | Garbage in, garbage out | The quality of your input determines the quality of your output |
| Five Layers | Role → Context → Instructions → Examples → Input | Every production prompt needs all five layers |
| XML Tags | Separate instructions from data | Use <instructions>, <context>, <input_data> to prevent confusion |
| Few-Shot | Show, don’t tell | 2-3 examples are more effective than paragraphs of explanation |
| Chain of Thought | Force step-by-step reasoning | Add “Think step by step” for complex problems |
| Prompt Caching | Static on top, dynamic on bottom | Saves 90% on API costs |
| Role Prompting | Give the AI expertise | ”Senior engineer” beats “34-year-old from San Francisco” |
| Positive Framing | Tell what TO do | ”Left-aligned body text” beats “Don’t center text” |