failure-aware-enhancements-code-generation
Failure-Aware Enhancements for Code Generation
This skill equips Claude to systematically diagnose why generated code fails and select the most effective repair strategy based on failure type rather than trial-and-error. Drawing from an empirical study of 25 GitHub projects (Shen, Peng & Owen, 2026), the approach classifies code generation failures into distinct categories -- logic errors, missing edge cases, integration issues, and specification gaps -- then maps each category to the enhancement method with the highest empirical success rate: self-critique for logic errors, RAG for implementation pattern gaps, multi-model reasoning for low-confidence outputs, and progressive prompting for unclear specifications.
When to Use
- When code you generated fails tests and you need to determine the root cause before retrying
- When a user says "this code doesn't handle X correctly" and you need to decide between reviewing the logic vs. looking up documentation
- When initial code generation misses requirements and you need a structured approach to fill the gaps
- When integrating with external services (APIs, databases, third-party libraries) where self-critique alone has 0% success rate
- When a user asks you to generate a complex feature and you want to proactively avoid common failure modes
- When repeated generation attempts keep producing the same errors, signaling you need to change strategy rather than retry
Key Technique
The core insight: not all code generation failures respond to the same fix. The study found that progressive prompting raises average task completion from 80.5% to 96.9% (Cohen's d=1.63, p<0.001), but the remaining failures require targeted interventions. Self-critique works well for code-reviewable logic errors but achieves 0% improvement on external service integration failures. RAG achieves the highest completion rate across all failure types with superior efficiency. The wrong enhancement wastes tokens and time.