from __future__ import annotations import math def clamp_score(raw: float) -> float: # Validator requires strictly between 0 and 1, not 0.0 or 1.0. try: value = float(raw) except (TypeError, ValueError): value = 0.0 if not math.isfinite(value): value = 0.0 return max(0.01, min(0.99, round(value, 4)))