Applied AI & Prompt Engineering · Module 2: Prompt Engineering Fundamentals · Lesson 15 of 55

One-Shot Prompting: Guide AI with One Example

One-Shot Prompting

One-shot prompting is a prompting technique in which an AI model is given one example of the desired task before being asked to perform the task on new input.

The example demonstrates the expected relationship between the input and output. The AI then uses that example as a pattern for generating the response to the actual task.

Simple Definition:

One-shot prompting means providing one example to demonstrate how AI should perform a task.

Why Is It Called "One-Shot"?

The term one-shot refers to the number of examples provided to the model.

Technique Number of Examples Basic Idea
Zero-Shot 0 Describe the task without an example.
One-Shot 1 Provide one example of the desired behavior.
Few-Shot 2 or more Provide multiple examples to demonstrate a pattern.

Basic One-Shot Prompt

Consider a sentiment classification task.

Classify the sentiment as Positive or Negative.

Example:
Review: "The application is very easy to use."
Sentiment: Positive

Now classify:
Review: "The application frequently crashes."
Sentiment:

One example has been supplied. The AI can infer that the expected output is a sentiment label.

One-Shot vs Zero-Shot

Zero-Shot

Classify the following review as Positive or Negative:

"The software is difficult to use."

One-Shot

Classify the following review as Positive or Negative.

Example:
Review: "The software is easy to use."
Sentiment: Positive

Review:
"The software is difficult to use."

Sentiment:

The one-shot version provides an example that demonstrates the expected classification pattern.

One-Shot Prompting for Output Format

One example can demonstrate a specific output structure that may be difficult to describe using instructions alone.

Convert the information into a structured summary.

Example:

Input:
Python is a programming language used for
web development, automation, and data science.

Output:
Topic: Python
Type: Programming Language
Uses: Web Development; Automation; Data Science

Now process this:

Input:
JavaScript is widely used to create interactive
web pages and web applications.

Output:

The example demonstrates not only the content to extract but also the exact style of the desired output.

One-Shot Classification

One-shot classification is useful when the categories have specialized meanings that may not be obvious from their names.

Classify each student request as:
Academic, Technical, or Administrative.

Example:
Request: "I cannot access the school ERP."
Category: Technical

Now classify:
Request: "I need to change my examination subject."
Category:

The example clarifies how a particular type of request should be categorized.

One-Shot Text Transformation

One-shot prompting can demonstrate how text should be rewritten.

Rewrite informal messages in professional language.

Example:

Input:
"Can you send me the report ASAP?"

Output:
"Please send me the report at your earliest convenience."

Now rewrite:

Input:
"Please check this file and tell me if anything is wrong."

Output:

One-Shot Summarization

An example can demonstrate how detailed or concise the desired summary should be.

Summarize each passage in one sentence.

Example:

Passage:
"Cloud computing allows organizations to access
computing resources over the internet instead of
maintaining all infrastructure locally."

Summary:
Cloud computing provides internet-based access
to computing resources without requiring all
infrastructure to be maintained locally.

Now summarize:

Passage:
"Artificial intelligence can analyze large datasets
and identify patterns that may be difficult for
humans to detect."

Summary:

One-Shot Question Generation

One example can establish the style and difficulty of generated questions.

Generate examination questions in the following style.

Example:

Topic: Python Lists
Question: Differentiate between append() and extend()
with suitable examples.
Difficulty: Intermediate

Now create a question for:

Topic: Python Dictionaries
Question:
Difficulty:

One-Shot Prompting for Education

Teachers can use one-shot prompting when they want AI-generated content to follow a particular classroom or examination style.

Create questions for Class XI Computer Science.

Example:

Question:
What is a Python list? Give one example.

Answer:
A list is an ordered, mutable collection in Python.
Example: numbers = [10, 20, 30]

Now create five questions about dictionaries
using the same question-and-answer style.

The example establishes the expected depth, wording style, and answer structure.

One-Shot Prompting for Examination Questions

One-shot prompting can be particularly useful when an institution follows a specific question style.

Create application-based Computer Science questions.

Example:

Question:
A school stores student marks in a Python list.
Write a program to find the highest mark.

Now create five application-based questions
on Python dictionaries using the same style.

Do not repeat the example.

One-Shot Prompting for Coding

A single code example can demonstrate the expected programming style.

Write Python programs using simple functions.

Example:

Task:
Calculate the square of a number.

Solution:
def square(n):
    return n * n

print(square(5))

Now write a program to calculate
the cube of a number using the same style.

The example demonstrates the preferred structure, use of functions, and level of simplicity.

One-Shot Prompting for PHP/MySQL

Developers can provide one example to establish the preferred coding pattern.

Use PHP PDO and prepared statements for database queries.

Example:

$stmt = $pdo->prepare(
    "SELECT * FROM students WHERE class = ?"
);
$stmt->execute([$class]);
$students = $stmt->fetchAll(PDO::FETCH_ASSOC);

Now write a similar query to retrieve students
from a specified section.

Use the same coding style.

One-Shot Prompting for Data Analysis

A sample analysis can demonstrate how the findings should be presented.

Analyze the supplied student performance data.

Example:

Subject: Mathematics
Average: 78.5
Observation: Performance is generally strong,
but 12% of students scored below 50.

Now analyze the English data using the same format.

Subject:
Average:
Observation:

One-Shot Prompting for Research

Summarize research findings using this format.

Example:

Finding:
AI tools can reduce the time required for
certain repetitive tasks.

Evidence:
The study reports measurable time savings
for the evaluated tasks.

Limitation:
The findings may not generalize to every
educational context.

Now summarize the next finding using
the same structure:

[PASTE RESEARCH TEXT]

One-Shot Prompting for Business

Summarize project risks using this format.

Example:

Risk:
Delayed vendor delivery.

Impact:
The project launch may be delayed.

Action:
Confirm the delivery schedule and identify
an alternative supplier.

Now analyze the following project risk
using exactly the same structure:

[PASTE RISK]

One-Shot Prompting for Tone

One example can help demonstrate the desired writing tone.

Rewrite school announcements in a
professional but warm tone.

Example:

Input:
"Tomorrow's workshop is cancelled."

Output:
"Please note that tomorrow's workshop has
been cancelled. A revised schedule will be
shared shortly."

Now rewrite:

Input:
"The computer lab will remain closed tomorrow
because of maintenance."

Output:

One-Shot Prompting for Formatting

The example can establish formatting rules without requiring a long explanation of every formatting detail.

Format programming concepts like this:

Example:

Concept: Python List
Definition: An ordered and mutable collection.
Example: numbers = [10, 20, 30]

Now format:

Concept: Python Dictionary
Definition:
Example:

One Example Can Demonstrate Multiple Things

A well-designed example can simultaneously communicate content structure, tone, level of detail, formatting, and expected reasoning pattern.

Example Can Demonstrate What AI Can Infer
Format How the answer should be organized.
Tone How formal, friendly, concise, or technical the response should be.
Level How detailed or advanced the answer should be.
Pattern How similar inputs should be processed.
Terminology Which style of language should be used.

Example Quality Matters

Because the model is expected to infer a pattern from the example, the example should be representative of the desired output.

Practical Rule:

A poor example can teach the wrong pattern. Before using one-shot prompting, make sure the example accurately represents the desired task, structure, and quality level.

Good One-Shot Example

Example:

Input:
"The website loads slowly on mobile devices."

Category:
Performance

The example clearly connects the input to the expected category.

Weak One-Shot Example

Example:

Input:
"The website has a problem."

Category:
Performance

The relationship is ambiguous because the example does not clearly demonstrate why the category is "Performance."

One-Shot Prompting with Constraints

One-shot prompting can be combined with the constraints learned in Lesson 2.7.

Generate short revision notes.

Example:

Topic:
Python List

Definition:
An ordered and mutable collection of items.

Key Point:
Lists can contain duplicate values.

Now create notes for:

Topic:
Python Dictionary

Constraints:
- Use exactly two key points.
- Keep the definition under 30 words.
- Use beginner-friendly language.

One-Shot Prompting with Output Format

An example can establish the output format while additional instructions define the task.

Explain programming concepts using this format.

Example:

Concept: Variable
Definition: A named location used to store a value.
Example: age = 16

Now explain:
Concept: Function

Use exactly the same format.

One-Shot Prompting with Context

Context can be supplied in addition to the single example.

Context:
The students are Class IX beginners.

Example:

Topic: Python Variable
Explanation:
A variable stores a value that can be used
later in a program.

Now explain:

Topic: Python Conditional Statement

Use language and detail appropriate for
the same students.

Complete One-Shot Prompt

The techniques from previous lessons can be combined with one example to create a highly controlled prompt.

ROLE:
Act as an experienced Computer Science teacher.

CONTEXT:
The students are Class XI beginners.

TASK:
Create revision notes for a Python concept.

EXAMPLE:

Topic: Python List

Definition:
An ordered and mutable collection of items.

Example:
numbers = [10, 20, 30]

Key Point:
Lists can be modified after creation.

NOW CREATE:

Topic: Python Dictionary

REQUIREMENTS:
- Include definition.
- Include one code example.
- Include one key point.

CONSTRAINTS:
- Beginner-friendly.
- Keep the response concise.

OUTPUT:
Follow exactly the structure demonstrated
in the example.

This is still a one-shot prompt because exactly one example is supplied.

When Should You Use One-Shot Prompting?

One-shot prompting is useful when a task is understandable but the desired pattern is difficult to communicate through instructions alone.

Situation Why One-Shot Helps
Custom output format The example demonstrates the structure.
Specific writing tone The example shows the desired style.
Specialized classification The example clarifies category interpretation.
Question style The example demonstrates wording and difficulty.
Coding style The example establishes preferred implementation patterns.
Text transformation The example demonstrates how input should be transformed.

When Is Zero-Shot Better?

If the task is straightforward and can be explained clearly, providing an example may be unnecessary.

Task Likely Approach
Simple translation Zero-shot may be sufficient.
Basic summarization Zero-shot may be sufficient.
Standard explanation Zero-shot may be sufficient.
Custom classification One-shot may be useful.
Specific output pattern One-shot may be useful.
Special writing style One-shot may be useful.

One-Shot vs Few-Shot Prompting

The main difference is the number of demonstrations provided.

Feature One-Shot Few-Shot
Examples One Multiple
Prompt size Usually smaller Usually larger
Pattern demonstration Single demonstration Multiple demonstrations
Useful when One clear example is sufficient The pattern has multiple variations

Advantages of One-Shot Prompting

Advantage Explanation
Demonstrates the task The example provides concrete guidance.
Controls format The output pattern can be demonstrated directly.
Clarifies ambiguity The example can explain what a category or instruction means.
More efficient than many examples Only one demonstration is required.
Easy to create Users need to prepare only one representative example.

Limitations of One-Shot Prompting

Limitation Explanation
One example may be insufficient A complex task may have many possible patterns.
Poor example The model may infer an undesirable pattern.
Example ambiguity The relationship between input and output may be unclear.
Limited coverage One example cannot demonstrate every possible case.
Accuracy An example does not guarantee that the resulting answer is correct.

Best Practices for One-Shot Prompting

  1. Use a representative example.
  2. Make the input-output relationship clear.
  3. Ensure the example is correct.
  4. Keep the example relevant to the task.
  5. Demonstrate the desired format clearly.
  6. Avoid unnecessary information in the example.
  7. Add constraints when the example alone is insufficient.
  8. Specify the target audience when necessary.
  9. Test the prompt with different inputs.
  10. Use few-shot prompting when one example cannot adequately demonstrate the pattern.

Common Mistakes

Mistake Problem Better Approach
Unclear example AI may not understand the intended pattern. Use a clear input-output pair.
Incorrect example The example may demonstrate incorrect behavior. Verify the example before using it.
Unrepresentative example One unusual case may not represent the general task. Choose a typical case.
Example contradicts instructions The model receives conflicting signals. Keep instructions and example consistent.
Too much irrelevant information The important pattern becomes less clear. Keep the demonstration focused.

Practical Activity 1 — Convert Zero-Shot to One-Shot

Start with this zero-shot prompt:

Classify the following school feedback as
Positive, Negative, or Neutral:

"The new laboratory is excellent."

Convert it into a one-shot prompt by adding one example that demonstrates the expected classification format.

Practical Activity 2 — One-Shot Question Generation

Create one example of a Class XI Computer Science question and answer.

Then ask AI to generate five additional questions following the same style and difficulty.

Practical Activity 3 — One-Shot Coding

Provide AI with one simple Python function and ask it to create another function using the same coding style.

Compare the generated code with the original example.

Practical Activity 4 — One-Shot Formatting

Create one example showing how a programming concept should be formatted as:

  • Concept
  • Definition
  • Example
  • Key Point

Ask AI to generate five more concepts using the same structure.

Practical Activity 5 — Education Use Case

Create a one-shot prompt that demonstrates your preferred format for generating examination questions.

Ask AI to generate 10 new questions following the demonstrated pattern.

Practical Activity 6 — Compare Zero-Shot and One-Shot

Give the same task to an AI system twice:

  1. Using a zero-shot prompt.
  2. Using a one-shot prompt.

Compare the outputs for:

  • Format consistency
  • Level of detail
  • Tone
  • Task alignment
  • Consistency with the example

Interview Questions

Q1. What is one-shot prompting?

One-shot prompting is a technique in which one example is provided to demonstrate the desired task or output pattern.

Q2. How is one-shot prompting different from zero-shot prompting?

Zero-shot prompting provides no task examples, while one-shot prompting provides exactly one example.

Q3. What can an example demonstrate?

An example can demonstrate output format, tone, classification behavior, level of detail, terminology, or a transformation pattern.

Q4. Why is the quality of the example important?

The AI may use the example as a pattern. An incorrect or unrepresentative example can therefore lead to undesirable output.

Q5. Can one-shot prompting include constraints?

Yes. One-shot prompting can be combined with instructions, context, constraints, and output-format requirements.

Q6. When is one-shot prompting useful?

It is useful when the desired pattern is easier to demonstrate with an example than to describe entirely through instructions.

Q7. What is a limitation of one-shot prompting?

One example may not adequately represent all variations of a complex task.

Q8. Can one-shot prompting guarantee correct output?

No. The example can guide the model, but it does not guarantee factual or technical correctness.

Q9. What should a good one-shot example contain?

It should contain a clear input and an appropriate output that accurately demonstrates the intended pattern.

Q10. When might few-shot prompting be preferable?

Few-shot prompting may be preferable when multiple examples are needed to demonstrate different cases or variations of a task.

Examination MCQs

Q1. How many examples are provided in one-shot prompting?

  1. Zero
  2. One
  3. Five
  4. Ten

Answer: B

Q2. What is the purpose of the example in one-shot prompting?

  1. To demonstrate the desired task or output pattern
  2. To increase computer memory
  3. To install software
  4. To connect to a database

Answer: A

Q3. Which technique provides no examples?

  1. One-shot prompting
  2. Few-shot prompting
  3. Zero-shot prompting
  4. Example prompting

Answer: C

Q4. What can one example demonstrate?

  1. Output format
  2. Tone
  3. Classification pattern
  4. All of the above

Answer: D

Q5. What can happen if the example is incorrect?

  1. The AI may learn an undesirable pattern from it.
  2. The computer will automatically shut down.
  3. The internet connection will improve.
  4. The database will be deleted.

Answer: A

Q6. Can constraints be used with one-shot prompting?

  1. Yes
  2. No
  3. Only for coding
  4. Only for education

Answer: A

Q7. When might few-shot prompting be better?

  1. When multiple examples are needed to demonstrate variations
  2. When no task is defined
  3. When no output is required
  4. When the prompt is empty

Answer: A

Q8. Which is an example of one-shot prompting?

  1. Providing one input-output example before the actual task
  2. Providing no instructions
  3. Providing ten examples
  4. Providing only a topic name

Answer: A

Q9. Which is important when selecting a one-shot example?

  1. It should be representative and correct.
  2. It should be unrelated to the task.
  3. It should be intentionally ambiguous.
  4. It should contain contradictory instructions.

Answer: A

Q10. Does one-shot prompting guarantee accurate output?

  1. Yes
  2. No
  3. Only for Python
  4. Only for tables

Answer: B

Key Terms

Term Meaning
One-Shot Prompting Providing one example to demonstrate how AI should perform a task.
Demonstration An example showing the relationship between an input and an expected output.
Input-Output Pair A task example containing an input and its desired output.
Pattern A recurring structure or behavior demonstrated by the example.
Zero-Shot Prompting Performing a task without providing task examples.
Few-Shot Prompting Providing multiple examples to demonstrate a task or pattern.

Self-Assessment Checklist

  • ☐ Define one-shot prompting.
  • ☐ Explain why it is called one-shot.
  • ☐ Distinguish one-shot from zero-shot prompting.
  • ☐ Create one-shot classification prompts.
  • ☐ Create one-shot summarization prompts.
  • ☐ Create one-shot text transformation prompts.
  • ☐ Create one-shot coding prompts.
  • ☐ Use one example to demonstrate output formatting.
  • ☐ Combine examples with constraints.
  • ☐ Combine examples with context and instructions.
  • ☐ Select representative examples.
  • ☐ Identify problems caused by poor examples.
  • ☐ Explain when few-shot prompting may be preferable.
  • ☐ Build reusable one-shot prompt templates.

Key Takeaway

One-shot prompting provides one example to demonstrate the desired task, behavior, or output pattern. The AI can use that example together with the instructions and context to generate the requested result.

Task + One Demonstration + Instructions → One-Shot Prompt

One-shot prompting is particularly useful when the desired format, tone, classification rule, coding style, or transformation pattern is easier to demonstrate than to describe. The example should be accurate, clear, and representative of the desired result.