2020
2121import re
2222from dataclasses import dataclass
23+ from decimal import Decimal , InvalidOperation
2324
2425from .turns import Interaction
2526
@@ -125,12 +126,18 @@ def check_policy_violation(inter: Interaction) -> list[Finding]:
125126 """
126127 out : list [Finding ] = []
127128 max_refund = inter .policy .get ("max_refund" )
128- if max_refund is None :
129+ normalized_max_refund = _finite_decimal (max_refund )
130+ if normalized_max_refund is None :
129131 return out
130132 for i , t in enumerate (inter .turns ):
131133 for a in t .actions :
132134 amount = a .args .get ("amount" )
133- if a .name == "refund" and isinstance (amount , (int , float )) and amount > max_refund :
135+ normalized_amount = _finite_decimal (amount )
136+ if (
137+ a .name == "refund"
138+ and normalized_amount is not None
139+ and normalized_amount > normalized_max_refund
140+ ):
134141 out .append (
135142 Finding (
136143 "policy_violation" ,
@@ -143,6 +150,18 @@ def check_policy_violation(inter: Interaction) -> list[Finding]:
143150 return out
144151
145152
153+ def _finite_decimal (value : object ) -> Decimal | None :
154+ if isinstance (value , bool ) or not isinstance (value , (int , float , str )):
155+ return None
156+ if isinstance (value , str ) and not value .strip ():
157+ return None
158+ try :
159+ number = Decimal (str (value ).strip ())
160+ except InvalidOperation :
161+ return None
162+ return number if number .is_finite () else None
163+
164+
146165def check_latency (inter : Interaction , budget_s : float = 1.5 ) -> list [Finding ]:
147166 """Silence between the caller finishing and the agent starting.
148167
0 commit comments