ChatGPT and Jupyter Notebook: make the cells work from a fresh kernel

Give ChatGPT the notebook's cells in document order, the exact error and the result of a fresh-kernel run. Ask it to identify hidden state before adding more code. A cell that succeeds after an earlier experiment can still fail when someone else runs the saved notebook from top to bottom.

Use a manual copy-and-review workflow when you want help with local notebook cells. Pasting code into ChatGPT does not connect it to your Jupyter kernel, installed packages or files. OpenAI's prompting guidance supports supplying the task context, intended output and constraints; supply the execution evidence yourself when it comes from your computer.

Reproduce the missing dependency in two cells

This authored Python notebook has two visible cells in this order:

# Cell 1
adjusted = [value * factor for value in values]
print(adjusted)
# Cell 2
values = [4, 7]
factor = 3

If you run cell 2 and then cell 1, the expected output is [12, 21]. In a fresh Python kernel, running cell 1 first instead raises a NameError because its inputs have not been defined. The saved document order and the interactive execution order describe different programs here.

Moving the definitions above their use repairs this particular dependency. Replacing the calculation with [12, 21] would merely hard-code one result. Adding factor = 1 to silence an error would change the intended calculation.

Restart the kernel, rather than just reopening the tab

Save your work and finish any computation you need before restarting. Restarting discards the kernel's in-memory state. Use Jupyter's kernel restart and run-all workflow, or restart the kernel and then run all cells in document order; menu wording varies by interface.

The JupyterLab kernel documentation, checked October 24, 2026, explains that closing a notebook document leaves its underlying kernel running. Reopening that document is therefore not a clean-state test. Jupyter's notebook documentation covers cells and execution in the notebook interface.

For the fixture, keep the failing order long enough to observe and record the first error. Then put the definitions first and rerun from a fresh kernel:

# Cell 1
values = [4, 7]
factor = 3
# Cell 2
adjusted = [value * factor for value in values]
print(adjusted)
assert adjusted == [12, 21]

These are teaching expectations. They do not establish that your own notebook has no file, package or data dependencies. A previous saved output can remain visible even when the current code cannot recreate it, so use the new run's result as the evidence.

Ask for a cell-order diagnosis

Help make this local Jupyter notebook reproducible from a fresh kernel.
Notebook interface and version: [ENTER]
Kernel language and version: [ENTER]
Required packages and relevant versions: [ENTER]
Cells in their current saved order: [PASTE WITH CELL NUMBERS]
Exact first error after restart and run all: [PASTE]
Expected outputs and permitted sample input: [PASTE]
External files, paths and earlier manual setup: [DESCRIBE]

Identify each cell's inputs and where they are defined. Explain any
dependency on out-of-order execution or old kernel state. Propose
the smallest reordering or initialization change preserving the
intended calculation. Keep raw data unchanged. Do not invent files,
package versions or a successful run. Return the revised cell order
and the specific outputs I should check after another fresh restart.

If the first clean run fails on an import, include that error before asking about a chart ten cells later. If it fails on a path, state where the notebook is running and where the file actually lives. Those observations point to different repairs from a variable defined too late.

The Python script workflow covers a complete file-based program, while debugging with an exact reproduction helps isolate a remaining failure. Here the additional requirement is that the saved sequence carries its own needed setup.

Save the notebook after the accepted fresh-kernel run and retain the package and input requirements beside it. Before handing it over, check that its displayed results came from that sequence rather than a successful experiment that the document no longer contains.

Keep reading