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:
@@ -284,9 +284,14 @@ def _parse_classification_response(
|
|||||||
) -> GlobalEvent:
|
) -> GlobalEvent:
|
||||||
"""Parse raw Ollama JSON output into a 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.
|
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)
|
confidence = data.get("confidence", 0.5)
|
||||||
if isinstance(confidence, (int, float)):
|
if isinstance(confidence, (int, float)):
|
||||||
|
|||||||
Reference in New Issue
Block a user