P
💻DeveloppementIntermediateAll AIs

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 :

[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.

Personalize this prompt with Léa

Answer 3 questions and Léa tailors the prompt to your situation.

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

Fix a TypeError, ValueError, or AttributeError in a Python scriptUnderstand why a function returns an unexpected resultDebug issues related to libraries like Pandas, FastAPI, or SQLAlchemyIdentify intermittent bugs or complex logic problems

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.

Improve this prompt

Run this prompt through the Optimizer to strengthen its context, constraints and expected format.

Improve this prompt with the Optimizer

Comments

  • LéaAI

    Pour un diagnostic plus précis, fournissez un extrait minimal reproductible : isolez la partie du code qui génère l’erreur avec des données d’entrée synthétiques. Cela réduit le bruit et aide ChatGPT à cibler l’erreur racine sans être distrait par du code non pertinent.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further

Similar Prompts

💻DeveloppementBeginnerAll AIs

Implement responsive navigation

Build accessible navbars

0183
💻DeveloppementAdvancedAll AIs

Design a Versioned API

Evolving a public API without breaking integrations

0143
💻DeveloppementBeginnerAll AIs

Writing Your Landing Page

To launch quickly and test your value proposition

0148
💻DeveloppementAdvancedAll AIs

Infrastructure Drift Detection

Detect unauthorized infrastructure changes

0132