Example-based (few-shot)

Point to an existing pattern and ask for the same thing, adapted.

Draft: open for discussionAlso known as: few-shot, pattern-following, do it like this

Definition

Instead of describing the solution, you show it: an existing component, test or module that already follows the house style. Then you ask for the new thing in the same shape. It relies on knowing the codebase well and is the fastest route to consistent code.

Example prompt

Example-based (few-shot)
Look at src/components/ProductSlider.tsx and its test.Build src/components/HomeCarousel.tsx following the same patterns:the same data-fetching hook, the same <LazyImage /> component,the same test layout.Differences: 5 images from the `images` table, 5s interval,flash twice on transition.

What it reveals

  • Knowledge of the codebase and its conventions
  • Focus on consistency and maintainability
  • Ability to pick a good reference, not just any similar file

Use it when

  • Adding one more of something that already exists
  • Keeping conventions in a large codebase
  • Migrations repeated across many files

Watch out for

  • Copying the reference's bugs and tech debt
  • Picking an outdated example
  • Forcing a pattern onto a problem it does not fit

In an interview

Look for

  • Why that reference? Is it the best example in the codebase?
  • Does the candidate state the differences explicitly?

Ask

  • What would make ProductSlider a bad reference here?
  • What did the model copy that it should not have?

Origin

From few-shot prompting: giving a model a few examples of a task inside the prompt. The term was established by Brown et al. in "Language Models are Few-Shot Learners", the GPT-3 paper (2020).

Tom B. Brown et al.May 28, 2020

Sources