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 itertools
import json import json
import subprocess import subprocess
import typing
from loop_claude.claude_code.formats import structured_output from loop_claude.claude_code.formats import structured_output
from loop_claude.outcome import Failure from loop_claude.outcome import Failure
@@ -29,20 +30,17 @@ JUDGE_RULES = (
@dataclasses.dataclass(frozen=True) @dataclasses.dataclass(frozen=True)
class Verdict: 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 finished: bool
interrupt: 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 = { JUDGE_SCHEMA = {
"properties": { "properties": {field.name: {**field.metadata, "type": JSON_TYPES[VERDICT_TYPES[field.name]]} for field in dataclasses.fields(Verdict)},
"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"}, "required": list(VERDICT_TYPES),
"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"],
"type": "object", "type": "object",
} }
@@ -94,13 +92,12 @@ def judge_prompt(task, premises, transcript):
def verdict_from(output): def verdict_from(output):
if not isinstance(output, dict): if not isinstance(output, dict):
return Failure("the judge returned no verdict") return Failure("the judge returned no verdict")
for name in JUDGE_SCHEMA["required"]: for name, kind in VERDICT_TYPES.items():
kind = JUDGE_SCHEMA["properties"][name]["type"] if not isinstance(output.get(name), kind):
if not isinstance(output.get(name), bool if kind == "boolean" else str): return Failure(f"the judge's verdict has no {name} of type {JSON_TYPES[kind]}")
return Failure(f"the judge's verdict has no {name} of type {kind}")
if output["interrupt"] and not output["question"].strip(): if output["interrupt"] and not output["question"].strip():
return Failure("the judge interrupted without a question") 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): def grounded(verdict, transcript):