Structured Debugging Prompt for a Failing Code Function
Debug a broken function step by step: reproduce it, isolate the cause, fix it, and prove the fix works.
Customize this prompt
Fill in the fields below — the prompt text updates automatically. [BRACKETED] words are placeholders you replace.
The prompt
Debug the failing function in [PROGRAMMING_LANGUAGE] shown below, which is supposed to [EXPECTED_BEHAVIOUR] but instead produces [ACTUAL_BEHAVIOUR]. First, restate the function's purpose in one sentence and list its inputs, outputs, and edge cases. Then trace the code line by line for the failing input [FAILING_INPUT], noting the value of each key variable. Identify the single most likely root cause, explain why it produces [ACTUAL_BEHAVIOUR], and propose a minimal fix that changes as little code as possible. Finish with a corrected version of the function and three test cases: the original failing input, one normal input, and one edge case, each with its expected output.
How to use it
- Restate the function's purpose, inputs, outputs, and edge cases.
- Trace the code line by line using [FAILING_INPUT].
- Identify the single most likely root cause and explain it.
- Propose a minimal fix that changes as little code as possible.
- Provide the corrected function plus three test cases.
Customization tips
Swap [PROGRAMMING_LANGUAGE] and [EXPECTED_BEHAVIOUR] for your stack, and add the error message verbatim when you have one.
Example use case
Developers stuck on a function that misbehaves and want a methodical path to the fix.
Frequently asked questions
What if the bug only appears sometimes?
Add the exact conditions that trigger it, including the input and environment, so the trace can reproduce the intermittent case.
Should I paste my whole project?
No, paste only the failing function plus the code that calls it; a minimal example gets a faster, more accurate answer.
Share
Tags: debugging coding software development code review problem solving programming
Reviewed by the PromptVault editorial team on October 31, 2026.
Source notes: Daily pipeline 20261031 batch 11