Prompt Engineering Tutorial menu

Examples and Few-Shot Prompting

Showing the AI a few examples of what you want is often the fastest way to get exactly that style or format.

Zero-Shot, One-Shot, Few-Shot

NameMeaning
Zero-shotOnly an instruction, no examples
One-shotAn instruction plus one example
Few-shotAn instruction plus several examples (usually 2 to 5)

Zero-shot works for simple tasks. When you need a specific pattern, examples beat long explanations.

A Few-Shot Example: Labelling Reviews

Example

text
Label each customer review as Positive, Negative or Mixed.

Review: "Delivery was quick and the shoes fit perfectly."
Label: Positive

Review: "The colour was different from the picture."
Label: Negative

Review: "Good quality, but it took 10 days to arrive."
Label: Mixed

Review: "Excellent packaging and the seller replied fast."
Label:

The model sees the pattern and continues it, answering "Positive".

Building Few-Shot Prompts in Code

When you have many items to label, you can build the prompt in a loop:

Example

python
examples = [
    ("Delivery was quick and the shoes fit perfectly.", "Positive"),
    ("The colour was different from the picture.", "Negative"),
    ("Good quality, but it took 10 days to arrive.", "Mixed"),
]
new_review = "Excellent packaging and the seller replied fast."

prompt = "Label each review as Positive, Negative or Mixed.\n\n"
for text, label in examples:
    prompt += f'Review: "{text}"\nLabel: {label}\n\n'
prompt += f'Review: "{new_review}"\nLabel:'

print(prompt.count("Review:"), "reviews in the prompt")
print(prompt.splitlines()[-1])
Output
4 reviews in the prompt
Label:

Examples for Style

Examples also teach tone and style. Suppose you want product descriptions that sound like your brand:

Example

text
Write a product description in the same style as these examples.

Example 1: "Lawn suit in mint green. Soft, breathable, made for
Karachi summers. Ready to wear in 3 days."

Example 2: "Black cotton kurta. Simple cut, strong stitching,
looks sharp at work and at Friday prayers."

Now write one for: a maroon embroidered shawl for winter weddings.

Choosing Good Examples

  • Cover the variety: include each label or case you expect (positive, negative, mixed).
  • Keep them consistent: same format in every example.
  • Make them realistic: similar to the real inputs.
  • Avoid hidden patterns: if all your positive examples are short, the model may think short means positive.
  • Do not over-do it: a few good examples usually beat twenty average ones.

If the AI keeps getting the format wrong, stop explaining and show one perfect example. It usually fixes the problem.

Examples for Formats

Few-shot is perfect when you need a strict output shape, such as one line per item:

Example

text
Turn each sentence into "Name | City | Course".

Sentence: Ayesha from Hyderabad joined the Python course.
Output: Ayesha | Hyderabad | Python

Sentence: Bilal, who lives in Quetta, is studying graphic design.
Output:

Exercise

Exercise

What is few-shot prompting?

Learn Prompt Engineering with a teacher

Join the AI & Prompt Engineering course at Workownix, online or in Orangi Town, Karachi, and get a certificate.

See the course Ask on WhatsApp