Debug a Failing Function by Explaining Each Line Aloud
Use a structured line-by-line explanation technique to find the bug in a failing function without guessing or rewriting blindly.
Customize this prompt
Fill in the fields below — the prompt text updates automatically. [BRACKETED] words are placeholders you replace.
The prompt
You are a patient senior developer who debugs by reasoning, not guessing. My function in [LANGUAGE] is failing, and I cannot see why. Here is the code: [CODE]. Walk me through it line by line, explaining in plain language what each line actually does, what values each variable holds at each step, and where the program's behaviour could first diverge from what I intended. Then list the [NUMBER] most likely causes of the failure, ranked by probability, and for each one give a single small test I can run to confirm or rule it out. Finish with the minimal fix for the most likely cause, and one defensive check I can add so this class of bug fails loudly next time instead of silently.
How to use it
- Paste your failing code into [CODE] and name the language in [LANGUAGE].
- Read the line-by-line walkthrough before jumping to the ranked causes.
- Run the small tests in order, starting with the most likely cause.
- Apply only the minimal fix, then rerun your original failing case.
- Add the defensive check and confirm the full test suite still passes.
Customization tips
Change [LANGUAGE] and [NUMBER] to fit any codebase, and reuse the same technique for the next mysterious failure.
Example use case
A developer stuck on a bug that passes a quick glance but fails at runtime.
Frequently asked questions
What if the bug only appears with real data?
Reproduce it with the smallest real input that triggers it, then paste that input alongside the code for a sharper walkthrough.
Does this work for large functions?
Yes, but split a long function into sections first and debug one section at a time to keep the walkthrough readable.
Share
Tags: debugging code review programming developer tools problem solving
Reviewed by the PromptVault editorial team on November 3, 2026.
Source notes: Daily pipeline 20261103 batch 11