#PowerPlatformTip 183: 'Anchor Few-Shot Examples in Your Prompt for Reliable AI Classification'
TL;DR: Don’t rely on a verbal rulebook for tricky classifications. Paste two to five fixed input → output pairs (few-shot examples) into your prompt. The model imitates the format and the decision boundaries you demonstrate, so it returns clean, consistent output (e.g. strict JSON) and is usually more reliable than instructions alone.
💡 Challenge
Even capable models stumble on domain classification - “Which cost center does this invoice belong to?” - when you only describe the rules in prose. The output drifts: sometimes a cost center as a number, sometimes as text, sometimes an explanation you didn’t ask for. Purely verbal instructions leave too much room for interpretation, especially on edge cases.
✅ Solution
Show, don’t just tell. Anchor a handful of few-shot examples directly in the prompt - concrete input/output pairs that demonstrate exactly what a correct answer looks like. The model pattern-matches against them, locking in both the output shape and the decision logic. It’s the single cheapest lever for reliable classification and strict output formats.
🔧 How It’s Done
1. Write the instruction, then add examples
🔸 Keep your rule/instruction short, then follow it with clearly labelled example pairs. In Prompt Builder (AI Builder) or a Copilot Studio prompt, put them straight into the prompt text.
1
2
3
4
5
6
7
8
9
10
11
12
13
Classify each purchase description into a cost center and type.
Return only JSON in this exact shape: {"costCenter": "<code>", "type": "<type>"}.
Example 1
Input: "Invoice for office furniture and desks"
Output: {"costCenter": "4020", "type": "Investment"}
Example 2
Input: "Coffee and milk for the staff kitchen"
Output: {"costCenter": "4010", "type": "Operating supplies"}
Input: <insert your input variable here>
Output:
2. Choose representative, edge-aware examples
🔸 Pick two to five examples that cover the distinctions that actually confuse the model - the boundary between “investment” and “operating supplies”, not two obvious cases. One well-chosen edge case beats three trivial ones.
3. Keep the examples consistent
🔸 Every example must use the identical output format and must never contradict another. A single inconsistent example teaches the model the wrong pattern.
4. Pass the real input as a variable
🔸 End the prompt with the live input and an empty Output: line so the model continues the demonstrated pattern. In the prompt editor, add a Text input (for example PurchaseDescription) and insert it at the position of <insert your input variable here>. Enter a sample value for the input, then select Test with realistic samples, including one edge case. For the second example above, the expected result is plain JSON without any extra text:
1
{"costCenter": "4010", "type": "Operating supplies"}
5. Switch the output to JSON
🔸 In the top-right corner of the prompt editor, change Output from Text to JSON. Open the settings icon next to Output: JSON, paste one of your example outputs as the JSON example (the format changes from Auto detected to Custom), select Apply, test again and save.
🔸 The saved format is used at runtime. In a cloud flow, the Run a prompt action then returns costCenter and type as separate dynamic content, no Parse JSON needed.
🔸 If the test shows “A JSON could not be generated”, add the instruction Don't include JSON markdown in your answer.
6. Combine with grounding when needed
🔸 Few-shot examples set the behaviour and format; a Dataverse Knowledge source (see #182) supplies the data. Use both together for classifications that depend on your business records.
🎉 Result
The model is more likely to return the format you demonstrated and applies your decision boundaries more consistently. Downstream steps (a Parse JSON, a Dataverse write) break less often on unexpected shapes, because the output shape is now demonstrated, not just described. Examples make the output more reliable, they don’t guarantee it: catch a failed generation (for example “A JSON could not be generated”) in the flow, and before you write anything, check that the combination of costCenter and type is valid against your master data, since a correctly shaped answer can still contain a cost center that doesn’t exist.
🌟 Key Advantages
🔸 Format lock-in - the model copies your exact JSON shape instead of improvising (keep the keys in English or in one language, as in the example).
🔸 Better edge-case handling - examples encode the tricky distinctions rules can’t fully spell out.
🔸 Cheap and instant - no fine-tuning, no extra services; just a few lines in the prompt.
🔸 Composable - pairs naturally with Dataverse grounding and input variables.
⚠️ Watch out: More examples aren’t automatically better - they add tokens and cost, and a contradictory or unrepresentative example actively hurts accuracy. Keep two to five clean, consistent, edge-aware pairs, and make sure none of them conflict. Also avoid putting real personal or sensitive data into static examples; use anonymized, illustrative inputs.
🎥 Video Tutorial
🛠️ FAQ
1. How many examples should I use? Usually two to five. Enough to show the format and the tricky distinctions, few enough to keep tokens and cost down. Add examples only when they cover a case the model currently gets wrong.
2. Where do I put the examples - system prompt or user input? Put them in the prompt definition itself (the instruction text in Prompt Builder or your Copilot Studio prompt), not in the runtime user input. That keeps them fixed for every call.
3. Why does my output format still drift? Usually an inconsistent example or a missing “return only JSON” instruction. Make every example use the exact same shape and state the required format explicitly.
4. Does few-shot replace grounding? No - they solve different problems. Few-shot shapes behaviour and format; grounding (#182) supplies your business data. Complex classifications often use both.
5. Can I use this in Copilot Studio and Power Automate? Yes. The same few-shot pattern works in any AI Builder prompt, whether you run it from Copilot Studio, a cloud flow or a canvas app.
🔗 Related Tips
🔸 #PowerPlatformTip 182: ‘Ground AI Builder Prompts Directly on Dataverse’ - give the prompt data; few-shot gives it behaviour.
🔸 #PowerPlatformTip 180: ‘Preload Config & User Context at Conversation Start in Copilot Studio’ - set up agent context up front.
🔸 #PowerPlatformTip 104: ‘Efficient JSON Handling’ - validate the JSON your prompt returns.
This tip is by Marcel Lehmann, Microsoft MVP (Business Applications) and founder of the Power Platform Academy, which runs free live workshops (in German). See the next free workshop dates (in German). For companies that want this implemented for them, see KMUpower: Power Platform consulting & automation for SMEs (DACH).