Debug with AI Without Deleting the Evidence: A Python Grid Example

Your AI assistant says the bug is fixed. The test is green. Then you notice the assertion disappeared. Congratulations: the smoke alarm has been successfully debugged.

A useful AI debugging session needs an observable requirement that survives the edit. Here is a small, reproducible example and a workflow you can reuse in a larger project. The example is illustrative; we ran the Python snippets locally, not a comparative test of any AI product.

The bug: one edit changes three rows

Imagine a tiny grid editor. Each cell should change independently:

grid = [[0] * 3] * 3
grid[0][1] = 7
print(grid)
# [[0, 7, 0], [0, 7, 0], [0, 7, 0]]

List repetition repeats references to the same inner list. The three rows therefore refer to one mutable object. A comprehension creates independent rows:

grid = [[0 for _ in range(3)] for _ in range(3)]
grid[0][1] = 7
assert grid == [[0, 7, 0], [0, 0, 0], [0, 0, 0]]
assert len({id(row) for row in grid}) == 3

Python’s Programming FAQ documents this shared-reference behavior. Copying only the outer list would still retain the inner references.

Give the assistant evidence, not a vague complaint

Before opening another chat, write down three things: the smallest input that reproduces the problem, the output you actually get, and the behavior the app requires. For this grid, the requirement is simple: editing one cell must leave the other rows untouched.

Use that as the center of the request:

Investigate this Python grid bug. Changing one cell changes every row. Expected: only the selected cell changes. First explain the likely cause using the supplied snippet. Then propose the smallest fix. Preserve the independent-cell requirement and its assertions. If you think an assertion is wrong, explain why before changing it. Show the diff and the exact verification command.

This is a suggested prompt, not a claim that any particular assistant will follow it reliably. Paste only the code and sample data needed to reproduce the issue. Replace credentials and real customer records with harmless examples.

For more reusable structure, see our prompt-template guide. Here the important addition is a concrete acceptance condition, rather than a request to make the error go away.

Inspect what changed before trusting green

A small diff makes the proposed explanation easier to judge. In this example, the construction of the grid should change. There is no obvious reason to delete a test, rewrite an unrelated module, or suppress an exception elsewhere.

Ask yourself whether the edit changes the behavior or merely changes what is checked. A test can legitimately need revision when the specification changes, but that is a separate decision. Make it visible and explain the new requirement.

Run the reproduction again. Then run the relevant existing tests. An assistant’s sentence saying “tests pass” is a report to verify, not the test result itself. Keep the command and actual output in the review record. If you cannot run the environment, label the fix unverified instead of filling the gap with confidence.

Check a second behavior

After the first assertion passes, edit a different row. If your app can add rows, check that path too. The goal is not to accumulate random tests; it is to challenge the explanation. A shared-reference bug can survive if a fix repairs the initial grid but a later row-creation path reuses another mutable object.

For a student portfolio, keep a short before-and-after note: reproduction, cause, minimal diff, verification and remaining limits. That demonstrates reasoning more clearly than a screenshot of a reassuring chat response.

The practical takeaway: ask AI to help explain a failure, preserve the requirement while editing, and verify the result yourself. A green checkmark earns its value from what it still checks.

Published November 24, 2026. Original MintedBrain walkthrough. Technical reference checked against Python’s official Programming FAQ; local assertions verified the shown shared-row failure and independent-row fix.

Discussion

  • Loading…

← Back to Blog