Unit tests pass
1.0 when the generated code plus your hidden tests pass pytest inside a timeout.
How it gets gamed
Models learn to edit or skip tests when they can see them. Keep tests in metadata, never in the prompt, and run untrusted code in a sandbox, not on your laptop. See reward hacking.
Use it
Compile a Verifiable-outcome loop, then replace its verify_environment with this one. Put "tests" in each JSONL row’s metadata. Requires pytest.
Compile a loop for it: Formal Reasoning Engines · Inkling 2 Mini
pytest_pass.pyverify_environment
def verify_environment(completion: str, metadata: dict | None = None) -> float: """Writes completion to solution.py and metadata["tests"] to test_solution.py, runs pytest -q. Run untrusted model code in a sandbox (container, VM, or the Tinker cookbook sandbox helpers). """ import re import subprocess import sys import tempfile from pathlib import Path tests = (metadata or {}).get("tests") if not tests: return 0.0 code = completion fenced = re.search(r"```(?:python)?\s*(.*?)```", completion, flags=re.S) if fenced: code = fenced.group(1) with tempfile.TemporaryDirectory() as tmp: Path(tmp, "solution.py").write_text(code, encoding="utf-8") Path(tmp, "test_solution.py").write_text(str(tests), encoding="utf-8") try: proc = subprocess.run( [sys.executable, "-m", "pytest", "-q", "-p", "no:cacheprovider", tmp], cwd=tmp, timeout=float((metadata or {}).get("timeout", 10)), capture_output=True, check=False, ) except (FileNotFoundError, subprocess.TimeoutExpired): return 0.0 return 1.0 if proc.returncode == 0 else 0.0
Test cases (run on every build)
"```python\ndef add(a, b):\n return a + b\n```" with {"tests":"from solution import add\n\ndef test_add():\n assert add(2, 3) == 5\n"} → 1
"def add(a, b):\n return a - b\n" with {"tests":"from solution import add\n\ndef test_add():\n assert add(2, 3) == 5\n"} → 0