Handle empty doctor model responses
Homelab Main / validate (push) Successful in 1m16s Details
Homelab Main / running-update (push) Successful in 2s Details
Homelab Main / debian-ops (push) Failing after 2s Details

This commit is contained in:
juvenal.diaz 2026-11-12 19:33:04 -06:00
parent e3564e211b
commit dd93d984d2
2 changed files with 7 additions and 0 deletions

View File

@ -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)

View File

@ -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]