The fastest way to get a wrong answer from an AI model during a production incident is to paste a stack trace and ask "what's wrong?" Without structure, the model will confidently name a plausible-sounding cause that may have nothing to do with your actual bug. Debugging needs a scientific-method framing, not a guess.
Why unstructured debugging prompts fail
LLMs generate the most statistically likely continuation of your text. A bare stack trace looks like hundreds of other stack traces in the model's training data, so it will pattern-match to the most common cause — not necessarily your cause. The fix is to force the model into an explicit hypothesis-and-evidence loop instead of a single guess.
A four-step debugging prompt framework
- State the observed symptom precisely (exact error, frequency, environment, recent changes) — this is your evidence.
- Ask the model to list multiple candidate hypotheses ranked by likelihood, not a single answer.
- For each hypothesis, ask what additional evidence (logs, code paths, config) would confirm or rule it out.
- Only after evidence narrows the list, ask for the fix — and require the model to explain why alternative hypotheses were ruled out.
Worked example: an intermittent 500 error under load
Say your payment API throws an intermittent NullReferenceException only under production load, never in staging. Here's the framework applied step by step.
Symptom: PaymentController.Charge throws System.NullReferenceException at PaymentService.cs:142, roughly 3-5 times per hour under production load (2000+ req/min). Never reproduces in staging (200 req/min) or locally. No related deploy in the last 48 hours. Stack trace: [paste full trace]. Relevant code: [paste PaymentService.cs lines 100-160, including the injected dependencies and their lifetimes].
Do not propose a fix yet. First, list 3-5 ranked hypotheses for why this only occurs under production load.For each of the hypotheses above, tell me exactly what to check in the codebase or logs to confirm or rule it out — specific file/line to inspect, or a specific log query to run.This step turns the model into a checklist generator rather than an oracle. In our example, checking the DI registration in Startup.cs confirms hypothesis #1: a Scoped ICurrencyConverter was being injected into a Singleton PaymentService, so the first resolved instance's converter reference gets reused — and under low load in staging, it happened to never be null at the moment of use, while under production concurrency a background refresh briefly nulled it out.
Confirmed: PaymentService is registered as Singleton but injects a Scoped ICurrencyConverter, matching hypothesis #1. Propose a fix that doesn't change PaymentService's Singleton lifetime (it's expensive to construct). Explain why the other three hypotheses are now ruled out given this evidence.Specialized debugging categories
| Category | What makes it different | Extra evidence to request |
|---|---|---|
| Multi-layer stack traces | Exception wrapped in exception across service/process boundaries | Ask for the innermost exception first, then work outward — outer wrapping often obscures the real type |
| Memory issues | Leak vs. bloat vs. GC pressure look identical from the outside | Request a heap snapshot diff over time, not a single snapshot |
| Deadlocks | Symptom (hang) is far removed from cause (lock ordering) | Request full thread dumps from all threads, not just the blocked one |
The Existing Project Analysis & Modernization program builds dedicated prompt patterns for each of these categories.
Related reading
- Writing a SEV1 Incident Post-Mortem with AI: Prompt Templates for On-Call EngineersPrompt templates that help on-call engineers triage a SEV1 incident and write a blameless post-mortem with a clear root cause, using any AI assistant.
- 10 ChatGPT & Claude Prompts for Debugging Code FasterTen ChatGPT and Claude prompts for debugging, built around the evidence AI needs to help: error output, a minimal reproduction and what you tried.
- Memory Leak Analysis: Debugging .NET Memory Issues with AIFind .NET memory leaks with AI: the usual causes such as event handlers, static caches and closures, and a step-by-step way to track them down.
PromptFable is independent and is not affiliated with, endorsed by or sponsored by Anthropic, Google, OpenAI or any other vendor. Claude, Gemini, Google AI Studio and other product names are trademarks of their respective owners.