knowledge: the prover wired — translate->validate->prove, no judge in the loop (phase 3b)
The LLM at the INPUT boundary only: one structured-output call (TranslateToDSL — question + the store's relation vocabulary in, typed DSL out), VALIDATED before execution (validate_query: the shared grammar — unknown filter/select, empty rel_any, malformed lookup are rejected deterministically; a mistranslation can never reach evaluate()). The evaluator (3a) closes the path; re-execution IS the check. _prover_answer runs BEFORE any judge: a closed path returns the answer with verified=True and the proof term; a multi-binding returns the SET with ambiguous=True + alternatives (the three readings as what they are — deterministic, no ablation rounds, no (K5) surface: the judge never sees these questions). No translation / no closed path / re-execution mismatch -> the judge path, unchanged; the prover can never kill a run. Wiring is additive: answer_question tries the prover first, falls back honestly. Tests: translate_dsl.py 4/4 (signature, live-shape translation, mistranslation rejection, honest decline -> None).
This commit is contained in:
@@ -41,6 +41,48 @@ from .store import KnowledgeStore, norm_name
|
||||
|
||||
_THIS_YEAR = "2026" # open_now: an open end or an end >= today coexists
|
||||
|
||||
_KNOWN_FILTERS = {"open_now", "before", "neq_value"}
|
||||
_KNOWN_SELECTS = {"all", "latest_end"}
|
||||
|
||||
|
||||
def validate_query(q: Any) -> tuple[bool, str]:
|
||||
"""The shared grammar: a DSL term type-checks BEFORE evaluation.
|
||||
|
||||
The translator (LLM) proposes; this deterministic gate decides. A
|
||||
mistranslation surfaces as an invalid term — unknown filter, unknown
|
||||
select, empty rel_any, malformed lookup — and NEVER reaches
|
||||
evaluate(): no wrong answer can hide inside an unexecutable query.
|
||||
Returns (ok, reason).
|
||||
"""
|
||||
if not isinstance(q, dict) or not q:
|
||||
return False, "empty or non-dict query"
|
||||
lookups = q.get("lookup")
|
||||
if isinstance(lookups, dict):
|
||||
lookups = [lookups]
|
||||
if not lookups or not isinstance(lookups, list):
|
||||
return False, "no lookup"
|
||||
for lk in lookups:
|
||||
if not isinstance(lk, dict) or not lk.get("subject"):
|
||||
return False, "lookup without subject"
|
||||
if not lk.get("rel_any"):
|
||||
return False, "lookup without rel_any"
|
||||
if not isinstance(lk["rel_any"], list):
|
||||
return False, "rel_any not a list"
|
||||
if not lk.get("bind"):
|
||||
return False, "lookup without bind var"
|
||||
for f in q.get("filter", []):
|
||||
if not isinstance(f, dict) or len(f) != 1:
|
||||
return False, f"malformed filter {f!r}"
|
||||
key = next(iter(f))
|
||||
if key not in _KNOWN_FILTERS:
|
||||
return False, f"unknown filter {key!r}"
|
||||
if not isinstance(f[key], list):
|
||||
return False, f"filter args not a list: {key}"
|
||||
sel = q.get("select", "all")
|
||||
if sel not in _KNOWN_SELECTS:
|
||||
return False, f"unknown select {sel!r}"
|
||||
return True, "ok"
|
||||
|
||||
|
||||
@dataclass
|
||||
class Step:
|
||||
|
||||
Reference in New Issue
Block a user