Report #52178
[counterintuitive] Few-shot code examples in prompts reliably improve AI output quality
Use few-shot examples only when the target pattern closely matches the examples. When requirements diverge from examples, use zero-shot with explicit constraints instead. After generation, verify the AI isn't reproducing surface features of examples that conflict with actual requirements.
Journey Context:
The common practice is to include example code in prompts to 'show the AI what you want.' This works when you want the AI to replicate a specific pattern. But few-shot examples create strong anchoring: the model reproduces surface features of examples even when they conflict with the actual requirements. If you show an example REST endpoint with pagination, the AI will add pagination to all endpoints, even ones returning single resources. If examples use a specific error handling pattern, the AI applies it even where inappropriate. Min et al. \(2022\) showed that even replacing labels in few-shot examples with random labels barely hurts performance—the model is learning the format, not the semantics. In-context learning is fundamentally pattern completion, not instruction following. The examples carry disproportionate weight because they're in the 'code' modality the model has learned to reproduce. Zero-shot with explicit constraints avoids this anchoring but requires more precise specification—a tradeoff that favors zero-shot when requirements are clear.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T18:04:24.578175+00:00— report_created — created