Quick overview
This workflow acts as a shared governance sub-workflow that other n8n workflows call to track per-run AI costs, validate workflow outputs, and screen inputs for prompt injection using Anthropic Claude plus Guardrails. It logs to Google Sheets and sends alerts and reports to Slack and Gmail.
How it works
- Receives a request from another workflow (or a daily scheduled run) and routes it based on the
guard value: cost, output, security, or daily report.
- Calculates estimated cost from model token counts, appends a row to the Google Sheets “Cost Ledger,” and posts a Slack alert if the run exceeds the configured USD limit.
- Validates
output_data against minimum item count, required fields, and error flags, then logs failures to the Google Sheets “Dead Letter” tab and alerts Slack.
- Sanitizes incoming text to mask PII, checks for blocked phrases and jailbreak signals using Guardrails backed by Anthropic Claude, and compiles a final allow/block/review security verdict.
- If input is blocked or held for review, records the incident in the Google Sheets “Security Log” and notifies a Slack channel with the masked text.
- On the daily schedule, reads the Cost Ledger to total month-to-date spend per client, posts Slack budget warnings, and on the configured billing day writes “Rebilling” rows and emails a rebilling summary via Gmail.
Setup
- Create (or choose) a Google Sheets spreadsheet with tabs named “Cost Ledger,” “Dead Letter,” “Security Log,” and “Rebilling,” and set the spreadsheet ID in each Google Sheets node.
- Add credentials for Google Sheets, Slack, Gmail, and Anthropic (Claude) to enable logging, alerts, rebilling emails, and injection checks.
- Update the configuration values (pricing table, cost alert limit, client budgets/markups, billing day, finance email, blocked phrases, and jailbreak threshold) in the “Workflow Configuration” step.
- Select the target Slack channel (for example #ai-governance) in each Slack message step.
- Call this workflow from other workflows using an Execute Workflow step and pass the expected inputs (guard, client_id, workflow_name, execution_id, and the relevant fields for cost/output/security).