skills/ai-generating-notifications/SKILL.md
Generate smart notification messages from structured events using AI. Use when writing push notification copy, creating alert messages from events, building weekly digest emails, summarizing incidents from logs, personalizing notification text, generating Slack alerts from system events, smart email subject lines, aggregating multiple events into one digest message, notification copy for mobile apps, incident summary notifications, AI-powered alert messages, context-aware push notifications.
npx skillsauth add lebsral/dspy-programming-not-prompting-lms-skills ai-generating-notificationsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Guide the user through building AI that turns structured events into useful, channel-appropriate notification messages. Uses DSPy to produce consistent, personalized notification copy with urgency calibration and digest aggregation.
Ask the user:
import dspy
from typing import Literal
lm = dspy.LM("openai/gpt-4o-mini") # or "anthropic/claude-sonnet-4-5-20250929", etc.
dspy.configure(lm=lm)
class GenerateNotification(dspy.Signature):
"""Write a clear, concise notification message for the target channel and recipient."""
event: str = dspy.InputField(desc="Structured event data or description")
recipient_profile: str = dspy.InputField(desc="Who receives the notification - role, name, preferences")
channel: Literal["push", "email", "slack", "sms"] = dspy.InputField(desc="Delivery channel")
notification_text: str = dspy.OutputField(desc="The notification message, respecting channel length limits")
urgency_level: Literal["low", "medium", "high", "critical"] = dspy.OutputField(
desc="Urgency level - low=informational, medium=needs attention, high=act soon, critical=act now"
)
notifier = dspy.ChainOfThought(GenerateNotification)
result = notifier(
event="User account login from new device - IP 203.0.113.42, Berlin, Germany",
recipient_profile="Account owner, security-conscious, email preferred",
channel="email",
)
print(result.notification_text)
print(result.urgency_level)
Each channel has hard limits. Define them explicitly and enforce with a reward function.
| Channel | Title limit | Body limit | Format | |---------|-------------|------------|--------| | Push (iOS/Android) | 50 chars | 100 chars | Plain text | | Email | ~60 chars subject | 1-3 short paragraphs | HTML or plain | | Slack | N/A | ~500 chars | Markdown blocks | | SMS | N/A | 160 chars total | Plain text only |
CHANNEL_LIMITS = {
"push": 150, # title + body combined
"email": 500, # subject + preview text
"slack": 500,
"sms": 160,
}
def channel_length_reward(args, pred):
"""Hard penalty for exceeding channel length limits."""
limit = CHANNEL_LIMITS.get(args["channel"], 300)
text_len = len(pred.notification_text)
if text_len <= limit:
return 1.0
# Hard fail above 2x limit, graduated penalty between limit and 2x
if text_len > limit * 2:
return 0.0
return max(0.0, 1.0 - (text_len - limit) / limit)
notifier_enforced = dspy.Refine(
module=dspy.ChainOfThought(GenerateNotification),
N=3,
reward_fn=channel_length_reward,
threshold=0.9,
)
Group multiple events into a single summary notification — reduces alert fatigue.
from pydantic import BaseModel, Field
class DigestOutput(BaseModel):
subject: str = Field(description="Email subject line, max 60 chars")
headline: str = Field(description="One-sentence summary of the most important event")
event_groups: list[str] = Field(description="Events grouped by type, e.g. '3 new comments, 2 deployments'")
call_to_action: str = Field(description="What the user should do next, if anything")
class GenerateDigest(dspy.Signature):
"""Aggregate multiple events into a single digest notification. Group similar events, highlight the most important, and keep it scannable."""
events: list[str] = dspy.InputField(desc="List of events to include in the digest")
recipient_profile: str = dspy.InputField(desc="Who receives the digest")
time_period: str = dspy.InputField(desc="Time window covered - e.g. 'last 24 hours', 'this week'")
digest: DigestOutput = dspy.OutputField()
class DigestNotifier(dspy.Module):
def __init__(self):
self.group = dspy.ChainOfThought("events -> grouped_events: list[str]")
self.write = dspy.ChainOfThought(GenerateDigest)
def forward(self, events, recipient_profile, time_period):
# Group similar events first, then write the digest
grouped = self.group(events=events).grouped_events
return self.write(
events=grouped,
recipient_profile=recipient_profile,
time_period=time_period,
)
Prevent over-alerting by calibrating urgency against event severity and recipient fatigue.
class CalibrateUrgency(dspy.Signature):
"""Assess the urgency of this event for this recipient. Consider event severity, recipient role, and whether action is required."""
event: str = dspy.InputField(desc="Event description")
recipient_profile: str = dspy.InputField(desc="Recipient role and preferences")
recent_notification_count: int = dspy.InputField(
desc="Number of notifications sent to this recipient in the last hour"
)
urgency_level: Literal["low", "medium", "high", "critical"] = dspy.OutputField()
should_send: bool = dspy.OutputField(
desc="False if recipient is already overloaded with high-urgency alerts"
)
rationale: str = dspy.OutputField(desc="One sentence explaining the urgency decision")
def urgency_reward(args, pred):
"""Penalize assigning high/critical urgency to clearly informational events."""
score = 1.0
informational_keywords = ["viewed", "logged in", "updated preferences", "exported"]
event_lower = args["event"].lower()
if any(kw in event_lower for kw in informational_keywords):
if pred.urgency_level in ("high", "critical"):
score -= 0.5 # soft: informational events should not be urgent
return score
urgency_calibrator = dspy.Refine(
module=dspy.ChainOfThought(CalibrateUrgency),
N=3,
reward_fn=urgency_reward,
threshold=0.8,
)
Recipient context should influence tone, detail level, and channel preference.
class PersonalizedNotification(dspy.Signature):
"""Write a notification tailored to the recipient. Match tone to their role, include relevant context, and use their preferred channel style."""
event: str = dspy.InputField(desc="Structured event data")
recipient_name: str = dspy.InputField(desc="Recipient's name")
recipient_role: str = dspy.InputField(desc="e.g. 'developer', 'executive', 'end user'")
recipient_preferences: str = dspy.InputField(
desc="e.g. 'brief and technical', 'plain language', 'include numbers'"
)
channel: Literal["push", "email", "slack", "sms"] = dspy.InputField()
notification_text: str = dspy.OutputField()
urgency_level: Literal["low", "medium", "high", "critical"] = dspy.OutputField()
Tone by role example:
ROLE_HINTS = {
"developer": "technical details, stack traces welcome, use markdown in Slack",
"executive": "business impact only, no jargon, one sentence if possible",
"end_user": "plain language, friendly tone, tell them exactly what to do",
"on_call": "all relevant details, include timestamp, severity, and system affected",
}
class JudgeNotification(dspy.Signature):
"""Judge the quality of a notification message on clarity, actionability, and channel fit."""
event: str = dspy.InputField(desc="Original event that triggered the notification")
channel: str = dspy.InputField()
notification_text: str = dspy.InputField()
urgency_level: str = dspy.InputField()
clarity: float = dspy.OutputField(desc="0.0-1.0 - is the message immediately understandable?")
actionability: float = dspy.OutputField(desc="0.0-1.0 - does the recipient know what to do?")
channel_fit: float = dspy.OutputField(desc="0.0-1.0 - is length and format right for the channel?")
def notification_metric(example, prediction, trace=None):
judge = dspy.Predict(JudgeNotification)
result = judge(
event=example.event,
channel=example.channel,
notification_text=prediction.notification_text,
urgency_level=prediction.urgency_level,
)
return (result.clarity + result.actionability + result.channel_fit) / 3
optimizer = dspy.BootstrapFewShot(metric=notification_metric, max_bootstrapped_demos=4)
optimized = optimizer.compile(notifier, trainset=trainset)
| Pattern | Use when |
|---------|----------|
| ChainOfThought(GenerateNotification) | Single event, single channel |
| DigestNotifier (GroupEvents + Write) | Multiple events → one message |
| dspy.Refine + channel_length_reward | Enforcing hard character limits per channel |
| CalibrateUrgency | Preventing alert fatigue |
| PersonalizedNotification | Different tone/detail for different roles |
max_chars=160 in a field description is not enough — the model treats it as a suggestion. Always wrap with dspy.Refine and a programmatic length check reward function that reads len(pred.notification_text).high urgency. Add a CalibrateUrgency step and a reward function that penalizes over-classification of low-severity events.dspy.Assert/dspy.Suggest for constraints. Use dspy.Refine with a reward function instead — it handles retries with feedback and is the current DSPy pattern for enforcing output constraints.recipient_profile in the signature, every user gets the same message. Always pass name, role, and preferences as inputs to get personalized copy.Install any skill:
npx skills add lebsral/DSPy-Programming-not-prompting-LMs-skills --skill <name>
/ai-summarizing/ai-parsing-data/ai-scoring/dspy-refine/dspy-best-of-n/dspy-modules/ai-do if you do not have it — it routes any AI problem to the right skill and is the fastest way to work: npx skills add lebsral/DSPy-Programming-not-prompting-LMs-skills --skill ai-dotools
See what is happening during optimizer.compile() instead of waiting blind. Use when you want to watch optimization progress, see scores as they come in, know if your optimizer is working, check if optimization is stuck, understand why optimization is taking too long, get live progress during compile, monitor convergence, detect overfitting during optimization, interpret optimization results, or pick the right tool for watching optimization. Also used for optimizer progress bar, is my optimizer doing anything, optimization seems stuck, how long will optimization take, watch GEPA run, watch MIPROv2 run, live optimization dashboard, optimizer not improving, scores not going up, optimization taking forever, see what optimizer is doing, debug slow optimization, optimization visibility, optimizer metrics, track compile progress, optimization observability.
testing
Use when you want the highest-quality prompt optimization DSPy offers — jointly optimizes instructions and few-shot demos, with auto=light/medium/heavy presets. Common scenarios - you want the best possible accuracy from prompt optimization, jointly tuning instructions and few-shot demonstrations, using auto presets for different compute budgets, or when COPRO or BootstrapFewShot alone are not reaching your accuracy target. Related - ai-improving-accuracy, dspy-copro, dspy-bootstrap-few-shot. Also used for dspy.MIPROv2, best DSPy optimizer, highest quality optimization, auto=light medium heavy, joint instruction and demo optimization, most powerful prompt optimizer, MIPROv2 vs COPRO vs BootstrapFewShot, which optimizer should I use, state of the art prompt optimization, when to use MIPROv2, optimize both instructions and examples, heavy optimization for production, best optimizer for accuracy.
testing
Use LangWatch for DSPy auto-tracing and real-time optimizer progress. Use when you want to set up LangWatch, langwatch.dspy.init, auto-tracing DSPy, real-time optimization dashboard, optimizer progress tracking, app.langwatch.ai, or DSPy optimizer dashboard. Also used for langwatch setup, pip install langwatch, langwatch trace, optimizer progress, real-time optimization, watch optimizer run, LangWatch self-hosted, langwatch docker, langwatch vs langtrace, langwatch autotrack_dspy.
data-ai
Use when you want to optimize instructions without few-shot examples — a lightweight alternative to COPRO when you do not have or do not want to use demonstrations. Common scenarios - optimizing instructions when you do not have or do not want to use few-shot demonstrations, lightweight instruction search as a first step, tasks where examples in the prompt confuse the model, or when you want fast instruction optimization without the cost of COPRO. Related - ai-improving-accuracy, dspy-copro, dspy-miprov2. Also used for dspy.GEPA, instruction optimization without demos, lightweight prompt optimization, optimize instructions only, no few-shot examples needed, GEPA vs COPRO, quick instruction search, when demonstrations hurt performance, zero-shot optimization, instruction-only optimizer, simplest instruction tuner, fast prompt optimization, skip few-shot and just tune instructions, optimize Pydantic field descriptions, GEPA structured output, GEPA does not optimize field desc.