Lesson 7 of 7 · 3 min read
Add a reliable AI summary to course notifications
Our notification service saves announcements durably and delivers them through workers. A long announcement can be hard to scan, so the team wants an optional short summary. The original announcement remains the source of truth, and the team keeps the existing publication and dispatch objectives.
Give the model a narrow job
Generate two short sentences from the published announcement in the requested language. Send the announcement text and locale. Keep recipient addresses, grades and private notes out of the request. Treat announcement text as content to summarize and give the summarizer no delivery or data-access tools. The service continues to determine recipients and assemble links from trusted course data. For course changes with authoritative dates or deadlines, render those fields from the course record and keep that information visible beside the summary.
Validate structure and preserve facts
Use a provider-supported structured-output schema with a required summary string and a language field restricted to en or uk. Parse the response and enforce application rules such as the requested locale and a 240-character display limit. Structure checks establish what the app can render. They cannot establish that a claimed date appears in the source. For instance, both the correct “Tuesday at 10:00” and the invented “Thursday at 10:00” are strings. Keep deadlines in deterministic fields and use a plain-text template when the response is refused, incomplete or invalid.
Evaluate what learners would act on
Build a versioned set of English and Ukrainian announcements with expected facts, permitted omissions and failure examples. Include a cancellation, two dates with different meanings, and an announcement with no deadline. Ask reviewers to mark invented details, omitted learner actions and meaning changes. Use automated checks for schema, language field and length, and human review for whether every stated deadline or action is supported by the source. Run the same evaluation against each model or prompt change. Keep examples used for improvement separate from a held-out set used for release decisions, and inspect results by language to catch regressions hidden by a combined average.
Cap latency, cost and failure impact
Generate asynchronously once per announcement revision and locale, then reuse the result for recipients who can read that same revision. The delivery worker sends the standard notification if a summary is unavailable when dispatch begins. If generation exceeds a two-second worker deadline, record the timeout and release the worker slot. Track p95 generation latency, fallback rate and provider cost per valid summary, counting token usage and failed attempts where billed. Set an output limit and compare a smaller model on the same evaluation set before adopting it. Monitor the original dispatch objective during a staged rollout. A rise in fallback rate or dispatch delay is grounds to disable summarization while the standard template continues delivering course updates.
Keep the model responsible for optional wording. Measure factual quality, latency and cost together so learners continue to receive the authoritative update on time.
function notificationSummary(modelOutput, course, parseSummary) {
const parsed = parseSummary(modelOutput);
const fallback = () => ({ title: course.title, deadline: course.deadline });
if (!parsed.ok) return fallback();
if (parsed.value.deadline !== course.deadline) return fallback();
return { title: parsed.value.title, deadline: course.deadline };
}