Code Review & Debugging5.0 · 0 ratings

Off-By-One And Boundary Bug Localizer

Pinpoints index, loop bound, and slicing errors by exhaustively reasoning through boundary inputs.

Role-Based

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. 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. 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. 3

    Run it, then refine. Ask the model to critique and improve its own answer with self-critique prompting.

Techniques in this prompt

Role-Based

Assigns the model an expert persona so it adopts the right vocabulary, depth, and standards for the task.

Learn this technique

Recommended models

claudegpt-4ogemini

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