Repair hallucinated Semantic Consolidator source IDs

This commit is contained in:
2026-08-09 14:59:27 +02:00
parent 58effcafc5
commit 0b24351127
4 changed files with 240 additions and 11 deletions
@@ -600,11 +600,12 @@ def repair_model_group_coverage(
"""
Apply deterministic source-coverage repairs to model grouping JSON.
The repair is intentionally conservative. Repeated source IDs are removed
after their first occurrence, empty groups created by that removal are
dropped, and missing facts are restored as singleton groups using the
original canonicalized fact text. No existing group text, merge reason or
semantic merge is rewritten.
The repair is intentionally conservative. Unknown source IDs are removed
without guessing a replacement. Repeated valid source IDs are removed after
their first occurrence, empty groups created by either removal are dropped,
and missing facts are restored as singleton groups using the original
canonicalized fact text. No existing group text, merge reason or semantic
merge is rewritten.
"""
groups = model_output.get("groups")
if not isinstance(groups, list):
@@ -625,9 +626,19 @@ def repair_model_group_coverage(
continue
kept_ids: list[str] = []
for id_index, item_id in enumerate(source_ids):
if not isinstance(item_id, str) or item_id not in expected_ids:
if not isinstance(item_id, str):
kept_ids.append(item_id)
continue
if item_id not in expected_ids:
changes.append(
{
"operation": "remove_unknown_source_id",
"id": item_id,
"group_index": group_index,
"id_index": id_index,
}
)
continue
if item_id in seen:
changes.append(
{