UNIT: 2
Prompt Engineering and
Prompt Optimization
Techniques:
SYLLABUS
• Prompt Engineering and Prompt Optimization
Techniques: Basics of Prompt Engineering, Types of
Prompts: Declarative, Interrogative, Instructional,
Advanced Prompt Engineering: Chain-of-Thought
Prompting, Zero-shot and Few-shot Prompting,
Prompt Optimization Techniques, Use Cases and
Practical Examples in Coding, Writing, and Customer
Interaction
Introduction to Prompt
Engineering
• Definition:
• Prompt Engineering is the process of crafting input
queries or instructions (called "prompts") in a
structured and optimized way to guide large
language models (LLMs) like ChatGPT, Gemini, or
Claude to produce accurate, context-relevant, and
useful outputs.
Importance of Prompt Engineering:
• Enhances model accuracy and reliability
• Reduces chances of hallucination or irrelevant
answers
• Maximizes the potential of generative tools in
automation, creativity, and reasoning tasks
• Affects performance in zero-shot, few-shot, and multi-
turn interactions
Types of Prompts
• 1. Declarative Prompts
• 🔸 Definition:
• Prompts that state a fact or request information
without forming a direct question. These are
typically used to elicit factual or explanatory
responses.
• 🔸 Structure:
• Usually a statement or simple instruction
Example:
• Explain the laws of thermodynamics.
• Write a short note on Generative Adversarial
Networks.
• ✅ Use case: Educational answers, explanations,
definitions
❌ Limitation: May result in generic responses if not
specific
2. Interrogative Promp
ts
• 2. Interrogative Prompts
• 🔸 Definition:
• These are prompts in the form of questions. They are most
common when a user wants specific information or insight.
• 🔸 Structure:
• Begins with question words like What, Why, How, When,
Who, Which
Example:
• What is the difference between supervised and
unsupervised learning?
• How does reinforcement learning work?
• ✅ Use case: Query-based tasks, research questions
❌ Limitation: If vague, can confuse the model or
give irrelevant answers
3. Instructional Prompts
• 🔸 Definition:
• Prompts that give explicit instructions or
commands to perform a specific task or
transformation.
• 🔸 Structure:
• Begins with a verb such as write, generate,
summarize, explain, create, convert
Example:
• Summarize the following paragraph in 3 bullet points.
• Convert this JSON into a Python dictionary.
• Write a story about a robot living on Mars.
• ✅ Use case: Writing, summarization, translation,
transformation
❌ Limitation: Ambiguity in instruction may mislead the
model
Contextual Prompts
• Definition:
• Prompts that provide background context, so that
the model understands the full situation before
responding.
• 🔸 Structure:
• Includes prior messages, task settings, or assumed
knowledge
•
Example:
• You are an AI tutor helping a 10th-grade student
understand calculus.
• Explain integration in the simplest possible way.
• ✅ Use case: Personalized responses, role-specific
behavior
❌ Limitation: Longer prompts may consume more
tokens
5. Role-based Prompts
• 🔸 Definition:
• Prompts that assign the model a persona or
profession to shape its tone, vocabulary, and
knowledge depth.
• 🔸 Structure:
• Starts with a role statement: "Act as a...", "You
are a..."
Example:
• You are a cybersecurity expert. Explain phishing
attacks to a non-technical user.
• Act as a data scientist and evaluate this dataset.
• ✅ Use case: Domain-specific tasks, tone control,
expert-level explanations
❌ Limitation: May overfit or hallucinate expertise
6. Few-shot Prompts
• 🔸 Definition:
• These prompts include 1–5 examples of how the
model should respond. It's like "showing" before
asking.
• 🔸 Structure:
• Shows input-output pairs as samples
• Ends with a new input for the model to complete
Example:
• Translate English to Spanish:
• English: Hello → Spanish: Hola
• English: Thank you → Spanish: Gracias
• English: Good night →
• ✅ Use case: Custom task formatting, consistent responses
❌ Limitation: Requires more tokens and manual example creation
7. Zero-shot Prompts
• Definition:
• A prompt that includes no examples and
depends solely on the model's general
knowledge.
• 🔸 Structure:
• Direct instruction without guidance samples
Example:
• Summarize the following article in 50 words.
• List five applications of artificial intelligence.
• ✅ Use case: Fast, general-purpose prompts
❌ Limitation: May lack structure or expected
format
8. Chain-of-Thought (CoT) Prompts
• 🔸 Definition:
• These prompts instruct the model to think
step-by-step before giving the answer.
Useful for complex reasoning.
• 🔸 Structure:
• Ends with: "Let's think step by step."
Example:
• If a train travels 60 km in 1 hour and then 90
km in 1.5 hours, what is the average speed?
Let's think step by step.
• ✅ Use case: Reasoning, math, logic, planning
❌ Limitation: Output may be lengthy
9. Multi-turn Prompts
• 🔸 Definition:
• These are prompts used in conversational
interactions, where each turn builds on the
previous one.
• 🔸 Structure:
• Context preserved between questions
Example:
• User: What is a neural network?
• Model: A neural network is...
• User: Can you explain backpropagation?
• Model: Sure, backpropagation is...
• ✅ Use case: Chatbots, tutoring, conversational AI
❌ Limitation: Context can be lost if not handled properly
Introduction to Prompt
Optimization
Prompt Optimization refers to the process of
improving prompt design to achieve more
accurate, reliable, and desirable outputs from a
generative AI model such as ChatGPT, Claude, or
Gemini. It is a core component of Prompt
Engineering and directly influences the quality
of interaction.
Goals of Prompt Optimization
• Enhance response relevance and precision
• Reduce ambiguity and hallucination
• Control tone, style, and length
• Improve consistency in structured outputs
• Customize for specific tasks (e.g., coding,
writing, customer support)
Prompt Optimization Techniques
• A. Rewriting Prompts Clearly
• Use explicit, specific instructions
• Avoid vague or ambiguous language
• Example: ❌ Bad Prompt: Write about trees.
• ✅ Good Prompt: Write a 100-word paragraph
describing the ecological role of trees in maintaining
air quality.
Instructional Cueing
• Start with verbs: write, list, summarize,
generate, translate
• Example:
• Generate a Python function to compute the
factorial of a number.
Format Control (Output Shaping)
• Use bullet points, numbered lists, tables,
or JSON
• Example:
• List 3 pros and cons of renewable energy
in bullet points.
Role Assignment
• Assign roles to get domain-specific
answers
• Example:
• You are an HR manager. Draft a job
description for a data analyst.
Use of Few-shot Examples
• Provide examples of desired behavior/output
• Example: Input: "Cat" → Output: "Animal"
• Input: "Rose" → Output: "Plant"
• Input: "Car" → Output: ?
Chain-of-Thought Prompting
• Encourage step-by-step reasoning
• Example:
• What is 18% of 250? Let's solve it step-by-
step.
Multimodal Prompting (if
supported)
•Combine text with
image/audio (e.g., for caption
generation or visual QA)
Iterative Refinement
• Continuously tweak prompt based on
output
• Example: Initial Prompt: Generate a
story.
• Refined Prompt: Generate a 150-word
motivational story with a moral,
Prompt
Optimizati
on
Framework
Use Cases & Practical Examples
• A. Coding Assistance
• Task: Generate Python code to reverse a string
• Optimized Prompt: Write a Python function
named reverse_string that takes a string input and
returns the reversed string.
• Output:
• def reverse_string(s):
• return s[::-1]
B. Content Writing
• Task: Generate an email to invite students to a workshop
Prompt: Write a professional email to B.Tech final-year students
inviting them to a workshop on Generative AI. Include date, time, and
registration link.
• Output: Subject: Invitation to Workshop on Generative AI
• Dear Students,
• You are invited to attend a workshop on Generative AI scheduled for
August 10, 2025, from 10:00 AM to 1:00 PM. Click the link to register:
www.aiworkshop2025.com.
• Best regards,
Customer Interaction
• Task: Handle customer complaint about late
delivery
Prompt: You are a customer support agent. Respond
politely to a complaint about delayed product
delivery and offer a 10% refund.
• Output: We sincerely apologize for the delay in
your delivery. We understand your concern and
have initiated a 10% refund as a token of our
apology. Thank you for your patience.
Generative AI in Workplace and
Education
• A. AI in Office Productivity
• Generative AI tools streamline repetitive and manual office tasks
using NLP and ML. Below are key applications:
• 1. Email Writing
• AI-generated email drafts reduce time spent on communication.
• Can adapt tone (formal/informal), structure, and purpose (follow-up,
invitation, apology).
• Tools: ChatGPT, Jasper, GrammarlyGO
• Example Prompt: "Draft a follow-up email to remind a client about
an upcoming deadline."
Generative AI in Workplace and
Education
• A. AI in Office Productivity
• Generative AI tools streamline repetitive and manual office tasks
using NLP and ML. Below are key applications:
• 2. Report Drafting
• Auto-summarization and content extension features.
• Format-ready outputs aligned with organizational standards.
• Tools: Notion AI, Microsoft Copilot, ChatGPT
• Example Prompt: "Create a monthly performance report for the
software development team with project updates."
Generative AI in Workplace and
Education
• A. AI in Office Productivity
• Generative AI tools streamline repetitive and
manual office tasks using NLP and ML. Below are
key applications:
• 3. Minutes of Meeting (MoM)
• Real-time meeting transcript summarization
• Action item extraction, role assignment
• Tools: Otter.ai, Fireflies.ai, AI Notetaker in Zoom
Generative AI in Workplace and
•Education
A. AI in Office Productivity
• Generative AI tools streamline repetitive and
manual office tasks using NLP and ML. Below are
key applications:
• 4. Proposal Writing
• Automated RFP responses and project proposals
• Templates integrated with company data
• Tools: ChatGPT, Jasper, ProposalKit
Generative AI in Workplace and
Education
• A. AI in Office Productivity
• Generative AI tools streamline repetitive and manual office
tasks using NLP and ML. Below are key applications:
• 5. Summarization
• Extracting key points from long documents
• Bullet-pointed summaries for meetings, PDFs, papers
• Tools: Quillbot, ChatGPT, SMMRY.
Generative AI in Workplace and
Education
• A. AI in Office Productivity
• Generative AI tools streamline repetitive and
manual office tasks using NLP and ML. Below are
key applications:
• 6. Task Automation
• Trigger-based automation (e.g., Slack + Zapier +
ChatGPT)
• Drafts, follow-ups, notification reminders
Generative AI in Workplace and
Education
• B. AI in Education
1. Content Creation
• Automatic generation of lecture notes, quizzes, MCQs
• Tools: ChatGPT, Eduaide, MagicSchool.ai
2. Summarization & Explanation
• Simplify textbook content
• Translate technical explanations into beginner-friendly language
3. Curriculum Design
• Generate semester plans, outcomes, assignments
• Use outcome-based learning formats
Generative AI in Workplace and
•Education
B. AI in Education
4. Assessment & Feedback
• Auto-grade short answers, essays, or projects
• Personalized feedback suggestions
5. Visualization (Mind Maps, Infographics)
• Convert topics into diagrams
• Tools: Canva AI, MindMeister, ChatGPT + Mermaid.js
Example Prompt: "Generate a mind map for the topic
‘Cloud Computing Architecture’."