AI Prompt for Debugging Errors

About Prompt

  • Prompt Type – Dynamic
  • Prompt Platform – ChatGPT, Grok, Deepseek, Gemini, Copilot, Midjourney, Meta AI and more
  • Niche – Debugging
  • Language – English
  • Category – Data & Analysis
  • Prompt Title – AI Prompt for Debugging Errors

Prompt Details

## Dynamic AI Prompt for Debugging Errors (Data & Analysis)

This prompt is designed to be used across various AI platforms for debugging errors, particularly focusing on data analysis tasks. It’s dynamic, allowing for customization based on the specific error, programming language, and available data. The goal is to leverage AI’s capabilities to not only identify the error but also provide insights into its root cause, potential solutions, and preventive measures.

**Prompt Template:**

“`
I’m encountering an error in my [Programming Language – e.g., Python, SQL, JavaScript] code related to data analysis. I’m using [Data Analysis Tools/Libraries – e.g., Pandas, NumPy, Spark, dplyr] for [Data Analysis Task – e.g., data cleaning, transformation, aggregation, visualization].

**Error Description:**

[Provide a detailed description of the error message, including the full text of the error, line number (if applicable), and the specific part of the code where it occurred. Be precise and avoid vague descriptions. For example, instead of “something went wrong,” describe “TypeError: unsupported operand type(s) for +: ‘int’ and ‘str’.”]

**Code Snippet:**

“`[Insert the relevant code snippet where the error occurs. Ensure proper formatting and indentation for readability. Clearly mark the line where the error is thrown. If the code is lengthy, focus on the critical sections related to the error.]“`

**Data Context:**

[Describe the data being used. This includes the data source (e.g., CSV file, database table, API), data format (e.g., JSON, CSV, Parquet), relevant data types (e.g., integer, string, date), and any specific characteristics of the data (e.g., large dataset, missing values, imbalanced classes) that might contribute to the error.]

**Expected Behavior:**

[Explain the intended outcome of the code snippet and what you expect to happen when it runs correctly. This helps the AI understand the logic behind your code and pinpoint the discrepancy causing the error.]

**Analysis Questions:**

1. What is the root cause of this error based on the provided information?
2. Provide specific suggestions on how to fix this error in the given code. Include code examples if possible.
3. Are there any alternative approaches or best practices I can adopt to avoid this type of error in the future?
4. Considering the data context, are there any data quality issues or preprocessing steps I should consider to prevent similar errors?
5. If the error is related to performance (e.g., slow execution, memory issues), suggest optimization strategies relevant to the data analysis task and tools being used.

**Optional Parameters:**

* **Specific Libraries/Functions:** If the error relates to specific libraries or functions, mention them explicitly (e.g., “error using the `pd.merge` function in Pandas”).
* **Testing Framework:** If you are using a testing framework, provide details about the test case that is failing.
* **Logging Information:** Include relevant logs or stack traces that provide more context about the error.
* **Debugging Tools Used:** Mention any debugging tools you have already tried (e.g., debugger, print statements).

**Output Format:**

Preferably provide the answers in a structured format, separating the root cause analysis, solutions, and preventative measures. Code examples for solutions should be clearly delineated and explained. If possible, provide links to relevant documentation or resources.

“`

**Example Usage (Python – Pandas):**

I’m encountering an error in my Python code using Pandas for data cleaning.

**Error Description:**

TypeError: unsupported operand type(s) for +: ‘int’ and ‘str’ on line 15.

**Code Snippet:**

“`python
import pandas as pd

data = {‘col1’: [1, 2, 3], ‘col2’: [‘a’, ‘b’, ‘c’]}
df = pd.DataFrame(data)

# Line 15 causing the error:
df[‘col3’] = df[‘col1’] + df[‘col2’]
print(df)
“`

**Data Context:**

The data is stored in a Python dictionary and then converted to a Pandas DataFrame. `col1` contains integers and `col2` contains strings. I want to create a new column `col3` by combining the values from `col1` and `col2`.

**Expected Behavior:**

I want to concatenate the string and integer values in each row to create a new column. For example, the first row of `col3` should be “1a”.

**Analysis Questions:** (as above)

This detailed and dynamic prompt empowers the AI to understand the specific error context, providing more relevant and helpful debugging assistance. By including information about the programming language, data analysis tools, error details, code snippet, data context, and expected behavior, the AI can effectively analyze the problem and generate targeted solutions, helping you resolve errors efficiently and improve your data analysis workflow.