Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/benchflow/templates/judge.py.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,19 @@ def judge_with_llm(trajectory_text: str) -> float:
return 0.0


def exact_ground_truth_pattern(ground_truth: str) -> re.Pattern:
"""Return a regex that matches a standalone exact ground-truth string."""
return re.compile(r"(?<!\w)" + re.escape(ground_truth) + r"(?!\w)")


def judge_exact_match() -> float:
"""Fallback: exact string match against ground_truth."""
ground_truth = CASE.get("ground_truth", "").strip()
if not ground_truth:
return 0.0

pattern = exact_ground_truth_pattern(ground_truth)

# Only check agent output files, not arbitrary filesystem content
search_paths = [AGENT_LOG_DIR, APP_DIR]
for search_root in search_paths:
Expand All @@ -179,8 +186,9 @@ def judge_exact_match() -> float:
continue
try:
content = f.read_text()
# Check for exact match on word boundaries (not substring)
if re.search(r'\b' + re.escape(ground_truth) + r'\b', content):
# Check for an exact standalone answer without requiring
# code-like punctuation such as ")" to form a word boundary.
if pattern.search(content):
return 1.0
except (UnicodeDecodeError, PermissionError):
pass
Expand Down
59 changes: 59 additions & 0 deletions tests/test_skill_eval_sweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

import json
import math
import os
import subprocess
import sys
import tomllib
from pathlib import Path

Expand Down Expand Up @@ -174,6 +177,62 @@ def test_generated_test_sh_copies_judge_result(self, tmp_path):
assert "/logs/verifier/judge_result.json" in test_sh


# Issue #897 — exact-match judge delimiter handling


class TestExactMatchJudgeDelimiters:
"""Guards #897: exact-match judge handles code-like answer delimiters."""

@pytest.mark.parametrize(
("content", "expected_reward"),
[
("The method is getPageCount().\n", 1.0),
("The method is getPageCount()Wrapper.\n", 0.0),
],
)
def test_non_word_suffix_ground_truth_uses_word_char_delimiters(
self, tmp_path, content, expected_reward
):
"""Guards PR #900 / issue #897 against punctuated exact answers."""
skill_dir = tmp_path / "skill"
skill_dir.mkdir()
ds = EvalDataset(
skill_name="method-skill",
skill_dir=skill_dir,
cases=[
EvalCase(
id="case-001",
question="Which method returns the page count?",
ground_truth="getPageCount()",
)
],
)
task = generate_tasks(ds, tmp_path / "tasks", with_skill=False)[0]
verifier_dir = TaskPaths(task).tests_dir

agent_log_dir = tmp_path / "logs" / "agent"
agent_log_dir.mkdir(parents=True)
(agent_log_dir / "answer.txt").write_text(content)

workspace = tmp_path / "workspace"
workspace.mkdir()
subprocess.run(
[sys.executable, str(verifier_dir / "judge.py")],
check=True,
env={
**os.environ,
"BENCHFLOW_VERIFIER_DIR": str(verifier_dir),
"BENCHFLOW_AGENT_LOG_DIR": str(agent_log_dir),
"BENCHFLOW_WORKSPACE": str(workspace),
},
text=True,
capture_output=True,
)

reward = json.loads((verifier_dir / "reward.json").read_text())
assert reward == {"reward": expected_reward}


# Issue #424 — evals.json schema validation


Expand Down
Loading