diff --git a/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb b/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb
index 756d4311009344a9461e3f322cfdee5c5f902720..9fb046b08e29923134ab8349e0acb6759d670d2b 100644
--- a/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb
+++ b/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb
@@ -324,6 +324,7 @@
     "\n",
     "inp = []\n",
     "for gain_index, (gain, qm_file_map) in enumerate(gain_mapped_files.items()):\n",
+    "    gain_input = []\n",
     "    for module_index in modules:\n",
     "        qm = module_index_to_qm(module_index)\n",
     "        if qm not in qm_file_map:\n",
@@ -337,9 +338,15 @@
     "            with h5py.File(filename, \"r\") as fin:\n",
     "                if fin[h5path.format(module_index)+\"/trainId\"].shape[0] != 0:\n",
     "                    print(f\"Process {filename} for {qm}\")\n",
-    "                    inp.append((filename, module_index, gain_index))\n",
+    "                    gain_input.append((filename, module_index, gain_index))\n",
     "                else:\n",
-    "                    print(f\"Do not process {filename} because it is empty.\")"
+    "                    print(f\"Do not process {filename} because it is empty.\")\n",
+    "    if not gain_input:\n",
+    "        raise ValueError(\n",
+    "            \"No images to process for run: \"\n",
+    "            f\"{[v for v in offset_runs.values()][gain_index]}\"\n",
+    "        )\n",
+    "    inp += gain_input"
    ]
   },
   {