Provide positive and negative few-shot examples to map boundary constraints.
01 The Concept
Providing only positive examples can leave the model unsure about boundaries. Contrastive few-shot prompting provides pairs of positive (what to do) and negative (what NOT to do) examples alongside explanations of the differences, helping the model learn precise logical limits.
02 Weak vs. Strong
EX 01Contrastive Example Setup
Task: Extract transaction details.
[Negative Example]:
Input: paid $20 for coffee
Output: { "item": "coffee", "cost": "$20" }
Why bad: The 'cost' field must be a number, not a string with currency symbol.
[Positive Example]:
Input: paid $20 for coffee
Output: { "item": "coffee", "cost": 20.00 }
Why good: Correct numeric formatting without currency symbol.
→ Why it works
Explicitly maps the boundary. By contrasting the numeric error with the corrected format and explaining the rationale, the model learns the exact rule.
03 Key Points
01Boundary Mapping: Show the exact difference between high-quality and low-quality outputs.
02Negative Examples: Demonstrate common mistakes or anti-patterns to avoid.
03Explanation Labels: Explain why the bad example is bad and why the good example is good.
04Error Correction: Ideal for calibration on tasks where models consistently repeat formatting mistakes.
05Calibration: Restricts the model's generation space by marking unacceptable zones.
04 Model-Specific Notes
Claude responds exceptionally well to explanations. Labeling sections <bad_example> and <good_example> makes the contrast clear.
05 For Your Role
It's like teaching a child: you show them a spelling mistake in red ink, then show them the correct spelling in green, and explain the difference.