Phase 0 — judge value cleanup + --no-cache + import assert

The (K5) bug fix (his 24-25/10 session): glm-5.3-flash glues row
citations and glosses onto the judge's value field, killing the ablation
audit silently ("the judge invented it: nothing to ablate") and leaking
LLM prose into typed payloads. Fixed at the judge's output boundary
(_answer_from_rows): trailing-only, marker-anchored cleanup (_clean_value)
that strips the three live citation shapes and survives legitimate
parentheticals ("(PSOE)", "(since 2018)"). The AnswerFromKG value desc
now says what the value must be.

--no-cache CLI flag (his ruling: the dspy disk cache is not a bug, the
default stays; the flag exists for A/B and freshness testing) — builds
dspy.LM with cache=False for the process; verified live: repeated runs
re-run real inference instead of replaying.

Import assert at startup: floop/knowledge SUBMODULE files must resolve
inside this repo's tree. Namespace-package __path__ lies (it recomputes
dynamically and lists every tree), so the check pins the actual module
files (run 085457 was main's pipeline inside the branch worktree, no
signal). Abort loudly, don't log.
This commit is contained in:
2026-10-25 20:00:34 +01:00
parent e594339629
commit 985aec2f60
5 changed files with 200 additions and 6 deletions
+40 -1
View File
@@ -33,6 +33,45 @@ from .wiki import (WikipediaClient, WikiPage, WikiTable, resolve_convert,
WORD_RE = re.compile(r"[A-Za-zÀ-ÿ0-9']+")
# (K5) bug (run 085457, 24-25/10): glm-5.3-flash glues row citations and
# glosses onto the value field (AnswerFromKG says "cite rows by id" but has
# no citation output field, so the model cites in the only field it has).
# Three live shapes, stripped at the judge's output boundary — BEFORE the
# evidence payload and the ablation audit see the value:
# "... (K5)" — row-id citation suffix
# "... (…; cited from rows K16 and K30)" — parenthetical gloss citing rows
# "15 (list of 15 members: …)" — the LIST path's own gloss of a count
# Trailing-only, marker-anchored: "(PSOE)" inside a name, "(since 2018)",
# "(Presidente del Gobierno)" are legitimate and MUST survive. Fixed code
# cleans the model's proposal (LLMs propose, code decides — the audit's
# _carries then finds the support rows and the ambiguity audit can run).
_ROW_CITATION_RE = re.compile(
r"\s*\(\s*(?:row\s+|rows\s+)?K\d+(?:\s*(?:,|and|;)\s*K?\d+)*\s*\)\s*$",
re.IGNORECASE)
_ROW_CITED_GLOSS_RE = re.compile(
r"\s*\([^()]*\bcited from (?:row|rows)\b[^()]*\)\s*$",
re.IGNORECASE)
_LIST_GLOSS_RE = re.compile(
r"\s*\(\s*list of\b[^()]*\)\s*$",
re.IGNORECASE)
def _clean_value(value: str) -> str:
"""Strip trailing citation/gloss parentheticals from a judge value.
The boundary law: only TRAILING shapes with a citation/list marker are
touched; mid-value text and legitimate parentheticals are the model's
own words and stay. Idempotent by construction (a cleaned value ends
clean). UNKNOWN and empty pass through untouched.
"""
v = (value or "").strip()
if not v or v.upper() == "UNKNOWN":
return v
for rx in (_ROW_CITATION_RE, _ROW_CITED_GLOSS_RE, _LIST_GLOSS_RE):
v = rx.sub("", v).rstrip()
return v.strip()
# header/caption terms that name the ENTITY column of a typical scalar table
_ENTITY_COL = ("river", "country", "name", "state", "city", "entity", "member")
@@ -1019,7 +1058,7 @@ class KnowledgeExpert:
for i, r in enumerate(rows))
pred = self.answer(question=question, rows=rendered)
return {
"value": pred.value.strip(),
"value": _clean_value(pred.value),
"quote": pred.quote.strip(),
"url": next((r.url for r in rows if r.quote and pred.quote.strip()
and r.quote.strip() in pred.quote.strip()), rows[0].url),