Skip to main content
Back to Library
Prompt Engineering Guide

Mastering Debug code
on Command R+

Stop guessing. See how professional prompt engineering transforms Command R+'s output for specific technical tasks.

The "Vibe" Prompt

"Hey, can you help me debug this code? It's not working right."
Low specificity, inconsistent output

Optimized Version

STABLE
You are an expert software engineer tasked with debugging a given code snippet. Your goal is to identify the root cause of any issues and propose a corrected, working version of the code, along with a clear explanation of the problem and your solution. Here's a structured approach I'd like you to follow: 1. **Understand the Request:** Carefully read the provided code, its intended purpose (if described), and any error messages or unexpected behaviors. 2. **Initial Scan & Syntax Check:** Perform a quick scan for obvious syntax errors, typos, or common language-specific pitfalls. 3. **Logical Analysis (Chain of Thought):** * **Identify Suspect Areas:** Based on the description of the problem or error, pinpoint the most likely sections of the code that could be causing the issue. * **Trace Execution (Mental Walkthrough):** Simulate the code's execution step-by-step, paying close attention to variable values, control flow statements (loops, conditionals), and function calls within the suspect areas. Consider edge cases. * **Formulate Hypotheses:** Based on your trace, propose one or more potential reasons why the code is behaving incorrectly. * **Verify Hypotheses:** Compare your hypotheses against the expected behavior and observed errors. Eliminate hypotheses that don't fit. 4. **Root Cause Identification:** Clearly state the identified root cause of the bug. 5. **Proposed Solution:** Provide the corrected code snippet. Ensure the solution directly addresses the root cause. 6. **Explanation of Solution:** Explain *why* your solution works and how it resolves the identified bug. If applicable, mention any trade-offs or alternative solutions considered. 7. **Test Cases (Optional but Recommended):** If the original problem description included test cases, demonstrate that your corrected code passes them. If not, suggest a simple test case to verify the fix. **Example Code to Debug:** ```python def calculate_average(numbers): total = 0 for num in numbers: total += num return total / len(numbers) # Problem: This function raises a ZeroDivisionError when called with an empty list. ``` **Your Turn: Please provide the code to debug after this prompt, following the above structure for your response.**
Structured, task-focused, reduced hallucinations

Engineering Rationale

The 'optimized_prompt' leverages a chain-of-thought approach and defines a clear, step-by-step process for Command R+ to follow. It provides explicit instructions for understanding, analyzing, identifying, solving, and explaining, which guides the model toward a comprehensive and accurate debugging response. The example further clarifies expectations for formatting and content. This structured guidance reduces ambiguity and encourages a more systematic problem-solving approach, leading to better quality output. It also explicitly asks for the 'root cause', ensuring the model doesn't just provide a patch.

0%
Token Efficiency Gain
The output for a given code snippet should consistently follow the specified 7-step structure.
The 'Root Cause Identification' section should pinpoint the actual underlying problem, not just describe the symptom.
The 'Proposed Solution' should be a functional correction of the original code, addressing the root cause.

Ready to stop burning tokens?

Join 5,000+ developers using Prompt Optimizer to slash costs and boost LLM reliability.

Optimize My Prompts