Valid JSON with required keys
1.0 when the output parses as a JSON object containing every required key with the right type.
How it gets gamed
Models wrap JSON in prose or code fences, or emit empty strings. Only a bare object (optionally fenced) parses, and empty strings do not satisfy a str field. See reward hacking.
Use it
Compile a Verifiable-outcome loop, then replace its verify_environment with this one. Put "required" in each JSONL row’s metadata.
Compile a loop for it: Specialized Tool Agents · Inkling 2 Mini
def verify_environment(completion: str, metadata: dict | None = None) -> float: """metadata["required"] maps key -> type name: "str", "int", "float", "bool", "list", "dict".""" import json import re text = completion.strip() fenced = re.fullmatch(r"```(?:json)?\s*(.*?)\s*```", text, flags=re.S) if fenced: text = fenced.group(1) try: obj = json.loads(text) except (ValueError, TypeError): return 0.0 if not isinstance(obj, dict): return 0.0 types_ = {"str": str, "int": int, "float": (int, float), "bool": bool, "list": list, "dict": dict} for key, type_name in ((metadata or {}).get("required") or {}).items(): if key not in obj: return 0.0 value = obj[key] expected = types_.get(type_name) if expected is None: return 0.0 if type_name in ("int", "float") and isinstance(value, bool): return 0.0 if not isinstance(value, expected): return 0.0 if type_name == "str" and not value.strip(): return 0.0 return 1.0
Test cases (run on every build)
"{\"city\": \"Tokyo\", \"days\": 3}" with {"required":{"city":"str","days":"int"}} → 1
"```json\n{\"city\": \"Tokyo\", \"days\": 3}\n```" with {"required":{"city":"str","days":"int"}} → 1
"Sure! {\"city\": \"Tokyo\", \"days\": 3}" with {"required":{"city":"str","days":"int"}} → 0
"{\"city\": \"\", \"days\": 3}" with {"required":{"city":"str","days":"int"}} → 0
"{\"city\": \"Tokyo\", \"days\": true}" with {"required":{"city":"str","days":"int"}} → 0