fix(llm_as_a_judge): use float sum with tolerance for weight validation

This commit is contained in:
Ishaan Jaffer 2026-04-23 19:58:14 -07:00
parent 3064834f7e
commit 55ae8b1a16
No known key found for this signature in database

View file

@ -258,8 +258,8 @@ def initialize_guardrail(
if not criteria:
raise ValueError("llm_as_a_judge guardrail requires at least one criterion")
weight_total = sum(int(c.get("weight", 0)) for c in criteria)
if weight_total != 100:
weight_total = sum(float(c.get("weight", 0)) for c in criteria)
if abs(weight_total - 100) > 0.5:
raise ValueError(
f"llm_as_a_judge criterion weights must sum to 100 (got {weight_total})"
)