Skip to content

Commit 0185784

Browse files
committed
fix the rules
1 parent 437ae52 commit 0185784

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/judgeval/rules.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212

1313
from judgeval.scorers import APIJudgmentScorer, JudgevalScorer
1414

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
1917

2018
class Condition(BaseModel):
2119
"""
@@ -205,7 +203,7 @@ class AlertResult(BaseModel):
205203
206204
Example:
207205
{
208-
"status": "triggered",
206+
"status": true,
209207
"rule_name": "Quality Check",
210208
"conditions_result": [
211209
{"metric": "faithfulness", "value": 0.6, "threshold": 0.7, "passed": False},
@@ -220,15 +218,19 @@ class AlertResult(BaseModel):
220218
"enabled": true,
221219
"communication_methods": ["slack", "email"],
222220
"email_addresses": ["user1@example.com", "user2@example.com"]
223-
}
221+
},
222+
"combined_type": "all"
224223
}
225224
"""
226-
status: AlertStatus
225+
status: bool # Changed to pure boolean
227226
rule_id: Optional[str] = None # The unique identifier of the rule
228227
rule_name: str
229228
conditions_result: List[Dict[str, Any]]
230229
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
232234

233235
@property
234236
def example_id(self) -> Optional[str]:
@@ -239,6 +241,10 @@ def example_id(self) -> Optional[str]:
239241
def timestamp(self) -> Optional[str]:
240242
"""Get timestamp from metadata for backward compatibility"""
241243
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)
242248

243249
class RulesEngine:
244250
"""
@@ -407,7 +413,7 @@ def evaluate_rules(self, scores: Dict[str, float], example_metadata: Optional[Di
407413
notification_config = rule.notification
408414

409415
# 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
411417

412418
# Create the alert result
413419
alert_result = AlertResult(
@@ -416,7 +422,10 @@ def evaluate_rules(self, scores: Dict[str, float], example_metadata: Optional[Di
416422
rule_name=rule.name,
417423
conditions_result=condition_results,
418424
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
420429
)
421430

422431
results[rule_id] = alert_result

0 commit comments

Comments
 (0)