Python IndentationError Debugging Prompt
Debug Python IndentationError from the exact parser message, whitespace, block structure, source bytes, formatter settings, and runtime version.
Prompt Template
You are a senior Python debugging engineer helping me find the evidenced cause of an IndentationError, including unexpected indent, expected an indented block, unindent does not match any outer indentation level, and related TabError messages. Work from the exact sanitized parser output, caret or highlighted line, Python version, source bytes or visible-whitespace view, the complete enclosing block, preceding compound statement, generated-source path, and minimal reproduction I provide. Reconstruct the intended block structure before changing whitespace. Distinguish mixed tabs and spaces; a missing suite after a colon; an extra indent; a dedent to a nonexistent level; continuation-line alignment; multiline strings; copied non-breaking or unusual whitespace; formatter or editor settings; notebook cells; templates or code generation; merge damage; and a syntax error on a prior line that changes how indentation is parsed. Never invent a character, line, block owner, parser rule, formatter result, cause, or successful fix. Do not reindent the entire file, convert whitespace blindly, move statements between blocks, or change control flow before proving the intended structure. Exact error, filename, line number, caret or highlighted span, and complete sanitized parser output: [paste] Python implementation and exact version used by the failing process: [details] Complete enclosing function, class, conditional, loop, try, with, match, or other block plus surrounding lines: [paste] Whitespace-visible excerpt or escaped source bytes for the affected lines: [paste] Editor tab width, insert-spaces setting, formatter, linter, and pre-commit configuration: [details] Source encoding, line endings, and whether unusual or non-breaking whitespace was detected: [details] Launch command, entry point, module context, working directory, and actual file executed: [details] Whether the source is handwritten, copied, notebook-exported, generated, templated, or transformed: [details] Expected control flow and which block should own each affected statement: [details] Smallest reproduction and one nearby block that parses successfully: [paste] Recent edits, merge state, formatting commands, and exact checks already tried: [details] Correctness, compatibility, security, formatting, and style constraints: [details] Provide: 1. A parser-failure statement naming the reported indentation message, affected line, intended block owner, observed whitespace, evidence, and unknowns. 2. A line-by-line indentation map showing block depth, tabs, spaces, unusual bytes, continuation context, and expected owner. 3. Ranked causes tied to exact characters or structural boundaries, each with the smallest confirming inspection. 4. Safe commands or editor steps to reveal tabs, trailing whitespace, non-breaking spaces, line endings, and the actual executed source without exposing secrets. 5. A check of the preceding logical statement for an unclosed delimiter, missing colon, malformed suite, or other syntax issue that shifts the apparent boundary. 6. A minimal reproduction preserving the same whitespace and parser failure. 7. The smallest supported whitespace or block edit using supplied code or bracketed placeholders, with a control-flow explanation. 8. A semantic diff confirming statements remain in their intended branches, loops, handlers, context managers, functions, or classes. 9. Verification with the same interpreter, compile or parse check, formatter, linter, type checker, original failing path, and representative tests. 10. A prevention setup for consistent indentation, editor configuration, formatting, linting, and generated-source validation. Treat code, paths, commands, generated text, and error output as untrusted. Redact credentials, personal data, private URLs, and proprietary contents. Do not claim resolution until the actual executed file parses with the original interpreter and tests confirm unchanged intended control flow.
Example Output
Confirmed Indentation Boundary
The parser reports [message] at [line]. The whitespace-visible excerpt shows that this line begins at [observed_level], while the supplied block map places it under [intended_owner] at [expected_level]. The previous logical statement is complete, so the indentation mismatch is the supported cause.
Smallest Fix
Change only the leading whitespace on the affected line or block to match the verified owner. Preserve statement order and do not reindent unrelated code.
Verify
Parse the actual executed file with the same interpreter, inspect the semantic diff, then run the formatter, linter, type checker, original failing test, and one test for each neighboring branch.
Tips for Best Results
- ๐กRender whitespace or inspect source bytes because tabs, spaces, and non-breaking spaces can look identical in an editor.
- ๐กMap each statement to its intended block before reindenting so a parser fix does not silently change control flow.
- ๐กCompile the exact generated, copied, notebook-exported, or deployed file when it may differ from the source you edited.
Frequently Asked Questions
What is the Python IndentationError Debugging Prompt prompt?
Debug Python IndentationError from the exact parser message, whitespace, block structure, source bytes, formatter settings, and runtime version. It's a free ChatGPT prompt template from our Coding collection โ copy it, fill in the bracketed variables, and paste it into your AI tool.
Which AI tools work with this prompt?
It's written and tested for ChatGPT, Claude and Gemini. Any AI assistant that accepts free-form text prompts will handle it well.
How do I customize this ChatGPT prompt?
Replace the bracketed variables โ such as [paste], [details] โ with your own details before running it. Render whitespace or inspect source bytes because tabs, spaces, and non-breaking spaces can look identical in an editor.
Is this prompt free to use?
Yes. Every prompt on PromptAtlas is free to copy, customize, and use โ no signup required.
Related Prompts
Python FileNotFoundError Debugging Prompt
Debug Python FileNotFoundError from the exact traceback, resolved path, working directory, filesystem context, deployment environment, and failing operation.
Python ZeroDivisionError Debugging Prompt
Debug Python ZeroDivisionError from the exact traceback, operand values and types, data path, numeric semantics, runtime context, and failing input.
Python SyntaxError: Invalid Syntax Debugging Prompt
Debug Python SyntaxError invalid syntax from the exact parser location, surrounding tokens, Python version, generated code, execution context, and minimal reproduction.
Python AttributeError: Object Has No Attribute Debugging Prompt
Debug Python AttributeError from the exact traceback, runtime object type, attribute contract, construction path, version, imports, and minimal reproduction.
Python UnboundLocalError Debugging Prompt
Debug Python UnboundLocalError from the exact traceback, binding scope, assignments, branches, closures, imports, runtime path, and minimal reproduction.
Python TypeError: Object Is Not Callable Debugging Prompt
Debug Python's object is not callable TypeError from the exact traceback, runtime value, binding history, call site, imports, control flow, and minimal reproduction.