12
12
13
13
from judgeval .scorers import APIJudgmentScorer , JudgevalScorer
14
14
15
- class AlertStatus (str , Enum ):
16
- """Status of an alert evaluation."""
17
- TRIGGERED = "triggered"
18
- NOT_TRIGGERED = "not_triggered"
15
+ # Alert status - using boolean instead of string enum
16
+ AlertStatus = bool # True = triggered, False = not triggered
19
17
20
18
class Condition (BaseModel ):
21
19
"""
@@ -205,7 +203,7 @@ class AlertResult(BaseModel):
205
203
206
204
Example:
207
205
{
208
- "status": "triggered" ,
206
+ "status": true ,
209
207
"rule_name": "Quality Check",
210
208
"conditions_result": [
211
209
{"metric": "faithfulness", "value": 0.6, "threshold": 0.7, "passed": False},
@@ -220,15 +218,19 @@ class AlertResult(BaseModel):
220
218
"enabled": true,
221
219
"communication_methods": ["slack", "email"],
222
220
"email_addresses": ["user1@example.com", "user2@example.com"]
223
- }
221
+ },
222
+ "combined_type": "all"
224
223
}
225
224
"""
226
- status : AlertStatus
225
+ status : bool # Changed to pure boolean
227
226
rule_id : Optional [str ] = None # The unique identifier of the rule
228
227
rule_name : str
229
228
conditions_result : List [Dict [str , Any ]]
230
229
metadata : Dict [str , Any ] = {}
231
- notification : Optional [NotificationConfig ] = None # Configuration for notifications
230
+ notification : Optional [NotificationConfig ] = None
231
+ combined_type : Optional [str ] = None # Changed from types to combined_type
232
+ project_id : Optional [str ] = None # Added project_id
233
+ trace_span_id : Optional [str ] = None # Added trace_span_id
232
234
233
235
@property
234
236
def example_id (self ) -> Optional [str ]:
@@ -239,6 +241,10 @@ def example_id(self) -> Optional[str]:
239
241
def timestamp (self ) -> Optional [str ]:
240
242
"""Get timestamp from metadata for backward compatibility"""
241
243
return self .metadata .get ("timestamp" )
244
+
245
+ def model_dump (self , ** kwargs ):
246
+ """Convert the AlertResult to a dictionary - status is already boolean."""
247
+ return super ().model_dump (** kwargs )
242
248
243
249
class RulesEngine :
244
250
"""
@@ -407,7 +413,7 @@ def evaluate_rules(self, scores: Dict[str, float], example_metadata: Optional[Di
407
413
notification_config = rule .notification
408
414
409
415
# Set the alert status based on whether the rule was triggered
410
- status = AlertStatus . TRIGGERED if triggered else AlertStatus . NOT_TRIGGERED
416
+ status = triggered # Now using boolean directly
411
417
412
418
# Create the alert result
413
419
alert_result = AlertResult (
@@ -416,7 +422,10 @@ def evaluate_rules(self, scores: Dict[str, float], example_metadata: Optional[Di
416
422
rule_name = rule .name ,
417
423
conditions_result = condition_results ,
418
424
notification = notification_config ,
419
- metadata = example_metadata or {}
425
+ metadata = example_metadata or {},
426
+ combined_type = rule .combine_type ,
427
+ project_id = example_metadata .get ("project_id" ) if example_metadata else None ,
428
+ trace_span_id = example_metadata .get ("trace_span_id" ) if example_metadata else None
420
429
)
421
430
422
431
results [rule_id ] = alert_result
0 commit comments