MCPcopy Create free account
hub / github.com/ScaleML/AgentSPEX / _parse_score_json

Function _parse_score_json

src/benchmarks/writing_bench/evaluate.py:30–52  ·  view source on GitHub ↗

Parse the judge's JSON response, tolerating markdown fences.

(raw: str)

Source from the content-addressed store, hash-verified

28
29
30def _parse_score_json(raw: str) -> Optional[dict]:
31 """Parse the judge's JSON response, tolerating markdown fences."""
32 cleaned = raw.strip().strip("`").removeprefix("json").strip()
33 try:
34 result = json.loads(cleaned)
35 except json.JSONDecodeError:
36 # Try extracting JSON from markdown code block
37 m = re.search(r"\{[^{}]*\}", raw, re.DOTALL)
38 if not m:
39 return None
40 try:
41 result = json.loads(m.group())
42 except json.JSONDecodeError:
43 return None
44
45 if (
46 isinstance(result, dict)
47 and isinstance(result.get("score"), int)
48 and 1 <= result["score"] <= 10
49 and isinstance(result.get("reason"), str)
50 ):
51 return result
52 return None
53
54
55def _call_judge(

Callers 1

_call_judgeFunction · 0.85

Calls 1

getMethod · 0.80

Tested by

no test coverage detected