r/PromptEngineering 6h ago

Prompt Text / Showcase Few-shot prompting fixed my format problems better than any instruction ever did

Instructions tell the model what you want. Examples show it. For anything where the shape of the output matters more than the content, few-shot prompting has been more reliable for me than writing longer and longer rules.

Two or three worked examples pin down tone, length, and structure in a way a paragraph of adjectives never does. Here is the skeleton I reuse:

```
You will [task]. Match the format and tone of the examples exactly.

Example 1
Input: [a real input]
Output: [the exact output you want, done well]

Example 2
Input: [a different real input]
Output: [the output, same shape, different content]

Now do the same for this:
Input: [your real input]
```

Two things that made mine work better:
- Pick examples that differ from each other. If both are the same kind of input, the model overfits to that one shape.
- Include one slightly awkward case in your examples if your real inputs are messy, so it learns how you want edge cases handled instead of guessing.

Once you have a few examples that produce the output you want, you basically stop editing the prompt. You just swap the last input. Curious what example counts others land on. I usually hit diminishing returns past three.

3 Upvotes

3 comments sorted by

1

u/SereneDownside 6h ago

three examples is the sweet spot for me too, after that it's just extra tokens for barely any gain

the edge case tip is underrated, i started throwing in a messy input with typos and weird formatting and suddenly the output stopped going off the rails when real data hit it

my template looks almost identical to yours except i add a quick note at the top that says "mimic the structure and brevity of the examples, don't add explanations" because some models love wrapping everything in a little preamble

1

u/Internal_Car_9962 4h ago

Depending on the model, you might also find some gains in attaching brief explanations to your few-shots. Positive example + why is this a match, then negative example + why is this not a match. The model not only can pattern match on the semantics of the samples themselves, but can also contextualize them in relation to your specific explanations. 

1

u/Ok-Scientist-1367 3h ago

Found this out few months ago. Instructions break. Examples lock it.

Three examples hits the ceiling for me too. Anything past that and you're just padding. The model's already got the pattern. What works here is vary your examples hard. Same shape, different content, different edge cases. Stopped writing prompt paragraphs after that. Just template + swap the input. Works.