RUNLOCALAIv38
->Will it run?Best GPUCompareTroubleshootStartLearnPulseModelsHardwareToolsBench
Run check
RUNLOCALAI

Independently operated catalog for local-AI hardware and software. Hand-written verdicts. Source-cited claims. Reproducible commands when we have them.

OP·Fredoline Eruo
DIR
  • Models
  • Hardware
  • Tools
  • Benchmarks
TOOLS
  • Will it run?
  • Compare hardware
  • Cost vs cloud
  • Choose my GPU
  • Prompting kits
  • Quick answers
REF
  • All buyer guides
  • Learn local AI
  • Methodology
  • Glossary
  • Errors KB
  • Trust
EDITOR
  • About
  • Author
  • How we make money
  • Editorial policy
  • Contact
LEGAL
  • Privacy
  • Terms
  • Sitemap
MAIL · MONTHLY DIGEST
Get monthly local AI changes
Monthly recap. No spam.
DISCLOSURE

Some links on this site are affiliate links (Amazon Associates and other first-class retailers). When you buy through them, we earn a small commission at no extra cost to you. Affiliate links do not influence our verdicts — there are cards we rate highly that we don't have affiliate relationships with, and cards that sell well that we refuse to recommend. Read more →

© 2026 runlocalai.coIndependently operated
RUNLOCALAI · v38
  1. >
  2. Home
  3. /Learn
  4. /Courses
  5. /Prompt Engineering Fundamentals
  6. /Ch. 4
Prompt Engineering Fundamentals

04. Few-Shot Prompting

Chapter 4 of 25 · 15 min
KEY INSIGHT

Few-shot examples teach model behavior through demonstration—but examples must be representative and consistent, not just any cases.

Few-shot prompting provides examples within the prompt. Each example demonstrates input-output pairs, showing the model how to handle your specific task. This grounds the model's behavior in your desired pattern rather than relying on inference.

The structure is: instructions + several (input → output) pairs + new input. The examples must be representative of the full range of cases you expect.

Extract the company name, revenue, and fiscal year from financial text.

Example 1:
Input: "Apple reported $394.3 billion in revenue for FY2023."
Output: {"company": "Apple", "revenue": "$394.3 billion", "fiscal_year": "FY2023"}

Example 2:
Input: "Tesla generated $96.8B in annual sales during 2024."
Output: {"company": "Tesla", "revenue": "$96.8B", "fiscal_year": "2024"}

Example 3:
Input: "Microsoft's cloud segment contributed $85.2 billion to 2023 revenue."
Output: {"company": "Microsoft", "revenue": "$85.2 billion", "fiscal_year": "2023"}

Now extract from:
Input: "Nvidia posted $60.9 billion in revenue for fiscal year 2024."

The examples show format, field names, currency notation, and fiscal year naming conventions. The model applies this pattern to the new input.

Few-shot quality depends on example selection:

  • Cover edge cases: Include examples of each category in classification tasks
  • Use realistic inputs: Synthetic examples may not match real data distribution
  • Maintain consistency: Varying format in examples teaches the model to improvise
  • Limit to 5-10 examples: More examples rarely help and increase token cost

Failure modes include:

  1. Unrepresentative examples: If you only show positive cases for classification, the model may never output negative
  2. Conflicting patterns: If examples contradict each other, the model may output inconsistent results
  3. Overfitting to examples: The model may copy example structure exactly rather than the underlying pattern
# Testing few-shot consistency
outputs = []
for trial in range(5):
    response = model.generate(prompt_with_3_examples)
    outputs.append(parse_json(response))

# Check consistency
formats = [type(o) for o in outputs]
print(f"Output types: {set(formats)}")  # Should be uniform
EXERCISE

Create a few-shot prompt for a task in your workflow. Test it with 10 diverse inputs and count how many produce correctly formatted output.

← Chapter 3
Zero-Shot Prompting
Chapter 5 →
Chain-of-Thought