Home Knowledge Base Contrastive examples

Contrastive examples in prompt engineering is the technique of providing the language model with both positive (correct) and negative (incorrect) demonstrations — showing not just what good output looks like, but also what bad output looks like and why, enabling the model to learn sharper decision boundaries for the target task.

Why Contrastive Examples Work

Contrastive Example Format

Good example:
Input: "The battery lasts all day"
Label: Positive
Why: Describes a desirable product feature.

Bad example:
Input: "The battery lasts all day"
Label: Negative
Why WRONG: Despite mentioning "lasts," this is a
positive statement about battery life, not negative.

When to Use Contrastive Examples

Contrastive Prompting Strategies

Benefits

Practical Tips

Contrastive examples are a high-impact prompt engineering technique — by teaching the model what to avoid alongside what to produce, they create sharper, more discriminating few-shot learners.

contrastive examplesprompt engineering

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.