fixaiprompt
All techniques
Glossary · Technique

Few-Shot Prompting

Also known as: In-context learning, k-shot

Show the model 2–5 examples of input → desired output before asking. Consistently the highest-ROI prompt move in real-world AI work.

When to use it

  • Any task where the desired output has a specific shape, voice, or format.
  • Anything generative — writing, code, JSON, summaries.
  • Where the failure mode is 'the answer is correct but in the wrong format'.
  • When a single descriptive instruction isn't getting the structure you want.

When not to use it

  • Simple factual questions — examples add noise without value.
  • When token budget is tight and the task is easy.
  • When the examples themselves bias the model into one of N answers you don't want.

How it works

  1. 1Provide 2–5 examples directly in the prompt, each showing INPUT → OUTPUT.
  2. 2The model treats these as the implicit pattern to follow.
  3. 3More examples = better adherence, but diminishing returns past ~5 examples for most tasks.
  4. 4Example variance matters: examples should cover edge cases, not all be near-duplicates.

Example

Lazy prompt
Convert this sentence to formal English: i wanna go home
Using the technique
Convert sentences to formal English.

Informal: i'm gonna grab lunch
Formal: I'm going to have lunch shortly.

Informal: u busy rn?
Formal: Are you available at the moment?

Informal: nah it ain't working
Formal: Unfortunately, it is not functioning.

Informal: i wanna go home
Formal:

Common pitfalls

  • Bad examples = bad output. Quality > quantity.
  • If examples are too similar, the model rigidly follows the pattern even when it shouldn't.
  • Long examples push the actual question to the back of context and can be ignored.

Where this came from

Brown et al., 2020 — GPT-3 paper formalized 'in-context learning' as the dominant zero/few-shot paradigm.