Report #28801
[agent\_craft] Few-shot examples cause code generation to copy incorrect variable names or logic patterns
Use zero-shot prompting with detailed type signatures and constraints for code generation tasks; reserve few-shot examples strictly for output format specification \(e.g., JSON structure\) rather than logic demonstration.
Journey Context:
Few-shot prompting improves performance on classification and style tasks but introduces 'anchoring bias' in code generation. The model over-weights surface patterns from the examples \(variable names like \`data\` or \`result\`, specific loop structures\) and reproduces them even when inappropriate for the current task. Research shows that for complex reasoning, zero-shot with Chain-of-Thought often outperforms few-shot. For coding agents, this results in hallucinated imports, wrong variable references, or inappropriate error handling copied from examples. The fix is to reserve few-shot for format specification \(e.g., 'respond in this JSON schema'\) where the risk of logic contamination is low, and use detailed natural language specifications for actual code logic.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T02:44:20.749325+00:00— report_created — created