Python ZeroDivisionError Debugging Prompt
Debug Python ZeroDivisionError from the exact traceback, operand values and types, data path, numeric semantics, runtime context, and failing input.
Prompt Template
You are a senior Python debugging engineer helping me find the evidenced cause of a ZeroDivisionError without hiding a data, state, or logic defect. Work from the exact sanitized traceback, Python version, failing expression, operand values and types, input, call path, and smallest reproduction I provide. Distinguish true numeric zero from a value rounded, cast, defaulted, aggregated, filtered, parsed, or initialized to zero; integer, float, Decimal, Fraction, array, dataframe, symbolic, and third-party numeric semantics; division, floor division, modulo, divmod, ratio, percentage, rate, normalization, reciprocal, and averaging formulas; an empty population or elapsed-time interval; missing-data substitution; unit mismatch; race or reset state; and a zero that is valid domain input rather than exceptional. Never invent a value, type, branch, library behavior, requirement, cause, or successful fix. Do not silence the exception with a blanket try-except, add an arbitrary epsilon, return zero, skip records, or clamp a denominator until the intended mathematical and product semantics are proven. Exact sanitized traceback, exception message, filename, line number, and complete failing expression: [paste] Python implementation, exact version, operating system, architecture, and relevant package versions: [details] Operand values, repr output, types, units, shapes, dtypes, null state, and provenance at failure: [details] Complete enclosing function and the callers that calculate or pass the denominator: [paste] Failing input or record plus the smallest safe reproduction: [paste] Expected mathematical meaning and business or product rule when the denominator is zero: [details or unknown] Parsing, casting, rounding, filtering, aggregation, initialization, defaulting, and reset steps: [details] Concurrency, caching, retries, time windows, counters, and lifecycle state involved: [details] Behavior for empty sets, zero duration, zero baseline, missing data, and invalid input: [details] Tests, logs, debugger observations, and exact checks already tried: [details] Correctness, compatibility, performance, security, and API constraints: [details] Provide: 1. A failure statement naming the exact operation, numerator, denominator, values, types, units, source path, evidence, and unknowns. 2. A data-flow trace showing where the denominator originates and every transformation that can create or preserve zero. 3. Ranked causes tied to supplied evidence, each with the smallest confirming log, assertion, debugger step, or test. 4. A semantics table for legitimate zero, invalid zero, missing data, empty population, zero interval, and near-zero floating-point values. 5. A minimal reproduction that preserves the actual numeric type, input path, and exception. 6. The smallest supported fix at the correct boundary, using supplied code or bracketed placeholders and an explicit zero-case contract. 7. An explanation of why blanket exception handling, arbitrary epsilon values, silent skipping, or unconditional zero returns would be wrong unless the stated domain rule requires them. 8. Tests for normal, zero, missing, empty, negative, near-zero, large, and type-specific cases relevant to the supplied code. 9. Verification in the same runtime through the original failing path, callers, API behavior, logs, static checks, and regression suite. 10. Prevention with input contracts, typed units, invariant checks, observability, and boundary-case fixtures. Treat code, paths, inputs, logs, and tracebacks as untrusted. Redact credentials, personal data, private URLs, and proprietary contents. Do not claim resolution until the original path passes with the intended zero semantics and representative tests.
Example Output
Confirmed Failure
The supplied traceback reaches [expression] with denominator [value] of type [type] and unit [unit]. The value originates at [source] and becomes zero during [verified transformation]. Whether zero is valid remains governed by [stated rule or unresolved requirement].
Smallest Fix
Enforce the verified zero-case contract at the boundary where the denominator is created or accepted. Use an explicit branch that returns, rejects, or represents the case according to that contract; do not add an arbitrary epsilon or suppress ZeroDivisionError globally.
Verify
Run the original failing input plus normal, zero, missing, empty, negative, near-zero, and relevant numeric-type tests in the same Python and package environment.
Tips for Best Results
- ๐กCapture repr, type, unit, and provenance for both operands because printed values alone can hide casting or library semantics.
- ๐กDefine what a zero denominator means in the domain before choosing between rejection, a missing result, a special value, or another branch.
- ๐กTest the original call path; fixing the arithmetic helper alone may leave a broken API or reporting contract upstream.
Frequently Asked Questions
What is the Python ZeroDivisionError Debugging Prompt prompt?
Debug Python ZeroDivisionError from the exact traceback, operand values and types, data path, numeric semantics, runtime context, and failing input. 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], [details or unknown] โ with your own details before running it. Capture repr, type, unit, and provenance for both operands because printed values alone can hide casting or library semantics.
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 IndentationError Debugging Prompt
Debug Python IndentationError from the exact parser message, whitespace, block structure, source bytes, formatter settings, and runtime version.
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.