Notifications
Notifications allow you to receive alerts through various communication channels when your rules are triggered. This feature helps you stay informed about potential issues with your AI system's performance in real-time.
Overview
The notification system works with rules to:
- Monitor your evaluation metrics
- Check if they meet your defined conditions
- Send alerts through your preferred channels when conditions are met
Notifications can be configured globally or per rule, allowing you to customize how you're alerted based on the specific rule that was triggered.
Notification Configuration
Notifications are configured using the NotificationConfig
class from the judgeval.rules
(Python) or judgeval
(Typescript) module.
Configuration Options
Parameter (Python) | Parameter (Typescript) | Type | Description |
---|---|---|---|
enabled | enabled | boolean | Whether notifications are enabled (default: True ) |
communication_methods | communicationMethods | array of strings | The methods to use for sending notifications (e.g., ["email", "slack"] ) |
email_addresses | emailAddresses | array of strings | Email addresses to send notifications to |
send_at | sendAt | number (Unix timestamp) | Schedule notifications for a specific time (learn more) |
Basic Configuration
from judgeval.rules import NotificationConfig
# Create a notification configuration
notification_config = NotificationConfig(
enabled=True,
communication_methods=["slack", "email"],
email_addresses=["user@example.com"],
send_at=None # Send immediately
)
Communication Methods
Judgeval supports multiple communication methods for notifications:
"email"
: Send emails to specified email addresses"slack"
: Send messages to configured Slack channels
You can configure multiple methods to be used simultaneously.
Slack Integration
For detailed information on integrating Slack with Judgment notifications, see the Platform Notification Center documentation.
Attaching Notifications to Rules
Notifications can be attached to rules during rule creation or added/configured later.
During Rule Creation
from judgeval.rules import Rule, Condition, NotificationConfig
from judgeval.scorers import FaithfulnessScorer
# Create notification config
notification_config = NotificationConfig(
enabled=True,
communication_methods=["slack", "email"],
email_addresses=["user@example.com"]
)
# Create rule with notification config
rule = Rule(
name="Faithfulness Check",
description="Check if faithfulness meets threshold",
conditions=[
# Note: Only built-in APIScorers are supported
Condition(metric=FaithfulnessScorer(threshold=0.7))
],
combine_type="all", # Trigger when all conditions fail
notification=notification_config
)
Scheduled Notifications
You can schedule one-time notifications to be sent at a specific time using the send_at
/ sendAt
parameter:
from judgeval.rules import NotificationConfig
import time
# Schedule notification for 1 hour from now
one_hour_from_now = int(time.time()) + 3600
notification_config = NotificationConfig(
enabled=True,
communication_methods=["email"],
email_addresses=["user@example.com"],
send_at=one_hour_from_now
)
The send_at
/ sendAt
parameter accepts a Unix timestamp (integer/number) that specifies when the notification should be sent. This is useful for delaying notifications or grouping them to be sent at a specific time of day.
send_at
parameter only delays when a single notification is sent. It doesn't create recurring notifications or group multiple alerts together. Each time a rule is triggered, a separate notification is generated.Notification Types in the Platform
The Judgment Platform offers two main types of notifications:
-
Evaluation Alerts - Real-time notifications sent when specific rules are triggered. When using the API, these can be scheduled for a specific time using the
send_at
parameter. -
Custom Alert Recaps - Periodic summaries (daily, weekly, monthly) of evaluation metrics and alerts. These are configured in the Platform Notification Center.
Setting Up Custom Alert Recaps
To set up periodic notification summaries:
- Navigate to the Notifications page in your Judgment account settings
- Under "Custom Alert Recaps," click the "+" button to create a new report
- Configure your preferred frequency (Daily, Weekly, Monthly) and delivery time
- Add recipient email addresses
For more details, see the Scheduled Reports documentation.
Judgment Platform Features
For information about configuring notifications in the Judgment web platform, including email alerts, scheduled reports, and Slack integration, see the Platform Notification Center documentation.
Practical Example
Here's a complete example showing how to set up rules with notifications and integrate them with the Tracer:
import os
from judgeval.common.tracer import Tracer, wrap
from judgeval.scorers import FaithfulnessScorer, AnswerRelevancyScorer
from judgeval.rules import Rule, Condition, NotificationConfig
from openai import OpenAI
# Create notification config
notification_config = NotificationConfig(
enabled=True,
communication_methods=["slack", "email"],
email_addresses=["alerts@example.com"],
send_at=None # Send immediately
)
# Create rules with notification config
rules = [
Rule(
name="Quality Check",
description="Check if all quality metrics meet thresholds",
conditions=[
# Only built-in APIScorers can be used as metrics
Condition(metric=FaithfulnessScorer(threshold=0.7)),
Condition(metric=AnswerRelevancyScorer(threshold=0.8))
],
combine_type="all", # Trigger when all conditions fail
notification=notification_config
)
]
# Initialize tracer with rules for notifications
judgment = Tracer(
# api_key=os.getenv("JUDGMENT_API_KEY"), # Key read automatically
project_name="my_project",
rules=rules
)
# Wrap OpenAI client for tracing
client = wrap(OpenAI())
# Now any evaluations that trigger the rules will send notifications