Ready to fix a bug?
Use the Bug Fix Template to get started with a structured prompt
Jump to: When to Use | Prompt Structure | Key Considerations | Common Patterns | Troubleshooting
When to Use This Approach
- Production Defects
- Logic and Data Errors
- Integration Failures
- Race Conditions and Edge Cases
Fix issues with clear reproduction steps where expected and actual behavior diverge.
Prompt Structure
Follow the Golden Rules when writing your bug fix prompt. Focus especially on:- Reproduction Steps - Provide exact sequence to trigger the bug consistently
- Error Messages - Include complete stack traces and error output
- Behavioral Specification - Define expected vs actual behavior precisely
- Test Requirements - Specify regression tests to prevent recurrence
Key Considerations
Reproduction Steps Are Essential
Document exact steps to trigger the failure consistently. Without reliable reproduction, fixes may address symptoms rather than root causes or introduce regressions.
Expected vs Actual Behavior Clarity
Clearly state what should happen versus what actually happens. Vague descriptions like “it’s broken” lead to superficial fixes that don’t address underlying issues.
Complete Error Context Matters
Include full stack traces, error messages, and relevant log entries. Partial error information leads to misdiagnosis and ineffective fixes.
Regression Tests Prevent Recurrence
Every bug fix must include tests that fail before the fix and pass after. Without regression tests, the same bug returns during future changes.
Common Patterns
Null/undefined handling - Add null checks for database lookups, API responses, and optional parameters. Define graceful defaults or appropriate error responses when values are missing. Error boundary failures - Wrap risky operations in try/catch blocks, define specific error types for different failure modes, and ensure error messages provide debugging context without exposing sensitive data. Race condition fixes - Add proper synchronization (locks, queues), implement idempotency for operations that may be retried, and add logging to track concurrent access patterns.Troubleshooting
Fix doesn't resolve the bug
Fix doesn't resolve the bug
Root cause may be misidentified. Add more detailed logging to trace execution flow, use debugger to inspect state at failure point, and verify reproduction steps trigger the actual issue.
Tests pass but bug persists in production
Tests pass but bug persists in production
Test environment may differ from production. Review the Environment Configuration guide to align test and production environments, and add integration tests with production-like data.
Fix introduces new bugs
Fix introduces new bugs
Scope may be too broad. Add comprehensive regression tests before implementing fix, use feature flags for gradual rollout, and test against full suite of existing functionality.
Bug is intermittent and unreproducible
Bug is intermittent and unreproducible
Add detailed logging at suspected failure points, implement distributed tracing for multi-service bugs, and analyze patterns in production logs to identify triggering conditions.
Performance degrades after bug fix
Performance degrades after bug fix
Fix may be inefficient. Profile code before and after fix, add the Analyze Performance Impact rule to your project on the platform, and consider alternative implementation approaches.