Prompt Engineering: From Beginner to Expert
Back to all articles
Prompt Engineering
32 min read7 min read

Prompt Engineering: From Beginner to Expert

The complete guide to prompt engineering. Learn techniques from basic structuring to advanced chain-of-thought and few-shot prompting.

Debasish Maji
Debasish Maji
AI Engineering Lead
February 28, 2026
Prompt EngineeringLLMGPTChain of Thought

Why Prompt Engineering Matters

The same AI model can give brilliant or terrible responses depending on how you ask. Prompt engineering is the skill of asking well.

Code
Bad prompt:  "Write about dogs"
Result:      Generic, unfocused content

Good prompt: "Write a 200-word guide for first-time dog owners 
             choosing between a Labrador and Golden Retriever, 
             comparing their exercise needs, temperament, and 
             grooming requirements. Use a friendly, helpful tone."
Result:      Exactly what you needed
•••

Part 1: The Fundamentals

The Basic Prompt Structure

Code
[Role/Context] + [Task] + [Format] + [Constraints]

Example:
"You are a senior software engineer.        <- Role
 Review this code for security issues.      <- Task
 List each issue with severity and fix.     <- Format
 Focus on SQL injection and XSS only."      <- Constraints

Be Specific, Not Vague

Code
❌ Vague: "Make it better"
✓ Specific: "Improve readability by adding comments, using descriptive 
             variable names, and breaking the function into smaller parts"

❌ Vague: "Write about AI"
✓ Specific: "Write a 500-word explanation of how neural networks learn,
             suitable for someone with basic programming knowledge"

Provide Context

The AI doesn't know what you know. Include relevant context:

Code
❌ "Fix the bug in my code"
   (What code? What bug?)

✓ "This Python function should return the sum of even numbers, 
   but it's returning the sum of all numbers. Here's the code:
   
   def sum_evens(numbers):
       total = 0
       for n in numbers:
           total += n
       return total
   
   Fix the bug and explain what was wrong."
•••

Part 2: Advanced Techniques

Chain-of-Thought Prompting

Ask the AI to think step-by-step for complex reasoning:

Code
❌ "What's 23 × 47?"
   (AI might just guess)

✓ "What's 23 × 47? Think step by step."
   
   AI response:
   "Let me break this down:
   23 × 47 = 23 × (50 - 3)
           = 23 × 50 - 23 × 3
           = 1150 - 69
           = 1081"

Few-Shot Learning

Show examples of what you want:

Code
"Convert these sentences to formal English:

Casual: 'gonna grab some food, wanna come?'
Formal: 'I am going to get some food. Would you like to join me?'

Casual: 'nah, im good'
Formal: 'No, thank you. I am fine.'

Casual: 'btw the meeting got pushed to 3'
Formal: "

Role Prompting

Assign a persona for consistent behavior:

Code
"You are a patient, encouraging coding tutor who:
- Never gives complete solutions immediately
- Asks guiding questions to help students discover answers
- Celebrates small wins and progress
- Uses simple analogies to explain complex concepts

A student asks: 'I don't understand recursion'"

Output Formatting

Specify exactly how you want the output:

Code
"Analyze this product review and respond in JSON:
{
  'sentiment': 'positive/negative/neutral',
  'confidence': 0.0 to 1.0,
  'key_points': ['point1', 'point2'],
  'improvement_suggestions': ['suggestion1']
}

Review: 'Love this product but shipping was slow'"
•••

Part 3: System Prompts

What Are System Prompts?

System prompts set the overall behavior for all subsequent interactions:

Python
response = openai.chat.completions.create(
    model="gpt-4",
    messages=[
        {"role": "system", "content": "You are a helpful assistant..."},
        {"role": "user", "content": "What's the weather?"}
    ]
)

Writing Effective System Prompts

Code
## Core Identity
You are [name], a [role] that helps users [primary goal].

## Personality
- [Trait 1]: description
- [Trait 2]: description

## Key Behaviors
1. Always [behavior]
2. Never [anti-behavior]
3. When [situation], do [action]

## Response Format
- Keep responses [length guideline]
- Use [formatting preference]
- Include [required elements]

## Boundaries
- Don't [restriction 1]
- Don't [restriction 2]

Example: Customer Support Bot

Code
## Core Identity
You are Aria, a friendly customer support agent for TechCorp, 
a software company that makes project management tools.

## Personality
- Warm and empathetic: Acknowledge frustrations before solving
- Clear communicator: No jargon, step-by-step instructions
- Proactive: Anticipate follow-up questions

## Key Behaviors
1. Always greet users warmly
2. Always confirm you understood their issue
3. Never blame the user for problems
4. When you can't help, escalate to human support
5. End interactions by asking if there's anything else

## Knowledge
- You can help with: account issues, billing, feature questions
- You cannot: process refunds (must escalate), access user data

## Response Format
- Keep responses under 150 words unless explaining complex steps
- Use numbered lists for multi-step instructions
- Bold key actions: "Click **Settings** then **Account**"
•••

Part 4: Common Patterns

The CRISPE Framework

Code
C - Capacity: What role should the AI assume?
R - Request: What specific task should it do?
I - Information: What context does it need?
S - Style: How should it communicate?
P - Preferences: Any special requirements?
E - Examples: Sample inputs/outputs if helpful

Example:
"Capacity: You are a data scientist
Request: Analyze this dataset for trends
Information: Sales data from 2020-2023, columns: date, product, revenue
Style: Professional but accessible
Preferences: Focus on quarterly patterns
Examples: 'Q1 2022 showed 15% growth compared to Q1 2021'"

Iterative Refinement

Start broad, then narrow:

Code
Prompt 1: "Write about machine learning"
(Too broad, not useful)

Prompt 2: "Write an introduction to machine learning for business executives"
(Better, but still vague)

Prompt 3: "Write a 300-word introduction to machine learning for 
          business executives who need to decide whether to invest 
          in ML projects. Focus on practical applications and ROI."
(Specific and actionable)

Constraint-First Prompting

State limitations upfront:

Code
"Important constraints:
- Response must be under 100 words
- Use only vocabulary a 10-year-old would understand
- No technical jargon

Now explain: What is a computer virus?"
•••

Part 5: Domain-Specific Prompting

For Code Generation

Code
"Write a Python function that:
- Name: validate_email
- Input: string (email address)
- Output: boolean (True if valid)
- Requirements:
  * Check for @ symbol
  * Check for domain with dot
  * Handle edge cases (empty string, None)
- Style: Include docstring, type hints
- Don't use: regex (use string methods only)"

For Content Writing

Code
"Write a blog post:
- Topic: Benefits of remote work
- Audience: HR managers considering hybrid policies
- Tone: Professional but engaging
- Length: 800 words
- Structure: 
  * Hook opening with a statistic
  * 3 main benefits with examples
  * Address one common concern
  * Call to action
- SEO: Include keywords 'remote work benefits', 'hybrid workplace'"

For Data Analysis

Code
"Analyze this sales data and provide:
1. Key trends (3-5 bullet points)
2. Anomalies that need investigation
3. Recommendations (prioritized by impact)

Data context:
- Monthly sales figures for 2023-2025
- Products: A, B, C
- Regions: North, South, East, West

Focus on: Seasonal patterns and regional differences
Format: Markdown with headers"
•••

Part 6: Avoiding Common Mistakes

Mistake 1: Too Vague

Code
❌ "Help me with my project"
✓ "I'm building a React app for a todo list. I need help 
   implementing drag-and-drop reordering of tasks."

Mistake 2: No Format Specification

Code
❌ "List the pros and cons of Python"
✓ "Create a comparison table of Python pros and cons with 
   columns: Category, Advantage/Disadvantage, Example"

Mistake 3: Conflicting Instructions

Code
❌ "Be concise but also be thorough and explain everything in detail"
✓ "Provide a concise summary (2-3 sentences), then a detailed 
   explanation (2-3 paragraphs) for those who want more depth"

Mistake 4: Assuming Context

Code
❌ "Continue the code from before"
   (New session, AI doesn't remember)
✓ "Here's my existing code: [paste code]. Add a function 
   that validates user input."
•••

Key Takeaways

  1. 1Specificity wins - The more specific your prompt, the better the result
  1. 2Structure helps - Use frameworks like Role + Task + Format + Constraints
  1. 3Examples are powerful - Few-shot learning dramatically improves outputs
  1. 4Chain-of-thought for reasoning - Ask the AI to think step-by-step
  1. 5Iterate and refine - Start broad, narrow based on results
  1. 6Context is crucial - Include all relevant information the AI needs

Found this helpful?

Share it with others who might benefit

TweetShare

Related articles