From dd93d984d24021eea2452d9bb5ddb8516f84dd06 Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Thu, 12 Nov 2026 19:33:04 -0600 Subject: [PATCH] Handle empty doctor model responses --- scripts/doctor-model-lab.py | 2 ++ tests/jeannie/test_doctor_model_lab.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/scripts/doctor-model-lab.py b/scripts/doctor-model-lab.py index 3c2257e..4b44aad 100644 --- a/scripts/doctor-model-lab.py +++ b/scripts/doctor-model-lab.py @@ -324,6 +324,8 @@ def external_config(): def parse_answer(response): """Allow one complete Markdown JSON fence, then use the unchanged validator.""" + if not isinstance(response, str) or not response.strip(): + raise ValueError("model returned no text content") text = response.strip() match = re.fullmatch(r"```(?:json)?[ \t]*\r?\n(.*?)\r?\n```", text, re.DOTALL | re.IGNORECASE) return json.loads(match.group(1) if match else text) diff --git a/tests/jeannie/test_doctor_model_lab.py b/tests/jeannie/test_doctor_model_lab.py index fa343d9..e1c1f69 100644 --- a/tests/jeannie/test_doctor_model_lab.py +++ b/tests/jeannie/test_doctor_model_lab.py @@ -16,6 +16,11 @@ rank_spec.loader.exec_module(ranker) class DoctorModelLabTests(unittest.TestCase): + def test_empty_or_non_text_response_is_a_validation_rejection(self): + for response in (None, "", " ", {"unexpected": "content"}): + with self.subTest(response=response), self.assertRaisesRegex(ValueError, "no text content"): + lab.parse_answer(response) + def test_external_request_uses_the_same_evidence_and_private_key(self): with tempfile.TemporaryDirectory() as directory: name, tsv = lab.CASES[0]