Few-shot prompting: Teaching AI with examples

Reading time: approx. 7 min

What you will learn

In this lesson, we dive into few-shot prompting, a powerful technique where you teach the AI model by providing concrete examples in your prompt. You will understand when and how to effectively use this method to get AI to generate more relevant and structured responses, especially when simple prompting is not enough.

The basics

Few-shot prompting means you include one to three examples of desired input and output directly in your prompt. These examples function as mini training data for AI, helping it imitate the pattern you want.

The difference between various types of prompting:

  • Zero-shot prompting: You only give an instruction without examples. AI is expected to understand the task directly.
  • One-shot prompting: You give a single example of input and desired output. Useful for steering AI toward a certain structure.
  • Few-shot prompting: You give several examples (usually 3 to 5). This strengthens the pattern and increases the chance that AI follows the intended format.

According to Lee Boonstra from Google, the most effective approach is to provide examples within a prompt, as it functions as a powerful teaching tool. A common misconception is that zero-shot, one-shot, and so on refer to how many prompts are used, but it is actually the number of examples that is meant.

Practical examples

Example 1: Summarize texts for different grade levels

You want AI to summarize a text for either middle school or high school, with adapted language and complexity.

Prompt (Few-shot):

Summarize texts adapted for different grade levels.

EXAMPLE 1:
Text: "Photosynthesis is the process where green plants use sunlight to convert carbon dioxide and water into glucose and oxygen."
Grade level: Middle school
Summary: Plants use sunlight, air, and water to make their own food, sugar. They also release oxygen that we need to breathe.

EXAMPLE 2:
Text: "The Industrial Revolution was a period of technological change that began in Britain in the late 1700s."
Grade level: High school
Summary: The Industrial Revolution started in Britain in the 1700s and involved a major shift from handmade to machine-made production. This fundamentally changed society.

YOUR TASK:
Text: "The water cycle describes how water constantly moves on Earth's surface. The sun heats water that evaporates and forms clouds."
Grade level: Middle school
Summary:

Benefits: AI gets a clear template for how summaries should look for different target audiences, reducing the need for lengthy instructions.

Example 2: Classify student answers

You want AI to help you classify student answers as correct, partially correct, or incorrect.

Prompt (Few-shot):

Classify student answers as "Correct", "Partially correct", or "Incorrect".

EXAMPLE 1:
Question: What is the capital of France?
Correct answer: Paris
Student answer: Paris
Classification: Correct

EXAMPLE 2:
Question: Briefly describe photosynthesis.
Correct answer: Process where plants convert light energy into chemical energy.
Student answer: Plants make their own food.
Classification: Partially correct

YOUR TASK:
Question: What are the three branches of government in Sweden?
Correct answer: Parliament, government, courts
Student answer: Parliament and the king.
Classification:

Benefits: AI learns to understand nuances in student answers and classifies them more consistently according to your criteria.

Implementation in the classroom

  1. Formative assessment: Let students use few-shot prompting to get quick feedback on shorter texts. Give them examples of what good answers look like.

  2. Language development: Ask AI to generate sentences in a certain style. Provide 2 to 3 examples of the style and then ask AI to continue or create something new in the same style.

  3. Problem solving: When students work with problems that require specific solution steps, you can give AI examples of the problem and its solution. Then ask AI to guide the student through a new, similar problem.

Next steps

Few-shot prompting is fundamental for steering AI responses. In the next lesson, we will explore how you can give AI overarching instructions and frameworks to ensure it follows set guidelines throughout the entire interaction.