Debug Your Python Code with ChatGPT
A structured prompt to get a complete analysis of your Python bugs: identification, root cause explanation, commented fix, and prevention tips.
Paste in your AI
Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.
Tu es un développeur Python senior spécialisé en debugging et résolution d'erreurs. Je rencontre un problème avec mon code Python et j'ai besoin de ton aide pour le diagnostiquer et le corriger. Voici mon code : ```python [CODE_PYTHON] ``` Voici le message d'erreur ou le comportement inattendu que j'observe : [DESCRIPTION_ERREUR] Contexte supplémentaire : - Version de Python utilisée : [VERSION_PYTHON] - Bibliothèques/frameworks impliqués : [BIBLIOTHEQUES] Analyse ce code en suivant cette méthodologie : 1. **Identification de l'erreur** : Explique précisément quelle est l'erreur et sur quelle ligne elle se produit. 2. **Cause racine** : Explique pourquoi cette erreur survient en détaillant le mécanisme sous-jacent. 3. **Correction proposée** : Fournis le code corrigé avec des commentaires expliquant chaque modification. 4. **Prévention** : Suggère des bonnes pratiques pour éviter ce type d'erreur à l'avenir (type hints, assertions, tests). 5. **Cas limites** : Identifie d'éventuels autres bugs ou cas limites que tu repères dans le code, même s'ils ne sont pas liés à l'erreur principale. Sois pédagogique dans tes explications et adapte ton niveau de détail pour que je comprenne non seulement la correction mais aussi le raisonnement derrière.
Why this prompt works
<p>This prompt is designed to transform ChatGPT into a true Python debugging partner. By providing your code, error message, and technical context, you enable the AI to perform a methodical analysis rather than a superficial fix.</p><p>The 5-step structure (identification, root cause, fix, prevention, edge cases) ensures a complete response. The <strong>root cause</strong> step is particularly important: it helps you understand the <em>why</em> of the error, which is essential for growing as a developer. The <strong>edge cases</strong> step often reveals latent bugs you hadn't noticed yet.</p><p>For best results, be as specific as possible in the <strong>[ERROR_DESCRIPTION]</strong>: include the complete traceback, describe the expected vs actual result, and specify the steps to reproduce the problem. The more context you provide, the more relevant and actionable the analysis will be.</p>
Use Cases
Expected Output
A structured 5-part analysis including precise error identification with line number, root cause explanation, corrected code with comments, best practice recommendations, and a review of potential edge cases.
Learn more
Check the full skill on Prompt Guide to master this technique from A to Z.
View on Prompt Guide📬 Get new prompts every week
Join our newsletter and never miss a prompt.
Similar Prompts
Create a CLI Tool with Node.js
Create a professional Node.js CLI tool with Commander.js, Inquirer, visual feedback, and npm publishing.
Document Code with JSDoc/TSDoc
Generate professional and complete JSDoc/TSDoc documentation for your functions and classes with concrete examples.
Write a Database Migration Script
Create complete, reversible, and secure database migration scripts with pre/post validation and a zero-downtime strategy.
Analyze and Optimize Algorithmic Complexity
Analyze the Big O complexity of your algorithms and optimize them with appropriate data structures and more efficient algorithms.