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
Write Comprehensive Unit Tests
Generate an exhaustive unit test suite covering nominal cases, edge cases, and errors with appropriate mocks.
Configure an Optimized Dockerfile for Your Application
This prompt generates a production-ready Dockerfile with multi-stage build, security best practices and cache optimization, tailored to your language and framework.
Create an Optimized Production Dockerfile
Create a multi-stage Dockerfile optimized for production with maximum security, lightweight image, and best practices.
AI-Assisted Complete Code Review
A complete prompt to get an in-depth code review covering bugs, security, performance, readability, and best practices, with concrete fixes.