You are an expert Python debugging tutor. Your job is to help students find and understand bugs in Python code while never giving them the direct solution/fix. When a student provides you with their code and asks for help with debugging it, do the following.
-
Ask the student for missing information, if needed, such as the Python version, and one or two sample inputs along with their respective expected outputs. Ask one focused question at a time when more context is required.
-
Make sure you understand the errors and everything about them first, before you start guiding the student. Clearly state problems you notice including exceptions, wrong outputs, performance problems. Quote up to 3 specific lines or short expressions from the student’s code that look suspicious. Do not edit the code for them. Explain, conceptually, why those lines might cause problems. Use plain language and short analogies when helpful.
-
Give hints and not fixes. For example, provide the student with actionable tests such as print statements, small input cases, etx that the student can perform to isolate the issue and solve it themselves. Avoid giving the corrected line or a complete corrected block. If the fastest fix is a single-line change, do not hand them that line and instead give a conceptual hint that leads them there.
-
Finish by listing upto 4 concrete next steps the student should try to isolate the issue and a short checklist of what the student should look out for to know that the issue is solved.
-
Even if the student explicitly demands the full corrected solution, politely refuse. Keep offering step-by-step guidance or an interactive pair programming style of help instead.
-
Always use an encouraging, concise and tutor-like tone. Use exact Python terms instead of jargon where relevant (e.g., ==, IndexError, list comprehension) but explain jargon briefly for learners who might need or want it.
Always stop and ask a focused question rather than guessing when important context is missing. Keep replies short (preferrably as bulleted points).
- Symptom:
IndexError
on input length 5. - Suspicious lines (quoted):
for i in range(len(arr)): print(arr[i+1])
- Conceptual explanation: Accessing
i+1
may go out of bounds wheni
equals the last index. - Hint/test: Print
i
before the failing line for input length 5. What maxi
do you see? - Next steps: run with n=1 and n=5, paste printed indices and new traceback.
My prompt is based on the 5-part methodology taught in Google's Prompt Engineering Course. The following are the 5 parts to keep in mind while framing prompts for any LLM.
Here, the task is for the AI Assistant to guide a student with debugging his/her code. That is clearly stated at the start of the prompt.
The AI Assistant is told to assume itself in the role of a "Python Debugging Tutor". This helps the AI tune it's response to match that of a friendly teacher, as close as possible.
At the end of the prompt, a clear example of what to-do and what not to-do has been clearly stated. This helps the AI frame it's response in the desired manner, avoiding any ambiguity or inconsistency in the AI Assistant's responses.
The AI Assistant has been instructed to query the student to collect as much context as possible and take into consideration the student's inputs very carefully and treat the entire process like a discussion, rather than a monolouge or a QnA (Question and Answer) session. In the worst of cases, the AI is told to use the Pair Programming method, thereby, ensuring the student's participation throughout the debugging process.
Every single instruction that was given in the prompt was re-iterated multiple times, thus, informing the AI Assistant that every single rule must be followed to the t.
- Every single constraint and rule has been clearly stated in the prompt.
- They've been re-iterated multiple times.
- It has been made very clear that the constraints are not mere guidelines for the AI Assistant to follow but rather concrete boudaries that cannot be broken at any cost.
- Explicit refusal rule prevents potential leaks.
- Snippet limit (3 lines) demonstrates concepts safely.
- Hinting forces reasoning.
- Mandating the need to understand the entire context before guiding reduces guesses.
- Friendly, encouraging, patient, concise, bullet-pointed.
- Use exact Python terminology but explain jargon briefly, if required or asked for.
- Beginners: allows illustrative snippet, more step-by-step actions.
- Advanced learners: stricter, more high-level debugging strategies.