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.

Category: Coding and Development Works with: ChatGPT, Claude Type: Text
Debug a Failing Function With a Structured AI Workflow — 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.
Act as a senior developer helping me debug [FUNCTION_NAME] in [LANGUAGE] inside [PROJECT_CONTEXT]. The failure is: [ERROR_MESSAGE], and it happens when [REPRO_STEPS]. First, ask me to confirm the smallest reproduction case and state what the function should do instead. Second, read [CODE_SNIPPET] and list three most likely fault locations, ranked, with the evidence for each. Third, propose one minimal fix for the top suspect only, and explain what would change in the output if you are right. Fourth, write a regression test that fails before the fix and passes after it, plus two edge cases worth checking. Do not rewrite the whole function, and do not suggest a fix you cannot justify from the code I pasted.

How to use it

  1. Paste [CODE_SNIPPET] and the exact [ERROR_MESSAGE].
  2. Write [REPRO_STEPS] someone else could follow.
  3. Apply only the top-suspect fix first and test it.
  4. Add the regression test before moving on.

Customization tips

Set [LANGUAGE] and [PROJECT_CONTEXT] to your stack, and add your test framework for the regression test step.

Example use case

Developers stuck on a bug who want a disciplined fix, not a blind rewrite.

Frequently asked questions

What if the AI's top suspect is wrong?

That is useful information: the failed prediction narrows the fault, so move to suspect two with the same one-fix-at-a-time rule.

Should I paste my whole codebase?

No: paste the failing function and its direct callers only, so the analysis stays focused on the real fault.

Share

Tags: debugging code review software development error fixing regression testing

Reviewed by the PromptVault editorial team on November 2, 2026.
Source notes: Daily pipeline 20261102 batch 11

Coding and Development ChatGPT · Claude

Thorough Pull Request Code Review With Fixes

A senior-engineer-style pull request review covering correctness, security, performance, and readability with concrete …

Coding and Development ChatGPT · Claude

Turn a Vague Bug Report Into Steps Anyone Can Reproduce

A prompt that converts a vague bug report into clear reproduction steps, expected behaviour, and a ready-to-write test …