Code Debugging

Education & Learningchain-of-thought-promptinglanguagecode_snippetexpected_behavior

Tracing execution step by step reveals bugs that pattern-matching misses. Restating intent first ensures the model understands the goal before diagnosing the problem.

Prompt
Debug the following code. Do not just give the fix — walk through your reasoning so I understand the root cause.

Language: {{language}}
Code:
{{code_snippet}}

Expected behavior: {{expected_behavior}}
Actual behavior: {{actual_behavior}}

Debug step by step:
1. Read the code and restate what it's supposed to do
2. Trace through the execution mentally, noting variable states
3. Identify where the actual behavior diverges from expected
4. Explain the root cause of the bug
5. Provide the corrected code with comments on what changed

Variables to customize

{{language}}{{code_snippet}}{{expected_behavior}}{{actual_behavior}}

Why this prompt works

Tracing execution step by step reveals bugs that pattern-matching misses. Restating intent first ensures the model understands the goal before diagnosing the problem.

What you get when you save this prompt

Your workspace unlocks powerful tools to iterate and improve.

AI OPTIMIZE

AI Optimization

One-click improvement with structure analysis and pattern suggestions.

VERSION DIFF

Version History

Track every edit. Compare versions side-by-side with word-level diffs.

ORGANIZE
Development
Code Review
Testing
Marketing

Folders & Tags

Organize your library with nested folders, tags, and drag-and-drop.

MCP
$ npm i -g @promptingbox/mcp
Claude · Cursor · ChatGPT

Use Everywhere

Access prompts from Claude, Cursor, ChatGPT & more via MCP integration.

Your prompts, organized

Save, version, and access your best prompts across ChatGPT, Claude, Cursor, and more.