Derive the judge's schema from Verdict

This commit is contained in:
2026-09-28 22:02:10 +02:00
parent 8b45f1f39b
commit 4d74622617
+11 -14
View File
@@ -2,6 +2,7 @@ import dataclasses
import itertools
import json
import subprocess
import typing
from loop_claude.claude_code.formats import structured_output
from loop_claude.outcome import Failure
@@ -29,20 +30,17 @@ JUDGE_RULES = (
@dataclasses.dataclass(frozen=True)
class Verdict:
evidence: str
evidence: str = dataclasses.field(metadata={"description": "A verbatim quote of the transcript line the verdict rests on: what triggers the interrupt, else what shows the chunk finished or the work remaining."})
finished: bool
interrupt: bool
question: str
question: str = dataclasses.field(metadata={"description": "The single question to put to the human. Empty when interrupt is false."})
VERDICT_TYPES = typing.get_type_hints(Verdict)
JSON_TYPES = {bool: "boolean", str: "string"}
JUDGE_SCHEMA = {
"properties": {
"evidence": {"description": "A verbatim quote of the transcript line the verdict rests on: what triggers the interrupt, else what shows the chunk finished or the work remaining.", "type": "string"},
"finished": {"type": "boolean"},
"interrupt": {"type": "boolean"},
"question": {"description": "The single question to put to the human. Empty when interrupt is false.", "type": "string"},
},
"required": ["evidence", "finished", "interrupt", "question"],
"properties": {field.name: {**field.metadata, "type": JSON_TYPES[VERDICT_TYPES[field.name]]} for field in dataclasses.fields(Verdict)},
"required": list(VERDICT_TYPES),
"type": "object",
}
@@ -94,13 +92,12 @@ def judge_prompt(task, premises, transcript):
def verdict_from(output):
if not isinstance(output, dict):
return Failure("the judge returned no verdict")
for name in JUDGE_SCHEMA["required"]:
kind = JUDGE_SCHEMA["properties"][name]["type"]
if not isinstance(output.get(name), bool if kind == "boolean" else str):
return Failure(f"the judge's verdict has no {name} of type {kind}")
for name, kind in VERDICT_TYPES.items():
if not isinstance(output.get(name), kind):
return Failure(f"the judge's verdict has no {name} of type {JSON_TYPES[kind]}")
if output["interrupt"] and not output["question"].strip():
return Failure("the judge interrupted without a question")
return Verdict(**{name: output[name] for name in JUDGE_SCHEMA["required"]})
return Verdict(**{name: output[name] for name in VERDICT_TYPES})
def grounded(verdict, transcript):