Copyable prompt chain

Debug Code with AI

A copyable chain for turning an error message into a diagnosis, minimal reproduction, fix, and regression test.

Best for
Developers and technical builders
Outcome
A safer debugging session with hypotheses, patch options, and tests.

Step 1

Frame the bug

Give the model enough context to avoid guessing.

You are a senior debugging partner. I will provide an error, relevant code, expected behavior, actual behavior, and recent changes. Ask up to 5 clarifying questions only if needed, then list the most likely causes ranked by probability.

Step 2

Create a minimal reproduction

Shrink the problem to the smallest verifiable case.

Based on the bug context, design the smallest reproduction case. Include exact inputs, setup, expected output, actual output, and what evidence would confirm each hypothesis.

Step 3

Propose the fix

Make the change understandable and reviewable.

Propose the safest fix. Explain why it addresses the root cause, what files or functions should change, and what edge cases could break if the assumption is wrong.

Step 4

Add regression coverage

Prevent the same bug from returning.

Write a focused regression test plan for this bug. Include unit cases, integration cases if relevant, and one negative test that proves the fix is not overbroad.

FAQ

Can I use this workflow with any AI model?

Yes. The steps are written for instruction-following models such as ChatGPT, Claude, Gemini, Llama, and Mistral.

Should I run every step in one chat?

For best results, run the steps in one conversation so the model keeps the context, then copy important outputs into your working document.