New Tool Radar

AI Concepts

How to Give a Model Few-Shot Examples to Fix Its Output Format

Give a model two or three few-shot examples of the format you want, and it will copy the pattern.

Schematic illustration of give a model few-shot examples to fix its output format: step one pick two examples, step two show input and output, step three test with a new input.

Few-shot prompting means showing the model examples of the task before asking it to do the task: two or three input-and-output pairs that demonstrate the format you want. The model copies the pattern from the examples, which is often more reliable than describing the format in words. Use it when the output format matters and a description alone keeps failing.

Prerequisites

  • Two or three examples of the task, with correct outputs.
  • The format you want, shown in the examples rather than described.
  • A new input to test the pattern on.

Steps

Step 1: Pick two examples

Pick two examples that cover the range of the task: one simple case and one edge case. Two good examples beat five similar ones.

Step 2: Show input and output

Write each example as an input followed by its output, in the exact format you want: same labels, same order, same punctuation. The model copies what it sees, including mistakes, so check the examples first.

Step 3: Test with a new input

Send the examples with a new input and read the output. It should follow the same format. If it does not, the examples may be inconsistent; fix the examples, not the description.

Worked example: Harbor Light library catalogue entries

The fictional Harbor Light library shows a model two catalogue entries in the format ‘Title – Author (Year)’, then asks for a third.

Input Output shown Format followed
Book 1: The Salt Road The Salt Road – M. Ferreira (2024) Yes
Book 2: Baking with Rye Baking with Rye – A. Novak (2023) Yes
New: The Long Winter The Long Winter – S. Adeyemi (2025) Yes

The model formats the new book as ‘The Long Winter – S. Adeyemi (2025)’, copying the pattern from the two examples.

Expected result. The model’s output follows the format shown in the examples, with the same labels and order. UNTESTED: this guide was not run against a live model or API. The worked example below is fictional practice material, and its result is the expected result, not a measured one.

Limits

  • Examples teach format, not facts; a wrong fact in an example will be copied too.
  • Too many examples waste context; two or three is usually enough.
  • This guide does not cover zero-shot prompting, where no examples are given.

Sources

See all