What this workflow does
- Every Monday 7am (Schedule Trigger) starts the run with a cron rule.
- Load weekly KPIs (Postgres) reads six weeks from a
kpi_weeklyview. A database error goes straight to the exceptions channel. - Compare and flag (Code) finds last Monday-to-Sunday week, computes change against the prior week and the trailing four-week average, checks target, and flags moves above a 15% band. Any KPI with history but no value this week marks the data incomplete.
- Data complete? (If) blocks the report when a source is missing, which is the most important control in this workflow.
- Write narrative with Claude (HTTP Request) calls the Anthropic Messages API with a JSON schema: headline, 150 to 250 word narrative, flagged metrics covered and questions for leadership. The prompt forbids figures that are not in the table and unsupported causes.
- Verify numbers (Code) handles refusals and truncated output, then checks that every number in the text matches a KPI figure and that every flagged metric is mentioned.
- Manager approval in Slack waits up to eight hours for Send or Hold.
- Post report to leadership (Slack) and Email report (Gmail) deliver the approved version with the KPI table and a dashboard link.
- Post exception to Slack receives database errors, incomplete data, API failures and failed number checks.
Before you import
- A Postgres database with a
kpi_weeklyview: kpi, label, unit, week_start (Monday), value, target, higher_is_better. Separate extract workflows load it from QuickBooks Online, your store, help desk and timesheets. - Written KPI definitions with an owner for each. The workflow reports numbers; it cannot fix a disputed definition.
- An Anthropic API key. The template uses
claude-opus-5-5;claude-haiku-5-5is cheaper for high-volume, simple classification. - Slack review, leadership and exceptions channels, and a Gmail account for the email copy.
Setup
- Import the JSON and connect Postgres, Anthropic, Slack and Gmail credentials.
- Set the workflow time zone in Workflow settings, and
TZin Compare and flag to match. - Adjust
BANDand, if some KPIs must always appear, list them inREQUIRED_KPIS. - Replace
REPLACE_WITH_SLACK_REVIEW_CHANNEL_ID,REPLACE_WITH_SLACK_LEADERSHIP_CHANNEL_IDandREPLACE_WITH_SLACK_EXCEPTIONS_CHANNEL_ID. - Replace
REPLACE_WITH_LEADERSHIP_EMAILon Email report andREPLACE_WITH_DASHBOARD_URLin Verify numbers.
Test it
Load twelve weeks of history and compare the KPI table in the Slack draft with the report your team built by hand for the same week. Then delete one KPI’s latest row and run again: the exceptions channel should say which metric is missing and nothing should reach leadership. Finally, edit a draft prompt to allow dates and confirm the number check blocks it.
Make it production-ready
- Add a Friday form for department notes and pass them in place of “Manager notes: none supplied”, so the narrative can explain causes.
- Store a business-day count per week and normalize volume KPIs for holiday weeks.
- Save each approved report and KPI table to a history table so restated numbers are visible.
- Set an n8n error workflow, and alert if the Monday run did not finish by 9am.
- The Claude call tries up to three times. If the number check blocks often, tighten the prompt before loosening the check.
Read the full guide on automating weekly operations reporting for KPI definitions and backfill, or ask Lumeor for help wiring the extracts.