Skip to content

armgit / Soup

Public Imported from GitHub
0

Fine-tune LLMs from one YAML. Layer streaming trains an 8B model on a 4 GB laptop GPU.

fix(eval): refuse judge tasks with no prompt measurements (#1928)

Nurkhan Esenbek49aee751008c
diff --git a/changelog.d/0.76.0/1928.fixed.md b/changelog.d/0.76.0/1928.fixed.md
new file mode 100644
index 00000000..2bf80b17
--- /dev/null
+++ b/changelog.d/0.76.0/1928.fixed.md
@@ -0,0 +1 @@
+- Empty judge prompt files now fail eval gates with a task/file diagnostic and no measured score, preventing an unmeasured zero baseline (#1928 by @kok-o).
diff --git a/docs/evaluation.md b/docs/evaluation.md
index 5fcb69a5..8e73b624 100644
--- a/docs/evaluation.md
+++ b/docs/evaluation.md
@@ -267,6 +267,10 @@ smoke generator are unchanged (#1798).
Baselines may be a registry reference (`registry://<name-or-id>`), a file path, or omitted for the first run. A registry baseline uses the newest eval row for each benchmark — re-measuring a benchmark replaces its baseline score — and warns, per benchmark, when that row's scorer stamp is missing or from a different scorer revision. A task whose evaluation raises (`ValueError`, `FileNotFoundError`, `OSError`, or a judge that stays unreachable) gets no score and fails the gate closed under `on_regression: stop`; the log line lists it as a task that could not be scored, with the error, rather than as a regression (#1447).
+A zero-byte or whitespace-only judge prompt file is an input error naming the
+task and file. It has no measured score, fails the gate even at threshold zero,
+and cannot create or replace a baseline when no other task was scored.
+
## Sequential A/B Harness (`soup ab`)
diff --git a/src/soup_cli/eval/gate.py b/src/soup_cli/eval/gate.py
index 250eef87..73ea23e1 100644
--- a/src/soup_cli/eval/gate.py
+++ b/src/soup_cli/eval/gate.py
@@ -522,7 +522,7 @@ def _run_judge_task(
})
if not items:
- return 0.0
+ raise ValueError(f"No judge prompts found in {task.prompts} for task '{task.name}'")
results = evaluator.evaluate_batch(items)
# Normalise to [0, 1] using the judge's ACTUAL rubric scale (DEFAULT_RUBRIC
diff --git a/tests/test_eval_gate_empty_judge_input.py b/tests/test_eval_gate_empty_judge_input.py
new file mode 100644
index 00000000..6aeb6960
--- /dev/null
+++ b/tests/test_eval_gate_empty_judge_input.py
@@ -0,0 +1,175 @@
+"""A judge task with no prompts has no measured score or baseline (#1910)."""
+
+from __future__ import annotations
+
+import json
+from pathlib import Path
+
+import pytest
+import yaml
+from rich.console import Console
+from typer.testing import CliRunner
+
+from soup_cli.cli import app
+from soup_cli.commands import eval as eval_command
+from soup_cli.eval import gate, quant_check
+from soup_cli.eval.judge import JudgeEvaluator
+from tests.conftest import strip_ansi
+
+
+def _task(path: Path, threshold: float = 0.0, kind: str = "judge") -> gate.GateTask:
+ return gate.GateTask(
+ name="input-control", type=kind, threshold=threshold,
+ prompts=str(path) if kind == "judge" else None,
+ tasks=str(path) if kind == "custom" else None,
+ judge_model="ollama://synthetic" if kind == "judge" else None,
+ )
+
+
+def calls(monkeypatch: pytest.MonkeyPatch) -> dict[str, list[str]]:
+ recorded: dict[str, list[str]] = {"generate": [], "judge": []}
+
+ def judge(self: JudgeEvaluator, prompt: str) -> str:
+ recorded["judge"].append(prompt)
+ return json.dumps({
+ "scores": {"helpfulness": 5, "accuracy": 5, "safety": 5},
+ "reasoning": "valid measured control",
+ })
+
+ monkeypatch.setattr(JudgeEvaluator, "_call_llm", judge)
+ monkeypatch.setattr(
+ quant_check, "make_model_generator",
+ lambda model: lambda prompt: recorded["generate"].append(prompt) or "gold",
+ )
+ monkeypatch.setattr(eval_command, "console", Console(width=200))
+ return recorded
+
+
[email protected]("body", ["", " \n\t\n"], ids=["zero-byte", "whitespace"])
[email protected]("threshold", [0.0, 0.5])
[email protected]("kind", ["judge", "custom"])
+def test_empty_input_has_no_score(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch, calls: dict[str, list[str]],
+ body: str, threshold: float, kind: str,
+) -> None:
+ monkeypatch.chdir(tmp_path)
+ path = tmp_path / "prompts.jsonl"
+ path.write_text(body, encoding="utf-8")
+ task = _task(path, threshold, kind)
+ result = gate.run_gate(
+ gate.EvalSuite(suite="input-control", tasks=[task]),
+ generate_fn=lambda prompt: calls["generate"].append(prompt) or "gold",
+ )
+ assert result.passed is False
+ row = result.task_results[0]
+ assert row.score is None
+ assert row.passed is False
+ assert row.delta is None
+ assert row.error is not None and str(path) in row.error
+ if kind == "judge":
+ assert "input-control" in row.error
+ assert "No judge prompts found" in row.error
+ else:
+ assert "No eval tasks found" in row.error
+ assert calls == {"generate": [], "judge": []}
+
+
+def _suite(tmp_path: Path, task: gate.GateTask) -> Path:
+ path = tmp_path / "gate.yaml"
+ path.write_text(yaml.safe_dump({
+ "suite": "input-control", "tasks": [task.model_dump(exclude_none=True)],
+ }), encoding="utf-8")
+ return path
+
+
[email protected]("body", ["", " \n\t\n"], ids=["zero-byte", "whitespace"])
[email protected]("threshold", [0.0, 0.5])
[email protected]("write", [False, True], ids=["gate-only", "write-baseline"])
[email protected]("existing", [False, True], ids=["new-baseline", "existing-baseline"])
+def test_cli_empty_judge_cannot_pass_or_mint_baseline(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch, calls: dict[str, list[str]],
+ body: str, threshold: float, write: bool, existing: bool,
+) -> None:
+ monkeypatch.chdir(tmp_path)
+ prompts = tmp_path / "prompts.jsonl"
+ prompts.write_text(body, encoding="utf-8")
+ suite = _suite(tmp_path, _task(prompts, threshold))
+ baseline = tmp_path / "baseline.json"
+ original = b'{"scores": {"older": 0.75}}\n'
+ if existing:
+ baseline.write_bytes(original)
+ args = ["eval", "gate", "--suite", str(suite), "--model", "synthetic"]
+ if write:
+ args.extend(["--write-baseline", str(baseline)])
+ result = CliRunner().invoke(app, args)
+ output = " ".join(strip_ansi(result.output).split())
+ assert result.exit_code == (1 if write else 2), output
+ assert "GATE FAILED" in output
+ assert "GATE PASSED" not in output
+ assert "No judge prompts found" in output
+ assert "prompts.jsonl" in output
+ assert "Wrote stamped baseline" not in output
+ assert calls == {"generate": [], "judge": []}
+ if existing:
+ assert baseline.read_bytes() == original
+ else:
+ assert not baseline.exists()
+
+
[email protected]("kind", ["judge", "custom"])
[email protected]("passes", [False, True], ids=["measured-failure", "measured-pass"])
+def test_nonempty_cli_measures_and_writes_baseline(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch, calls: dict[str, list[str]], kind: str,
+ passes: bool,
+) -> None:
+ monkeypatch.chdir(tmp_path)
+ prompts = tmp_path / "prompts.jsonl"
+ prompts.write_text(
+ json.dumps({"prompt": "question", "expected": "gold"}) + "\n", encoding="utf-8",
+ )
+ suite = _suite(tmp_path, _task(prompts, 0.5, kind))
+ baseline = tmp_path / "baseline.json"
+ if not passes:
+ monkeypatch.setattr(
+ quant_check, "make_model_generator",
+ lambda model: lambda prompt: calls["generate"].append(prompt) or "wrong",
+ )
+
+ def low_judge(self: JudgeEvaluator, prompt: str) -> str:
+ calls["judge"].append(prompt)
+ return json.dumps({"scores": {"helpfulness": 1, "accuracy": 1, "safety": 1}})
+
+ monkeypatch.setattr(JudgeEvaluator, "_call_llm", low_judge)
+ result = CliRunner().invoke(app, [
+ "eval", "gate", "--suite", str(suite), "--model", "synthetic",
+ "--write-baseline", str(baseline),
+ ])
+ assert result.exit_code == (0 if passes else 2), result.output
+ assert ("GATE PASSED" if passes else "GATE FAILED") in strip_ansi(result.output)
+ payload = json.loads(baseline.read_text(encoding="utf-8"))
+ assert payload["scores"] == {"input-control": 1.0 if passes else 0.0}
+ assert payload["provenance"]
+ assert calls["generate"] == ["question"]
+ assert len(calls["judge"]) == (1 if kind == "judge" else 0)
+
+
[email protected]("body", ["{broken\n", '{"prompt": "question"}\n'])
+def test_existing_invalid_json_and_valid_judge_input(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch, calls: dict[str, list[str]], body: str,
+) -> None:
+ monkeypatch.chdir(tmp_path)
+ path = tmp_path / "prompts.jsonl"
+ path.write_text(body, encoding="utf-8")
+ result = gate.run_gate(
+ gate.EvalSuite(suite="control", tasks=[_task(path)]),
+ generate_fn=lambda prompt: calls["generate"].append(prompt) or "gold",
+ baseline={"input-control": 1.0},
+ )
+ row = result.task_results[0]
+ if body.startswith("{broken"):
+ assert row.score is None and "invalid JSONL" in row.error
+ assert calls == {"generate": [], "judge": []}
+ else:
+ assert result.passed is True and row.score == 1.0 and row.error is None
+ assert calls["generate"] == ["question"] and len(calls["judge"]) == 1