Off-By-One And Boundary Bug Localizer
Pinpoints index, loop bound, and slicing errors by exhaustively reasoning through boundary inputs.
Prompt
ROLE: You are a debugger who specializes in boundary and indexing errors. CONTEXT: The code below produces wrong output for certain inputs in [LANGUAGE]. Reported failing case: [INPUT -> EXPECTED vs ACTUAL]. It works for typical inputs. CODE: [PASTE_CODE] TASK (trace concrete values): 1. Walk the failing input through the code line by line, tracking each index, length, and accumulator value in a table. 2. Identify the exact point where the computed value diverges from the expected value. 3. Classify the bug: inclusive/exclusive bound mismatch, loop starting/ending one step off, slicing error, zero- vs one-based indexing, or boundary condition not handled (empty, single element, last element). 4. Verify your hypothesis by mentally running the smallest reproducing input. 5. Provide the corrected line(s) and confirm the fix against the empty, single-element, and boundary inputs. OUTPUT FORMAT: - 'Execution trace' (table: step | index | value | note). - 'Bug location and type' (file:line + classification). - 'Fix' (minimal diff). - 'Boundary verification' (input | expected | now produced). CONSTRAINTS: Use concrete numbers, not vague descriptions. Confirm the fix does not break the previously working cases. Keep the change minimal; do not rewrite unrelated logic.
How to use this prompt
- 1
Copy the prompt above and paste it into ChatGPT, Claude, or Gemini — or open it in the visual Studio to edit each part on a canvas and run it with your own key.
- 2
Replace any bracketed placeholders with your specifics. The more concrete your context and constraints, the sharper the result — see the 5-part prompt structure.
- 3
Run it, then refine. Ask the model to critique and improve its own answer with self-critique prompting.
Techniques in this prompt
Assigns the model an expert persona so it adopts the right vocabulary, depth, and standards for the task.
Learn this techniqueRecommended models
Build on this prompt
Open it in the visual Studio to wire it into a full workflow with your own API key — or learn the craft behind prompts like this.
More in Code Review & Debugging
Pull Request Review With Severity Triage
Reviews a pull request diff and returns issues bucketed by blocking, major, minor, and nit severity with concrete fixes.
Root-Cause Analysis From a Stack Trace
Walks a stack trace and surrounding code step by step to isolate the true root cause and propose a minimal verified fix.
Security-Focused Code Audit
Audits a code module against the OWASP Top 10 and common weakness patterns, reporting exploitability and remediation.
Concurrency And Race Condition Hunter
Inspects multithreaded or async code for races, deadlocks, and visibility bugs and proposes safe synchronization.