About Prompt
- Prompt Type – Dynamic
- Prompt Platform – ChatGPT, Grok, Deepseek, Gemini, Copilot, Midjourney, Meta AI and more
- Niche – Coding
- Language – English
- Category – Developer Tools
- Prompt Title – AI Agent Prompt for Automated Code Debugging Assistant
Prompt Details
**Prompt Type:** Dynamic
**Target Audience:** Developers
**Purpose:** Automated code debugging and solution generation across various programming languages.
**AI Platform Compatibility:** Designed for general compatibility across AI platforms capable of code interpretation and generation. Adaptations may be necessary for platform-specific features.
**Prompt Structure:**
“`
## Code Debugging Assistant
**Task:** Debug the provided code snippet and suggest corrections. Provide a detailed explanation of the identified bug(s), the proposed solution, and the logic behind the fix. If applicable, suggest alternative approaches for improved code quality, performance, or maintainability.
**Programming Language:** {programming_language}
**Code Snippet:**
“`
{code_snippet}
“`
**Error Message (Optional):**
“`
{error_message}
“`
**Expected Behavior:** {expected_behavior}
**Current Behavior:** {current_behavior}
**Context (Optional):**
* **Relevant Code Sections:** {related_code_snippets} (e.g., function calls, class definitions, etc.)
* **External Libraries/Dependencies:** {list_of_dependencies}
* **Specific Requirements/Constraints:** {specific_instructions} (e.g., performance constraints, coding style guidelines, etc.)
**Output Format:**
“`json
{
“bugs”: [
{
“description”: “Description of the bug”,
“location”: { // Line number or other location identifier
“line”: 12,
“column”: 5
},
“severity”: “high/medium/low” // Optional severity level
}
],
“solutions”: [
{
“description”: “Description of the solution”,
“code”: “Corrected code snippet”
}
],
“alternative_approaches”: [ // Optional suggestions for improvement
{
“description”: “Description of the alternative approach”,
“code”: “Alternative code snippet”
}
],
“explanation”: “Detailed explanation of the bug, solution, and alternative approaches (if any).”
}
“`
**Example Usage:**
**Programming Language:** Python
**Code Snippet:**
“`python
def calculate_sum(a, b):
return a – b
result = calculate_sum(5, 3)
print(f”The sum is: {result}”)
“`
**Expected Behavior:** The function should return the sum of two numbers.
**Current Behavior:** The function returns the difference between two numbers.
**Output (Example):**
“`json
{
“bugs”: [
{
“description”: “The function `calculate_sum` subtracts `b` from `a` instead of adding them.”,
“location”: {
“line”: 2,
“column”: 12
},
“severity”: “high”
}
],
“solutions”: [
{
“description”: “Corrected the function to add `a` and `b`.”,
“code”: “def calculate_sum(a, b):\n return a + b”
}
],
“explanation”: “The original code had a ‘-‘ operator instead of a ‘+’ operator, resulting in subtraction instead of addition. The solution replaces the ‘-‘ with ‘+’ to correctly calculate the sum.”
}
“`
**Guidelines for Effective Prompts:**
* **Be Specific:** Clearly define the expected behavior and the observed behavior. Include any relevant error messages.
* **Provide Context:** Include relevant code sections, dependencies, and constraints to help the AI understand the code’s environment.
* **Structure the Input:** Use a consistent format to provide the code, error message, and expected behavior. This helps the AI parse the information effectively.
* **Specify the Output Format:** Requesting a structured JSON output simplifies parsing and integration with other tools.
* **Iterate and Refine:** Test and refine the prompt based on the AI’s responses. Adjust the level of detail and specificity as needed.
This structured prompt allows for dynamic input, making it a versatile tool for debugging various code snippets across different programming languages. The JSON output format facilitates easy integration with other developer tools and workflows, enhancing the debugging process. Remember to adapt the prompt to specific AI platform requirements for optimal performance.