Report #40682
[agent\_craft] Agent provides 5\+ similar examples for coding tasks, causing the model to hallucinate irrelevant patterns from the examples instead of following the current context
Use at most 2-3 few-shot examples for code generation, and ensure they are maximally diverse in syntax style and problem domain \(e.g., one functional, one OOP; one string manipulation, one numeric\). If examples must be similar, use zero-shot with a detailed specification instead.
Journey Context:
The common misconception is that 'more examples = better performance' for in-context learning. However, for code generation, too many examples cause the model to overfit to superficial patterns in the examples \(variable naming conventions, specific library choices, structural boilerplate\) that conflict with the actual user request. Research shows that example diversity \(coverage of the solution space\) is significantly more important than raw count for code tasks. Beyond 3 examples, marginal gains are negative due to context dilution and pattern hallucination. Two high-diversity examples provide sufficient pattern guidance without overwhelming the model's ability to adapt to novel requirements in the current prompt.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T22:45:17.575221+00:00— report_created — created