From 1394e6168bba269fd9ef7371d4aeb826dbf101c4 Mon Sep 17 00:00:00 2001 From: Celes Renata Date: Fri, 17 Apr 2026 16:35:13 +0000 Subject: [PATCH] fix: event classifier now strips markdown fences and repairs JSON _parse_classification_response receives raw model output (with thinking tags, markdown fences, etc.) but was calling json.loads directly. Now uses _strip_markdown_fences + _repair_json from the client module before parsing, matching what _call_ollama does for extractions. --- services/extractor/event_classifier.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/services/extractor/event_classifier.py b/services/extractor/event_classifier.py index d240c69..801e0e1 100644 --- a/services/extractor/event_classifier.py +++ b/services/extractor/event_classifier.py @@ -284,9 +284,14 @@ def _parse_classification_response( ) -> GlobalEvent: """Parse raw Ollama JSON output into a GlobalEvent. + Strips markdown fences and repairs malformed JSON before parsing. Normalizes enum values and clamps numeric fields. """ - data = json.loads(raw_json) + from services.extractor.client import _strip_markdown_fences, _repair_json + + cleaned = _strip_markdown_fences(raw_json) + cleaned = _repair_json(cleaned) + data = json.loads(cleaned) confidence = data.get("confidence", 0.5) if isinstance(confidence, (int, float)):