Given aggregate candidate metadata, prefer examples with high model
uncertainty, high user impact, undercovered slices, and recent
regressions. Exclude disallowed consent scopes and cap each slice so
one noisy cohort cannot consume the whole review batch.
Hidden answer: Python solution
import math
def finite_number(value, name):
if isinstance(value, bool) or not isinstance(value, (int, float)):
raise ValueError(f"{name} must be numeric")
if not math.isfinite(value):
raise ValueError(f"{name} must be finite")
return float(value)
def rank_review_candidates(records, allowed_scopes, max_per_slice=2, min_slice_count=20):
if not isinstance(max_per_slice, int) or max_per_slice <= 0:
raise ValueError("max_per_slice must be a positive integer")
if not isinstance(min_slice_count, int) or min_slice_count <= 0:
raise ValueError("min_slice_count must be a positive integer")
ranked = []
for row in records:
if row["consent_scope"] not in allowed_scopes:
continue
slice_id = row["slice_id"]
if not isinstance(slice_id, str) or not slice_id:
raise ValueError("slice_id must be a non-empty string")
confidence = finite_number(row["confidence"], "confidence")
daily_sessions = finite_number(row["daily_sessions"], "daily_sessions")
slice_coverage = finite_number(row["slice_coverage"], "slice_coverage")
if not 0.0 <= confidence <= 1.0:
raise ValueError("confidence must be between 0 and 1")
if daily_sessions < 0:
raise ValueError("daily_sessions must be non-negative")
if not 0.0 <= slice_coverage <= 1.0:
raise ValueError("slice_coverage must be between 0 and 1")
slice_count = finite_number(row.get("slice_count", min_slice_count), "slice_count")
if slice_count < 0:
raise ValueError("slice_count must be non-negative")
if not isinstance(row["recent_regression"], bool):
raise ValueError("recent_regression must be boolean")
if not isinstance(row.get("sensitive_proxy", False), bool):
raise ValueError("sensitive_proxy must be boolean")
if row.get("sensitive_proxy", False) and slice_count < min_slice_count:
slice_id = "bucketed_sensitive_proxy"
uncertainty = 1.0 - confidence
impact = min(daily_sessions / 1000.0, 3.0)
coverage_gap = 1.5 if slice_coverage < 0.2 else 0.0
regression = 2.0 if row["recent_regression"] else 0.0
privacy_penalty = 1.0 if row.get("sensitive_proxy", False) else 0.0
score = uncertainty + impact + coverage_gap + regression - privacy_penalty
ranked.append((score, row["candidate_id"], slice_id))
ranked.sort(key=lambda item: (-item[0], item[1]))
selected = []
per_slice = {}
for score, candidate_id, slice_id in ranked:
if per_slice.get(slice_id, 0) >= max_per_slice:
continue
selected.append(candidate_id)
per_slice[slice_id] = per_slice.get(slice_id, 0) + 1
return selected