Basic prompt structure handles straightforward tasks, but complex problems need more sophisticated techniques. These methods unlock better reasoning, domain expertise, and multi-step problem solving from AI tools.
Chain-of-thoughtWhat is chain-of-thought?A prompting technique where you ask the AI to show its reasoning step by step before giving a final answer, improving accuracy on complex problems. prompting
What it is: Asking the AI to think step by step and show its reasoning.
Why it works: Breaking problems into steps reduces errors and helps you verify the logic.
Without chain-of-thought
A farmer has 17 sheep and all but 9 die. How many are left?AI might answer: 8 (subtracting 9 from 17)
With chain-of-thought
A farmer has 17 sheep and all but 9 die. How many are left?
Think through this step by step before giving your answer.AI reasoning:
Step 1: "All but 9 die" means 9 sheep did NOT die
Step 2: The question asks how many are LEFT (alive)
Step 3: Therefore, 9 sheep are leftWhen to use chain-of-thought
| Use case | Example |
|---|---|
| Math problems | "Calculate the tip on $47.50 at 18%. Show your work." |
| Logic puzzles | "Solve this step by step..." |
| Code debugging | "Walk through what this code does line by line" |
| Complex decisions | "Analyze the pros and cons of each option" |
The "magic phrase"
These phrases trigger chain-of-thought reasoning:
- "Let's think step by step"
- "Explain your reasoning"
- "Walk through this systematically"
- "Before answering, consider..."
- "Break this down into steps"
Few-shot learning
What it is: Teaching the AI a pattern by showing examples instead of explaining rules.
Why it works: Examples are concrete and unambiguous. The AI learns the pattern from data, not descriptions.
Pattern matching with examples
Convert dates from MM/DD/YYYY to "Month Day, Year" format:
03/15/2023 → March 15, 2023
12/25/2022 → December 25, 2022
07/04/1776 → July 4, 1776
Now convert: 11/30/2024The AI learns:
- First two digits are month number
- Middle two digits are day
- Last four digits are year
- Month names are spelled out
- Format is "Month Day, Year"
Few-shot for code style
Convert these function names to camelCase following the pattern:
get_user_data → getUserData
update_user_profile → updateUserProfile
delete_old_records → deleteOldRecords
Now convert these:
fetch_customer_orders
validate_email_address
send_notification_emailHow many examples?
| Complexity | Examples needed |
|---|---|
| Simple pattern | 2-3 |
| Complex transformation | 3-5 |
| Subjective/nuanced | 5-10 |
Role prompting
What it is: Assigning a specific persona or role to the AI.
Why it works: Different roles have different knowledge bases, vocabularies, and perspectives.
Role prompt structure
Act as a [specific role]. [Context about the situation].
[Your request]Examples of effective roles
| Role | Use case |
|---|---|
| "Senior React developer" | Code review and architecture advice |
| "Technical writer" | Documentation and explanations |
| "DevOps engineer" | Infrastructure and deployment help |
| "Security expert" | Security audit and best practices |
| "Beginner student" | Explaining your code simply |
| "Product manager" | Feature prioritization and user stories |
Role prompting in action
Without role:
Review this code.With role:
You are a senior JavaScript developer with 10 years of experience.
You specialize in React performance optimization.
Review this code for:
1. Performance issues
2. React best practices
3. Potential bugs
4. Readability improvements
Be thorough but constructive in your feedback.Combining roles with constraints
You are a code reviewer at a strict company that values:
- Type safety above all else
- Minimal dependencies
- Comprehensive error handling
Review this function with those priorities in mind.System prompts
What it is: Instructions that apply to the entire conversation, not just one message.
Why it works: Sets persistent behavior so you don't repeat instructions.
System vs user prompts
System promptWhat is system prompt?Hidden instructions set by the developer that shape how an AI assistant behaves throughout a conversation. Users don't see it, but it defines the AI's persona and constraints. (set once):
You are a helpful coding assistant. Always:
1. Provide code in markdown code blocks
2. Explain complex concepts simply
3. Suggest best practices
4. Ask clarifying questions when neededUser prompts (ongoing):
How do I reverse an array in JavaScript?When to use system prompts
Use system prompts for:
- Persistent formatting requirements
- Safety guidelines
- Personality/tone settings
- Domain expertise ("You are an expert in...")
APIWhat is api?A set of rules that lets one program talk to another, usually over the internet, by sending requests and getting responses. example (OpenAI)
response = client.chat.completions.create(
model="your-model-id", # check docs for current models
messages=[
{"role": "system", "content": "You are a concise technical assistant. Always provide code examples."},
{"role": "user", "content": "Explain closures in JavaScript"}
]
)Web interface workaround
ChatGPT and Claude don't have a "system prompt" field, but you can simulate it:
For this conversation, I want you to act as a [role].
Always [behavior 1], [behavior 2], and [behavior 3].
Understood? (Wait for confirmation)
[Then proceed with your actual questions]Iterative refinement
What it is: Treating prompting as a conversation, improving results through feedback.
Why it works: The AI can learn from your feedback and adjust its approach.
The iterative process
Step 1: Initial prompt
"Write a function to validate email addresses"
Step 2: Review and give feedback
"Good start, but I need it to also check that the domain
actually exists. Can you add that?"
Step 3: Further refinement
"Perfect. Now can you make it return specific error messages
instead of just true/false?"
Step 4: Final polish
"Great! Can you add TypeScript types and JSDoc comments?"Effective feedback phrases
| What you want | What to say |
|---|---|
| More detail | "Can you expand on [specific part]?" |
| Less detail | "Can you give me just the essentials?" |
| Different approach | "Can you show me an alternative way?" |
| Fix errors | "There's an issue with [specific thing]" |
| Change format | "Can you present this as [format]?" |
| Simpler language | "Explain this like I'm a beginner" |
When to start over vs iterate
Iterate when:
- The response is 70% of what you need
- You can pinpoint specific issues
- You want to explore variations
Start over when:
- The response is completely off
- You forgot crucial context
- You need a fundamentally different approach
Prompt chaining
What it is: Breaking a complex task into a sequence of simpler prompts, using the output of one as input to the next.
Why it works: Each step has focused context, reducing confusion and improving accuracy.
Example: Building a feature
Chain Step 1: Planning
I need to add user authentication to my React app.
Requirements:
- Login with email/password
- JWT token storage
- Protected routes
Create a plan with:
1. Components needed
2. State management approach
3. API integration pointsChain Step 2: Generate types/interfaces
Based on that plan, generate TypeScript interfaces for:
- User data
- Auth context
- API responsesChain Step 3: Build the auth context
Now create the AuthContext using those types.
Include login, logout, and auth state.Chain Step 4: Create the login form
Create a LoginForm component that uses AuthContext.
Include form validation with React Hook Form.Benefits of prompt chaining
- Better accuracy: Each step is simpler and clearer
- Easier debugging: You can see where things go wrong
- Human oversight: Review each step before continuing
- Reusability: Save useful intermediate outputs
Prompt chaining patterns
| Pattern | Description | Example |
|---|---|---|
| Sequential | Do A, then B, then C | Plan → Code → Test |
| Branching | Start with one prompt, then choose direction | Analyze → (Fix bug OR Add feature) |
| Iterative | Repeat until done | Draft → Review → Revise → Review |
| Parallel | Run multiple prompts, then combine | Generate 3 ideas → Evaluate each → Pick best |
Quick reference: technique selection
| Problem | Technique |
|---|---|
| Complex reasoning | Chain-of-thought |
| Pattern learning | Few-shot examples |
| Expert knowledge | Role prompting |
| Consistent behavior | System prompts |
| Improving results | Iterative refinement |
| Complex tasks | Prompt chaining |
These advanced techniques aren't just tricks, they're ways of working with AI more effectively. Chain-of-thoughtWhat is chain-of-thought?A prompting technique where you ask the AI to show its reasoning step by step before giving a final answer, improving accuracy on complex problems. improves accuracy, few-shot learning teaches patterns, roles bring expertise, and chaining manages complexity. Combine them as needed. The best prompters mix and match techniques based on the task at hand.