---
title: "Few-Shot Prompting: How to Write Examples for AI, and When to Stop"
description: "Few-shot prompting shows an AI a few input-to-output examples first. Learn how to write them for formats, style and classification, and the cost of too many."
url: https://cdnping.org/en/blog/few-shot-examples-prompt
language: en
published: 2026-12-05
category: "AI concepts"
tags: ["prompting","few-shot prompting","beginner guide","AI concepts"]
source: cdnping.org
license: Free to quote and summarize with a link to the url above.
---
# Few-Shot Prompting: How to Write Examples for AI, and When to Stop

Few-shot prompting means showing the AI a few "input → output" examples before you ask your real question, so it handles the new input the same way. When you can't easily put a requirement into words but can produce two or three samples that are exactly what you want, examples usually work better than adding another paragraph of instructions. For everyday tasks, a few examples are typically enough. What matters is that they share one format and cover different cases.

Below are three common scenarios, followed by what happens when you give too many examples.

## How is few-shot prompting different from just describing what you want?

Describing the requirement without examples is called zero-shot: you write only the instruction. One example is one-shot, and several are few-shot.

Say you want an AI to turn meeting notes into fixed-format items. The zero-shot version is "Turn this into a to-do list with owner and due date." The AI can do that, but it has to guess whether brackets should be full-width or half-width, and whether dates look like "10/20" or "October 20". The few-shot version pastes in one finished item, and the format is settled.

So few-shot is best for things that are hard to explain in words: format, tone, and where to draw the line on a judgment call. Rules and background belong in the instruction or system prompt instead; see [What Is a System Prompt? How to Write a Useful One](/en/blog/what-is-system-prompt).

## Scenario 1: How do you use examples to lock down output format?

Suppose you want to convert one-sentence expense notes into a single line with fixed fields. Example prompt:

```
把下面的报销说明整理成“日期 | 事项 | 金额”，没有的信息写“未提及”。
(Convert the expense note below into "date | item | amount". If something is missing, write "not mentioned".)

输入：10 月 8 日打车去客户公司，花了 46 元
输出：10月8日 | 打车去客户公司 | 46元

输入：上周请客户吃饭，发票 380
输出：未提及 | 请客户吃饭 | 380元

输入：{这里放你的真实内容}
输出：
```

(The prompt is in Chinese because the notes are Chinese. The pattern is the same in any language: Input is the raw note, Output is the formatted line, and the real content replaces the placeholder.)

Three things to watch when writing this kind of example:

1. Every example must have exactly the same format, including punctuation, spacing and how units are written. The AI imitates even these details.
2. Include a case with missing information, like the second one above. Otherwise, when information is missing, the AI may invent a date.
3. Leave the last item blank so the AI continues from there, and keep its layout aligned with the earlier examples.

## Scenario 2: How do you get an AI to imitate a writing style?

Style is the hardest thing to describe with adjectives. "Concise and punchy" or "friendly" means something different to everyone. A more reliable approach is to paste one or two passages you like and ask it to rewrite in the same voice.

```
下面是我写的两条产品更新说明，请按同样的语气和长度，把第三条改写出来。
(Below are two product update notes I wrote. Rewrite the third in the same tone and length.)

示例 1：搜索现在支持按日期筛选。找旧文件不用再一页页翻了。
(Example 1: Search now supports filtering by date. No more paging through old files.)
示例 2：导出速度变快了。几百行的表格，点一下就好。
(Example 2: Export is faster. A spreadsheet with hundreds of rows takes one click.)

待改写：修复了在部分设备上登录后白屏的问题。
(To rewrite: Fixed a blank screen after login on some devices.)
```

Two points here. First, pick examples that truly represent the style you want, not ones you grabbed at random. Second, tell the AI that it should learn the tone and length; otherwise it may copy specific wording from the examples. If the result still comes out vague, see [What to Do When AI Answers Are Too Generic](/en/blog/ai-answer-too-generic-fix).

## Scenario 3: How do you give examples for a classification task?

Classification is the most common use of few-shot prompting, for example sorting user feedback into "feature request / bug / question".

```
把用户反馈分类，只输出类别名：功能建议、故障、咨询。
(Classify the user feedback. Output only the category name: feature request, bug, question.)

反馈：希望能加一个暗色模式
类别：功能建议

反馈：点击保存没反应，刷新也一样
类别：故障

反馈：请问企业版怎么开发票？
类别：咨询

反馈：{待分类内容}
类别：
```

(Feedback 1: "I hope you add a dark mode" → feature request. Feedback 2: "Clicking Save does nothing, and refreshing doesn't help" → bug. Feedback 3: "How do I get an invoice for the enterprise plan?" → question.)

For classification examples, give at least one example per category, in roughly equal numbers. Then add one or two edge cases, such as feedback that is part suggestion and part complaint, and label them with the category you consider correct. Edge cases teach the AI your judgment standard better than typical cases do.

## What are the side effects of too many examples?

More examples are not always better. Common problems:

| Symptom | Likely cause | What to do |
|---|---|---|
| Output is nearly identical to one of the examples | Examples are too similar, or there is only one | Swap in several examples that differ more |
| A new input that is clearly different gets forced into one category | One category has noticeably more examples | Keep the number of examples per category roughly balanced |
| Format is inconsistent from run to run | Examples don't share the same format | Check punctuation and fields one by one |
| Responses get slower and cost more | Examples take up a lot of input length | Trim to the few that make the point |
| Your separately written rules are ignored | Examples contradict the written rules | Make sure the examples follow your rules |

Also, an example is itself an "answer." If one of your examples contains a mistake, the AI will faithfully learn that mistake. Check them yourself before using them.

## How do you decide whether to add examples or fix the instruction?

Work through this order:

1. Write a clear instruction on its own first and try it once.
2. If the problem is format, tone or classification standard, add 2 to 3 examples.
3. If the problem is logic or steps, have it work step by step instead; see [Making AI Think Step by Step: When It Helps and How to Write It](/en/blog/step-by-step-prompting).
4. Test with 5 to 10 real inputs, not just one.
5. If more than 5 examples still don't help, the task description itself usually has a problem. Go back and check the instruction.

For the basics of writing prompts, compare with [How to Write Prompts: A Four-Element Template Beginners Can Use](/en/blog/how-to-write-prompts-beginner). If you call a model through an API, examples usually go in the messages array as earlier "user / assistant" turns; see [What Is Chat Completions? How to Write the messages Array](/en/blog/what-is-chat-completions-api).

## Do all models respond to examples the same way?

Not necessarily. Models differ in how sensitive they are to examples: some imitate them strictly, while others lean toward following the written instruction. Which suits you is something you have to test. If you want to compare how different models do on the same kind of task, first check provider availability on the [cdnping model monitor](/en/models), then try the same prompt on each model in turn.

## What if you want to try your prompt on several models?

Tuning a few-shot prompt often means running the same set of examples against several models. AGI Plan is a commercial partner of cdnping. It is a multi-provider LLM aggregation gateway, sold as a monthly subscription, paid in RMB (Chinese yuan), with no overseas credit card needed. One subscription lets you switch among capability groups: frontier reasoning, balanced general-purpose, Chinese flagship models, and fast lightweight models. Tools like Claude Code and Codex work by changing a single endpoint address. Some models are marked "overseas only"; check the [AGI Plan models page](https://agiplan.dev/models) for specifics, and note that the service itself says it is not an officially authorized channel. To see how to connect, read the [AGI Plan getting-started page](https://agiplan.dev/startup).

You can also practice few-shot prompting without any aggregation service. The official web apps from each vendor are enough.

## Next step

Pick a small task you repeat often, such as organizing meeting to-dos or classifying feedback. Write 3 examples with the same format, including one edge case, and test them on 5 real inputs. Add the ones that came out wrong back into your examples. After two or three rounds, the prompt will be much more stable than it was at the start.
