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.
This commit is contained in:
Celes Renata
2026-04-17 16:35:13 +00:00
parent 759d868e3b
commit 1394e6168b
+6 -1
View File
@@ -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)):