"""Build the exact judge input for one brief from the released files. No other construction is valid. from judge_input import load_bundle, user_message bundle = load_bundle("path/to/ma-bench") # reads data/cases.jsonl, data/rubric_items.jsonl, scoring/judge_prompt.md system, user = user_message(bundle, "C3", brief_text) The judge sees, per case, the rubric as one JSON object {"items": [...]} whose items carry exactly these ten keys in this naming: id, step, question, pass_condition, fail_condition, source_fact, artifact_anchor, source, tier, severity (pretty-printed, keys sorted). The case header fields come from data/cases.jsonl. This is byte-identical to the input used when the judge was validated against the expert panel. """ from __future__ import annotations import json import re from pathlib import Path RUBRIC_KEYS = { # released column -> key the judge sees "item_id": "id", "step": "step", "question": "question", "pass_condition": "pass_condition", "fail_condition": "fail_condition", "source_fact": "source_fact", "artifact_anchor": "artifact_anchor", "source_documents": "source", "tier": "tier", "severity": "severity", } def load_bundle(root: str | Path) -> dict: root = Path(root) cases = {c["case_id"]: c for c in map(json.loads, open(root / "data" / "cases.jsonl", encoding="utf-8"))} items = [json.loads(line) for line in open(root / "data" / "rubric_items.jsonl", encoding="utf-8")] md = (root / "scoring" / "judge_prompt.md").read_text(encoding="utf-8") blocks = re.findall(r"```\n(.*?)\n```", md, re.S) task_md = (root / "scoring" / "task_prompt.md").read_text(encoding="utf-8") task_blocks = re.findall(r"```\n(.*?)\n```", task_md, re.S) return {"cases": cases, "items": items, "system": blocks[0], "user_template": blocks[1], "task_template": task_blocks[0]} def rubric_json(bundle: dict, case_id: str) -> str: rows = [{RUBRIC_KEYS[k]: i[k] for k in RUBRIC_KEYS} for i in bundle["items"] if i["case_id"] == case_id] return json.dumps({"items": rows}, indent=2, sort_keys=True) def task_text(bundle: dict, case_id: str) -> str: return bundle["task_template"].replace("{op}", bundle["cases"][case_id]["operation"]) def user_message(bundle: dict, case_id: str, brief_text: str) -> tuple[str, str]: c = bundle["cases"][case_id] user = bundle["user_template"].format( case_id=c["case_id"], planning_level=c["planning_level"], document_type=c["document_type"], difficulty=c["difficulty"], task=task_text(bundle, case_id), rubric_json=rubric_json(bundle, case_id), final_content=brief_text, ) return bundle["system"], user