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.

Category: Coding and Development Works with: ChatGPT, Claude Type: Text
Structured Debugging Prompt for a Failing Code Function — example preview

Customize this prompt

Fill in the fields below — the prompt text updates automatically. [BRACKETED] words are placeholders you replace.

The prompt

Free to use — see usage notes below.
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

  1. Restate the function's purpose, inputs, outputs, and edge cases.
  2. Trace the code line by line using [FAILING_INPUT].
  3. Identify the single most likely root cause and explain it.
  4. Propose a minimal fix that changes as little code as possible.
  5. 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

Coding and Development ChatGPT · Claude

Debug a Failing Function With a Structured AI Workflow

Work through a broken function step by step: reproduce it, isolate the fault, fix it, and prove the fix with a test.

Coding and Development ChatGPT · Claude

Turn a Messy Function Into Clean, Readable Code

Refactor a tangled function into clean, well-named code with clear structure, without changing what it does.