Few-Shot Prompting

Few-shot prompting is the technique of including a small number of input-output examples in your prompt to teach the AI model the exact pattern, format, tone, or reasoning you want. Instead of describing what you want in abstract terms, you show the model what good output looks like. For instance, rather than saying "classify these customer reviews as positive or negative," you provide three labeled examples and then present the new review for classification. The model learns the pattern from your examples and applies it consistently. Few-shot prompting is one of the most reliable ways to control output format, enforce specific styles, and improve accuracy on classification, extraction, and transformation tasks.

The number of examples matters, but more is not always better. Research and practice suggest that two to five examples typically hit the sweet spot. One example (one-shot) establishes the format but may not capture edge cases. Two to three examples let the model distinguish the pattern from coincidence. Beyond five, you often get diminishing returns while consuming valuable context window space. The quality and diversity of your examples matter far more than quantity — choose examples that cover the range of inputs the model will encounter, including edge cases and boundary conditions. If your examples are all similar, the model may overfit to that narrow pattern and handle novel inputs poorly.

Formatting your examples consistently is critical. Use clear delimiters between the input and output (like "Input:" and "Output:" labels, or XML tags), keep the structure identical across all examples, and place your actual query at the end in the same format. Few-shot prompting combines powerfully with chain-of-thought — you can show examples that include reasoning steps, teaching the model both the thinking process and the output format simultaneously. For production use, save your best few-shot prompts as templates. The examples you curate are intellectual property — they encode your domain expertise into a reusable format that consistently produces high-quality AI outputs.

Few-Shot Prompt Examples

Copy these templates and swap in your own examples. Each one demonstrates a different few-shot pattern.

Sentiment Classification

Classify each customer review as Positive, Negative, or Neutral.

Example 1:
Review: "The shipping was fast and the product exceeded my expectations."
Label: Positive

Example 2:
Review: "Broke after two days. Complete waste of money."
Label: Negative

Example 3:
Review: "It works fine. Nothing special but does the job."
Label: Neutral

Now classify this review:
Review: "{{review_text}}"
Label:
review_text

Why it works: Three diverse examples cover each label, teaching the model the exact classification scheme and output format. The consistent structure (Review/Label) makes the pattern unambiguous.

Output Format Enforcement

Convert the following product descriptions into structured JSON. Follow this exact format:

Example 1:
Input: "Red cotton t-shirt, size medium, $24.99, currently in stock"
Output: {"name": "Red cotton t-shirt", "material": "cotton", "size": "M", "price": 24.99, "in_stock": true}

Example 2:
Input: "Blue denim jacket, size large, $89.00, sold out"
Output: {"name": "Blue denim jacket", "material": "denim", "size": "L", "price": 89.00, "in_stock": false}

Now convert:
Input: "{{product_description}}"
Output:
product_description

Why it works: The examples establish the exact JSON schema, field naming conventions, and how to handle boolean values — the model follows the same pattern for any new input.

Tone Matching

Rewrite the following messages to match our brand voice: friendly, concise, and slightly playful. Never use corporate jargon.

Example 1:
Original: "Your request has been received and is currently being processed by our team."
Rewritten: "Got it! We're on it and will have an update for you soon."

Example 2:
Original: "We regret to inform you that the item you requested is temporarily unavailable."
Rewritten: "Ah, bummer — that item's out of stock right now. We'll let you know the second it's back!"

Example 3:
Original: "Please do not hesitate to contact our support department for further assistance."
Rewritten: "Need help? Just ping us — we're here for you."

Now rewrite:
Original: "{{original_message}}"
Rewritten:
original_message

Why it works: Examples demonstrate the target tone across different situations (confirmation, bad news, CTA), giving the model a clear sense of the brand voice spectrum rather than a single data point.

Data Extraction

Extract the key details from each email and return them in a consistent format.

Example 1:
Email: "Hi, I'd like to book a meeting room for 6 people on March 15th from 2-4pm. We need a projector. Thanks, Sarah"
Extracted:
- Requester: Sarah
- Date: March 15
- Time: 2:00 PM - 4:00 PM
- Attendees: 6
- Requirements: Projector

Example 2:
Email: "Can you reserve the large conference room next Tuesday morning for our quarterly review? About 12 people. Video conferencing setup needed. - Mike"
Extracted:
- Requester: Mike
- Date: Next Tuesday
- Time: Morning
- Attendees: 12
- Requirements: Video conferencing

Now extract from this email:
Email: "{{email_text}}"
Extracted:
email_text

Why it works: The examples teach the model which fields to extract and how to normalize unstructured data into a consistent format, even when the source emails are written very differently.

Code Generation with Examples

Generate a {{language}} function based on the description. Follow the style and conventions shown in the examples.

Example 1:
Description: Check if a string is a palindrome
Function:
function isPalindrome(str: string): boolean {
  const cleaned = str.toLowerCase().replace(/[^a-z0-9]/g, '');
  return cleaned === cleaned.split('').reverse().join('');
}

Example 2:
Description: Calculate the factorial of a number
Function:
function factorial(n: number): number {
  if (n < 0) throw new Error('Negative numbers not supported');
  if (n <= 1) return 1;
  return n * factorial(n - 1);
}

Now generate:
Description: {{function_description}}
Function:
languagefunction_description

Why it works: Examples establish coding conventions — input validation, type annotations, naming style, and concise implementation. The model mirrors these patterns in generated code.

Style Transfer

Rewrite the following paragraph in the style of {{target_style}}. Study these examples first:

Example 1 — Original:
"The company released a new product today. It has several improvements over the previous version."
Rewritten in Ernest Hemingway's style:
"The product was new. It was better than the old one. That was enough."

Example 2 — Original:
"The market experienced significant volatility due to uncertainty around interest rate decisions."
Rewritten in Ernest Hemingway's style:
"The market moved. No one knew about the rates. The traders watched and waited."

Now rewrite this:
Original: "{{original_text}}"
Rewritten in {{target_style}}:
target_styleoriginal_text

Why it works: Style transfer is one of the hardest tasks to describe in words alone. Showing the model two examples of the transformation makes the target voice concrete and reproducible.