Back to cookbook

AI Prompt for Few-Shot Prompting to Get Consistent, Correctly Formatted Output

13 views Published

Make this prompt yours

Share

This is a few-shot prompting prompt: a template for teaching ChatGPT, Claude, or Gemini the exact output format you want by showing it two or three worked examples before asking it to handle a new case. Instead of describing the format in abstract rules ("use a table", "keep it under 50 words"), you show the model what a correct input-output pair looks like, and it pattern-matches to that structure on the next input. This is useful for anyone who needs repeatable, consistently formatted output across many similar requests — support ticket tagging, product data extraction, log classification, or any task run in a loop or pipeline where format drift breaks downstream code.

Few-shot prompting works because large language models are strong at in-context pattern completion: given a handful of consistent examples, they infer the implicit schema (field order, tone, length, delimiters) more reliably than from a written specification alone. The tradeoff is prompt length and token cost — each example adds tokens on every call — and the examples themselves have to be genuinely representative, including at least one edge case, or the model will confidently misapply the pattern to inputs that do not fit it.

Before running this at scale, it is worth checking that the few-shot examples themselves do not contain ambiguous labels or inconsistent formatting between them, since the model will faithfully copy any inconsistency it sees; running the finished prompt through Prompt Debugger will flag mismatched examples and vague output constraints before you burn a batch of API calls on a flawed pattern.

Prompt template

Make this prompt yours

prompt-template
220 tokens
Role: You are a [TASK TYPE, e.g. support ticket classifier / data extractor / content tagger]. Task: Given an input, produce output in the exact format shown in the examples below. Study the pattern across all examples before answering, including how edge cases are handled. Example 1 Input: [EXAMPLE INPUT 1] Output: [EXAMPLE OUTPUT 1] Example 2 Input: [EXAMPLE INPUT 2] Output: [EXAMPLE OUTPUT 2] Example 3 (edge case: [DESCRIBE WHAT MAKES THIS ONE TRICKY]) Input: [EXAMPLE INPUT 3] Output: [EXAMPLE OUTPUT 3] Constraints: - Match the exact structure, field names, and formatting shown above - If the new input does not clearly fit the pattern, output [FALLBACK VALUE, e.g. "UNCLEAR"] instead of guessing - Do not add commentary, explanation, or text outside the output format Now classify this new input using the same format: Input: [NEW INPUT TO PROCESS] Output:

Want it sharper? Optimize this prompt with Prompt Optimizer, check it with the Prompt Debugger or shorten it with the Token Optimizer.

Example input

example-input
230 tokens
Role: You are a customer support ticket classifier. Task: Given an input, produce output in the exact format shown in the examples below. Example 1 Input: "My card was charged twice for the same order." Output: {"category": "billing", "priority": "high"} Example 2 Input: "How do I change the email on my account?" Output: {"category": "account", "priority": "low"} Example 3 (edge case: message mentions both a bug and a billing issue) Input: "The app crashed right after I was billed, not sure if I actually got charged." Output: {"category": "billing", "priority": "medium"} Constraints: - Match the exact structure and field names shown above - If the new input does not clearly fit the pattern, output {"category": "unclear", "priority": "low"} instead of guessing - Do not add commentary, explanation, or text outside the output format Now classify this new input using the same format: Input: "I was charged for the annual plan but I only ever used the free trial." Output:

When to use it

  • You need the same output structure (JSON fields, a table, a fixed tag set) across hundreds of similar inputs run through an API or script
  • A plain instruction keeps producing inconsistent formatting, field order, or length from one run to the next
  • The task has a few tricky edge cases that are hard to describe in words but easy to show by example
  • You are building a classification or extraction step in a pipeline where downstream code parses the model's output and cannot tolerate format drift

Best practices

  • Use 2-4 examples, not one: a single example lets the model guess at a rule that does not generalize, while 2-4 examples pin down the actual pattern
  • Include at least one edge case or boundary example (an empty field, an unusual input, a tie-breaker) so the model learns the pattern's limits, not just the easy case
  • Keep every example in the identical format you want back, down to punctuation and field names, since the model copies surface formatting as literally as it copies structure
  • Order examples from simplest to most complex, and put the real input last, right after the final example, so it reads as the next item in the same list rather than a separate question

Common mistakes

  • Using only one example, which teaches a format but not its boundaries, so the model overfits to that single case
  • Writing inconsistent formatting between the examples themselves (different date formats, mismatched field names), which the model then reproduces as noise
  • Making examples too similar to each other, leaving the model to guess how to handle inputs that differ meaningfully from all of them
  • Forgetting to show the exact delimiter or wrapper (quotes, code fences, JSON braces) you want in the final answer, so the model picks its own

FAQs

What is few-shot prompting?

Few-shot prompting is a technique where you include a small number of example input-output pairs directly in the prompt before asking the model to handle a new case. The model uses those examples to infer the format, tone, and structure it should follow, rather than relying only on a written instruction.

How many examples should I use in a few-shot prompt?

Most tasks work well with 2-4 examples. One example is usually not enough because the model cannot tell which details of that single example are the actual rule versus incidental. More than 4-5 examples adds token cost without much added accuracy for most straightforward formatting tasks.

Does few-shot prompting work the same way on ChatGPT, Claude, and Gemini?

Yes, in-context learning from examples is a general capability of current large language models, so the same example-based prompt structure works across ChatGPT, Claude, and Gemini. Exact output consistency can still vary slightly between models, so it is worth testing the finished prompt on whichever model you will actually run in production.

Why does my few-shot prompt still produce inconsistent output?

This usually means the examples themselves are inconsistent with each other, too similar to cover real variation in your inputs, or missing an edge case that shows up in production. Checking that every example matches the exact structure you want, and adding one deliberately tricky example, fixes most inconsistency.

Which Cuelara tool can help me check this few-shot prompt before running it at scale?

Prompt Debugger — it scans a prompt for vague constraints, inconsistent examples, and edge cases the model is likely to mishandle, which is exactly where few-shot prompts tend to break down before a full production run.

Found this prompt useful? Share it.

Share

More in Prompt Fundamentals & Techniques

Prompt Fundamentals & Techniques

AI Prompt for ReAct (Reason + Act) Prompting to Combine Reasoning With Tool Use

A ReAct prompt (short for Reason + Act) is a prompting pattern that asks a model to alternate between explaining its reasoning and taking a…

ROLE:
You are an agent that solves tasks by alternating between reasoning and taking actions. You have access to a fixed set of tools.

AVAILABLE ACTIONS:
[LIST_OF_TOOL_NAMES_AND_WHAT_EACH_ONE_DOES]

CONTEXT:
Task: [DESCRIBE_THE_TASK_OR_QUESTION]
Constraints: [ANY_LIMITS_ON_SCOPE_TIME_OR_TOOLS]

INSTRUCTIONS:
For each step, output exactly these three labeled parts, in order:
Thought: explain what you currently know and what you need to find out or do next.
Action: name exactly one action from the available list and its input, in the format ActionName[input].
Observation: left blank for the system to fill in with the real result of the action.

Repeat the Thought-Action-Observation cycle until you have enough information to answer, or until you reach [MAX_NUMBER] cycles. If a tool call fails or returns an error, say so explicitly in the next Thought instead of inventing a result.

OUTPUT FORMAT:
When you have enough information, stop the loop and output:
Final Answer: [YOUR_ANSWER_BASED_ONLY_ON_WHAT_WAS_ACTUALLY_OBSERVED]

Make this prompt yours

Prompt Fundamentals & Techniques

AI Prompt for Chain-of-Verification (CoVe) Prompting to Reduce Hallucinations

Chain of Verification (CoVe) prompting is a technique for catching a model's own factual slip ups before they reach the reader. Instead of t…

Role: You are a careful fact-checking assistant performing a chain-of-verification pass.

Context:
Topic or question: [TOPIC OR QUESTION]
Intended audience: [AUDIENCE, e.g. internal report, public blog post, client email]

Task (follow these steps in order, showing each step separately):

Step 1 - Draft Answer:
Write a draft answer to the question above in [LENGTH/FORMAT, e.g. 150 words, bullet list].

Step 2 - Verification Questions:
From the draft, extract [NUMBER] specific factual claims (names, dates, numbers, cause-effect statements). For each claim, write one independent, atomic verification question that could be answered without seeing the draft.

Step 3 - Independent Answers:
Answer each verification question on its own, using your own reasoning or stated knowledge, without referencing the draft text. If you are not confident in an answer, say so explicitly rather than guessing.

Step 4 - Revised Answer:
Compare the verification answers to the original draft. List any contradictions found. Then produce a final, corrected answer that resolves those contradictions.

Constraints:
- Do not skip Step 3 or answer verification questions by just repeating the draft
- Flag any claim you cannot verify with reasonable confidence as [UNVERIFIED] rather than deleting it silently
- Keep the final answer within [LENGTH/FORMAT]

Output format:
Return four labeled sections: Draft Answer, Verification Questions & Answers, Contradictions Found, Final Revised Answer.

Make this prompt yours

Prompt Fundamentals & Techniques

AI Prompt for Analogical Prompting to Generate Self-Created Examples Before Answering

Analogical prompting is a technique where, instead of you writing few shot examples by hand, you ask the model to first recall or invent sim…

You are solving a problem using analogical reasoning.

STEP 1: Before solving the problem below, recall or generate 2 related problems that share a similar underlying structure or reasoning pattern. For each one, briefly state the problem and how it would be solved.

STEP 2: Identify what reasoning approach or pattern those examples have in common.

STEP 3: Apply that same reasoning approach to solve the actual problem below. Show your work step by step.

ACTUAL PROBLEM:
[YOUR QUESTION OR PROBLEM HERE]

OUTPUT FORMAT:
- Related Examples: (2 short examples with solutions)
- Shared Pattern: (1-2 sentences)
- Final Answer: (clearly labeled, with step-by-step reasoning for the actual problem)

Make this prompt yours