import json import re def extract_json(text: str) -> dict | None: """ Match the JSON extraction logic used during checkpoint evaluation: find the first decodable JSON object in the generated text. """ decoder = json.JSONDecoder() for match in re.finditer(r"\{", text): try: obj, _ = decoder.raw_decode(text[match.start():]) if isinstance(obj, dict): return obj except json.JSONDecodeError: pass return None