From aee2e76c1ec5250dc01eab4265f9714c77629176 Mon Sep 17 00:00:00 2001 From: santhreal <64453045+santhreal@users.noreply.github.com> Date: Wed, 22 Jul 2026 22:49:03 -0700 Subject: [PATCH 1/2] fix(question): parse quiz JSON with raw_decode Trailing prose that contains braces made the greedy brace slice invalid, so valid quiz payloads were dropped to {}. Decode the first JSON object instead. --- deeptutor/agents/question/pipeline.py | 8 +++++--- tests/agents/question/test_pipeline.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/deeptutor/agents/question/pipeline.py b/deeptutor/agents/question/pipeline.py index 41c3f4e48..818457ebf 100644 --- a/deeptutor/agents/question/pipeline.py +++ b/deeptutor/agents/question/pipeline.py @@ -1299,11 +1299,13 @@ class QuestionPipeline: try: parsed = json.loads(text) except json.JSONDecodeError: - obj = re.search(r"\{[\s\S]*\}", text) - if obj is None: + # raw_decode stops at the first complete value so trailing prose + # that itself contains braces cannot poison the slice. + start = text.find("{") + if start == -1: return {} try: - parsed = json.loads(obj.group(0)) + parsed, _end = json.JSONDecoder().raw_decode(text[start:]) except json.JSONDecodeError: return {} return parsed if isinstance(parsed, dict) else {} diff --git a/tests/agents/question/test_pipeline.py b/tests/agents/question/test_pipeline.py index b3a4b4759..6fb80e4d9 100644 --- a/tests/agents/question/test_pipeline.py +++ b/tests/agents/question/test_pipeline.py @@ -984,3 +984,14 @@ def test_parse_exam_paper_to_templates_happy_path(monkeypatch, tmp_path: Path) - assert templates[1].question_type == "choice" assert trace["template_count"] == "2" assert trace["question_file"].endswith("exam_questions.json") + + +def test_parse_quiz_payload_tolerates_trailing_brace_prose() -> None: + raw = ( + '{"question":"What is 2+2?","correct_answer":"4",' + '"explanation":"basic arithmetic"} note: see {docs}' + ) + parsed = QuestionPipeline._parse_quiz_payload(raw) + assert parsed["question"] == "What is 2+2?" + assert parsed["correct_answer"] == "4" + assert parsed["explanation"] == "basic arithmetic" From 968038f756d0606d8110212f6cfef6970511b4cd Mon Sep 17 00:00:00 2001 From: santhreal <64453045+santhreal@users.noreply.github.com> Date: Wed, 22 Jul 2026 22:52:14 -0700 Subject: [PATCH 2/2] style(question): one-line comment on quiz JSON raw_decode --- deeptutor/agents/question/pipeline.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/deeptutor/agents/question/pipeline.py b/deeptutor/agents/question/pipeline.py index 818457ebf..bbc1659c6 100644 --- a/deeptutor/agents/question/pipeline.py +++ b/deeptutor/agents/question/pipeline.py @@ -1299,8 +1299,7 @@ class QuestionPipeline: try: parsed = json.loads(text) except json.JSONDecodeError: - # raw_decode stops at the first complete value so trailing prose - # that itself contains braces cannot poison the slice. + # First JSON object only; trailing brace-prose must not extend the slice. start = text.find("{") if start == -1: return {}