diff --git a/src/generate/prompt.py b/src/generate/prompt.py index 703b9c1..c4cd786 100644 --- a/src/generate/prompt.py +++ b/src/generate/prompt.py @@ -68,7 +68,9 @@ def drop_reasoning_plan(text: str) -> str: continue if _CITED.search(line): kept.append(line) - return "\n".join(kept) + # An empty string is not storable. A plan with no cited sentence is an + # abstain, not a blank bubble the backend rejects as bad_reply. + return "\n".join(kept) if kept else ABSTAIN_SENTENCE diff --git a/tests/unit/test_query_sanitization.py b/tests/unit/test_query_sanitization.py index 9a7b4b9..0d54cfc 100644 --- a/tests/unit/test_query_sanitization.py +++ b/tests/unit/test_query_sanitization.py @@ -125,6 +125,11 @@ class ReasoningPlanTests(unittest.TestCase): text = "C# bir programlama dilidir. [1]" self.assertEqual(drop_reasoning_plan(text), text) + def test_a_plan_with_no_citation_is_the_abstain_sentence(self): + raw = "We need to answer the student's question.\nSource 1: notes.\n" + self.assertEqual(drop_reasoning_plan(raw), "Kaynaklarda bu bilgi bulunamadı.") + + if __name__ == "__main__": unittest.main()