Skip to content
few-shot-prompting logo

Few-Shot Prompting Skill

few-shot-prompting

Example-based prompting techniques for in-context learning

SKILL.md

Full skill instructions

Few-Shot Prompting Skill

Bonded to: few-shot-specialist-agent


Quick Start

Skill("custom-plugin-prompt-engineering:few-shot-prompting")

Parameter Schema

parameters:
  shot_count:
    type: integer
    range: [0, 20]
    default: 3
    description: Number of examples to include

  example_format:
    type: enum
    values: [input_output, labeled, conversational, structured]
    default: input_output

  ordering_strategy:
    type: enum
    values: [random, similarity, difficulty, recency]
    default: similarity

Shot Strategies

StrategyExamplesBest ForTrade-offs
Zero-shot0Simple, well-defined tasksFast but less accurate
One-shot1Format demonstrationMinimal context usage
Few-shot2-5Pattern learningBalanced accuracy/​tokens
Many-shot6-20Complex classificationsHigh accuracy, high tokens

Core Patterns

1. Standard Input-Output

[Task instruction]

Example 1:
Input: [example_input_1]
Output: [example_output_1]

Example 2:
Input: [example_input_2]
Output: [example_output_2]

Example 3:
Input: [example_input_3]
Output: [example_output_3]

Now process:
Input: [actual_input]
Output:

2. Labeled Classification

Classify the following text into categories: [category_list]

"[text_1]" → [category_1]
"[text_2]" → [category_2]
"[text_3]" → [category_3]

"[new_text]" →

3. Structured Output

Extract information in the specified format.

Text: "John Smith, CEO of TechCorp, announced the merger on Monday."
Output: {"name": "John Smith", "title": "CEO", "company": "TechCorp", "action": "announced merger", "date": "Monday"}

Text: "Dr. Sarah Chen presented findings at the 2024 AI Conference."
Output: {"name": "Sarah Chen", "title": "Dr.", "event": "2024 AI Conference", "action": "presented findings"}

Text: "[new_text]"
Output:

4. Chain-of-Thought Few-Shot

Solve the following problems showing your reasoning.

Problem: If a shirt costs $25 and is on 20% sale, what's the final price?
Reasoning: 20% of $25 = $25 × 0.20 = $5 discount. Final price = $25 - $5 = $20.
Answer: $20

Problem: [new_problem]
Reasoning:
Answer:

Example Selection Criteria

selection_criteria:
  diversity:
    coverage: "Include all output classes/​categories"
    variation: "Vary input complexity and length"
    edge_cases: "Include at least one boundary case"

  quality:
    correctness: "All examples must have correct outputs"
    clarity: "Examples should be unambiguous"
    representativeness: "Reflect real-world distribution"

  relevance:
    similarity: "Examples similar to expected inputs"
    domain: "Match the target domain/​context"
    recency: "Use recent examples for time-sensitive tasks"

Ordering Strategies

StrategyImplementationWhen to Use
Similarity-basedMost similar to input lastRetrieval-augmented systems
Difficulty gradientSimple → ComplexLearning/​educational tasks
RandomShuffled orderReduce position bias
RecencyMost recent lastTime-sensitive tasks
Reverse-difficultyComplex → SimpleEmphasize simple patterns

Token Optimization

optimization_techniques:
  concise_examples:
    description: "Use minimal but complete examples"
    savings: "~25%"
    example:
      verbose: "The customer said 'This product is amazing!' which expresses positive sentiment"
      concise: "'Amazing product!' → positive"

  shared_prefix:
    description: "Factor out common instructions"
    savings: "~15%"
    implementation: "Move repeated text to instruction section"

  dynamic_loading:
    description: "Only load relevant examples"
    savings: "~40%"
    implementation: "Use semantic search to select examples"

Validation

validation_checklist:
  format:
    - [ ] All examples use identical structure
    - [ ] Separators are consistent
    - [ ] Input/​output markers are clear

  content:
    - [ ] Examples cover all output categories
    - [ ] No duplicate examples
    - [ ] Edge cases included

  quality:
    - [ ] All outputs are correct
    - [ ] No example leakage (test data in examples)
    - [ ] Complexity is varied

Troubleshooting

IssueCauseSolution
Model copies examplesOverfittingAdd more diverse examples
Wrong formatInconsistent examplesStandardize all formats
Missing categoriesImbalanced examplesBalance class distribution
Poor accuracyToo few examplesIncrease shot count
Token overflowToo many examplesReduce count, improve quality

Integration

integrates_with:
  - prompt-design: Base prompt structure
  - chain-of-thought: Reasoning examples
  - prompt-evaluation: Test effectiveness

combination_example: |
  # Few-shot + CoT
  [Instruction]

  Example 1:
  Input: [problem]
  Reasoning: [step-by-step]
  Output: [answer]

  Example 2: ...

References

See references/​GUIDE.md for example selection strategies. See assets/​config.yaml for configuration options.

More Other skills

Delegate independent tasks to specialized agents working concurrently with isolated context.

295.4K 206.3K
View

Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.

179.7K 100.1K
View

Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with colors/fonts that you can apply to any artifact that has been creating, or can generate a new theme on-the-fly.

179.7K 89.5K
View

A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill whenever asked to write some sort of internal communications (status reports, leadership updates, 3P updates, company newsletters, FAQs, incident reports, project updates, etc.).

179.7K 76.1K
View

Fundamental design principles for writing maintainable, testable Python code.

40.2K 21.9K
View

Modern responsive layouts using container queries, fluid typography, CSS Grid, and mobile-first strategies.

40.2K 20K
View

Generate Playwright tests from scenarios using interactive browser exploration and validation.

39.7K 18.2K
View

Modern React state management with Redux Toolkit, Zustand, Jotai, and React Query for every state category.

40.2K 14.7K
View

GDPR-compliant data handling with consent management, data subject rights, and privacy controls.

40.2K 14.3K
View

Python error handling patterns including input validation, exception hierarchies, and partial failure handling. Use when implementing validation logic, designing exception strategies, handling batch processing failures, or building robust APIs.

40.2K 13.5K
View

Detailed multi-file refactor planning with safety checks and rollback guidance.

39.7K 13K
View