Beginner3 min readPrompt Engineering

Few-shot prompting: steer output by example

When a description leaves room for interpretation, show the model representative input-output examples and test whether they improve consistency on your task.

What you should be able to do

Examples can make an abstract requirement concrete. Use a small, representative set of input-output pairs, then test and revise it against real cases.

Saved only in this browser.
In this article

Few-shot prompting means giving a model example inputs and the outputs you want, then asking it to handle a new input. It can clarify a format, style or category boundary that a short description leaves ambiguous. Test whether it helps your task instead of treating it as a mandatory upgrade.

The GPT-3 paper studied this use of examples in context without task-specific parameter updates. That historical result does not establish a best example count for today’s models. OpenAI’s guide recommends varied input-output examples; Anthropic’s overview puts testable success criteria first.

Supply facts as well as a style

A product name alone is not enough to write an accurate product description. If the examples mention time tracking and the new name is “PromptDesk,” a model might copy the pattern by inventing features. Include the new product’s actual capabilities or mark the entire exercise fictional.

Use authorized, non-sensitive examples. Real support tickets, client drafts and invoices can disclose information before you ever reach the new input. Provider data settings do not decide whether you may share those records.

A complete example set

The following products, facts and descriptions are fictional teaching material. The outputs were authored for this article, not captured from a vendor test.

Task: Write one plain sentence describing the supplied capability.
Use only the facts given. No outcomes, integrations or users not supplied.
If capability is missing, write: “Capability missing; description not drafted.”

Example 1 input:
Name: SlotBook. Capability: lets a pottery studio publish available class places.
Example 1 output:
SlotBook lets a pottery studio publish its available class places.

Example 2 input:
Name: NoteShelf. Capability: groups personal reading notes by a user-chosen topic.
Example 2 output:
NoteShelf groups personal reading notes by a topic you choose.

Example 3 input:
Name: BrightLoop. Capability: not supplied.
Example 3 output:
Capability missing; description not drafted.

New input:
Name: PromptDesk. Capability: saves reusable text prompts with a title and tags.

A checked teaching output is: “PromptDesk saves reusable text prompts with a title and tags.” It preserves the supplied capability. “PromptDesk helps teams automate their workflow” would invent an audience and an automation feature.

The third example demonstrates a boundary as well as a style. If the model still invents a capability when one is missing, reject the output; the example has not made that behavior reliable.

Three fictional product input-output examples, including a missing-capability case, followed by a separate PromptDesk input and authored checked description.
Teach factual style and missing-data behavior with examples. Keep the new case separate, then compare its output with the supplied facts. Open the full-size diagram.

Test a case the model has not seen in the examples

Compare the plain instruction alone with the instruction plus examples. Keep a few representative new inputs aside. Check both ordinary cases and the failure that matters to you: missing facts, conflicting labels, unfamiliar wording or an input that fits no permitted category.

Do not put the test answer into the example set and then call the model’s reproduction an independent success. NIST’s generative-AI profile discusses confabulation risks; factual comparison remains necessary even when an output follows the desired shape.

For a writing task, record factual additions and the edits needed, not just whether you like the tone. For extraction, compare each required field with its source. A clean-looking JSON object still needs validation and source checks before software relies on it.

Repair the example that teaches the wrong lesson

If examples conflict, resolve the rule. If every example has a deadline, add a case with no deadline so the expected omission is visible. If the model copies a product feature into another product, separate reusable style from case-specific facts more clearly.

There is no useful universal number of examples. Start with enough to express the intended pattern and its important boundary, then add or remove examples in response to actual errors. More examples consume more context and can add conflicting patterns.

Save a tested set with its purpose, permitted input, owner and last check. The example-check worksheet keeps the example set separate from the new test cases. Recheck it when the task, model or output requirements change.

Read next

Continue through the same learning path with the next practical articles.