From 4d746226172fa7289f1c5aeb6de0a622b0636ff8 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 28 Sep 2026 22:02:10 +0200 Subject: [PATCH] Derive the judge's schema from Verdict --- bin/loop_claude/claude_runs/judge.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/bin/loop_claude/claude_runs/judge.py b/bin/loop_claude/claude_runs/judge.py index 2934c2a3..c8f22b18 100644 --- a/bin/loop_claude/claude_runs/judge.py +++ b/bin/loop_claude/claude_runs/judge.py @@ -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):