From 2aa088a8cfbc1347559b70ce518c38d4fd2a7924 Mon Sep 17 00:00:00 2001 From: Brad Stein Date: Tue, 3 Feb 2026 17:03:09 -0300 Subject: [PATCH] atlasbot: enforce metric facts in answers --- atlasbot/engine/answerer.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/atlasbot/engine/answerer.py b/atlasbot/engine/answerer.py index ec9b15d..03d2f0d 100644 --- a/atlasbot/engine/answerer.py +++ b/atlasbot/engine/answerer.py @@ -481,6 +481,9 @@ class AnswerEngine: hardware_line = _line_starting_with(summary_lines, "hardware_nodes:") if any(term in lowered_question for term in hardware_terms) and hardware_line: needs_evidence = True + if metric_facts and (classify.get("question_type") in {"metric", "diagnostic"} or force_metric): + if not _reply_matches_metric_facts(reply, metric_facts): + needs_evidence = True if classify.get("question_type") in {"open_ended", "planning"} and metric_facts: needs_evidence = True resolved_runbook = None @@ -1769,6 +1772,18 @@ def _needs_evidence_fix(reply: str, classify: dict[str, Any]) -> bool: return False +def _reply_matches_metric_facts(reply: str, metric_facts: list[str]) -> bool: + if not reply or not metric_facts: + return True + reply_numbers = set(re.findall(r"\d+(?:\\.\d+)?", reply)) + if not reply_numbers: + return False + fact_numbers = set(re.findall(r"\d+(?:\\.\d+)?", " ".join(metric_facts))) + if not fact_numbers: + return True + return bool(reply_numbers & fact_numbers) + + def _needs_dedup(reply: str) -> bool: if not reply: return False