[KongchangAI]
· 2 min read· 1,278 words

Rule-Based Scoring, AI-Written Proposals: An n8n Renewal Risk Workflow in Practice

Rule-Based Scoring, AI-Written Proposals: An n8n Renewal Risk Workflow in Practice

An n8n customer renewal risk workflow that uses deterministic rules for scoring and AI only for wording.

A developer shared an n8n-based customer success workflow: account data (ARR, days to renewal, usage change, ticket count, payment status) is first converted by a code step into a 0-100 risk score with triggered warning flags, then a Gemini-powered AI Agent generates recommendations for account managers and customer-facing message drafts, and finally after code validation the results are distributed to Slack and written to Supabase. The author's core design principle is separating "decision" from "expression"—AI does not participate in judging who is at risk, only in turning established facts into actionable plans and talking points, ensuring scores are explainable, traceable, and auditable. The author also reminds that Slack message text must use Expression mode, and acknowledges that the demo is based on simulated data, so rule weights and signal coverage still need validation in real scenarios.

A developer shared an n8n-based customer success workflow on Reddit: deterministic rules assess an account's renewal risk, then an AI Agent (Gemini) writes retention recommendations and customer communication drafts. The core idea of this project is worth noting—in scenarios involving business judgment, it separates "decision-making" from "expression."

Screenshot of the original Reddit post

Why not let AI score directly?

The author's reasoning is straightforward: churn scores produced by AI are both hard to trust and hard to explain. When an account manager sees "risk score 78," they need to know where that number comes from—otherwise they can't act on it.

So this workflow establishes a clear division of labor—scoring is done entirely by rules in code, and the AI does not participate in judging "who is at risk," only in turning already-determined facts into actionable plans and talking points. The author's exact words: "The AI never sees the job of deciding who is at risk."

This design approach actually applies to many enterprise AI application scenarios. When outputs need to be attributable, auditable, and explainable, deterministic logic is more suitable than probabilistic models; while natural language generation happens to be AI's strength—each plays its own role.

n8n is an open-source workflow automation tool that uses node-based visual orchestration: each node represents an operation (such as reading data, executing code, calling an API, sending a message), and nodes pass data to each other through connections. It is often compared with Zapier and Make, but places more emphasis on self-hosting and the flexibility of code nodes, making it popular in automation scenarios that require embedding custom logic. The "code step," "AI Agent node," and "Slack node" mentioned in the article are all specific node types in n8n.

AI Agent, in the n8n context, refers to a type of LLM node that can have tools attached and possesses a degree of autonomous invocation capability. This contrasts with a pure "text generation" node—the latter only performs a single constrained input-output operation. The author specifically emphasizes that the Agent node has no tools attached, precisely to constrain the process to a controllable scope of text generation and avoid unpredictable behavior from the model autonomously calling external systems.

The three stages of the workflow

Data input and rule-based scoring

Account data includes ARR, days until renewal, usage change, number of support tickets in the last 30 days, and payment status. The demo uses 4 simulated accounts.

A code step converts these signals into a risk score from 0 to 100, while listing the triggered warning flags: usage decline, excessive tickets, failed or overdue payments, and approaching renewal. These warning flags are stored alongside the score, so any flagged account can be traced back to specific reasons.

AI Agent generates recommendations

The Gemini-powered AI Agent node receives the account facts and outputs two parts: a one-sentence recommendation for the account manager, and a friendly message draft addressed to the customer. The prompt explicitly requires that the draft must not mention the internal risk score.

The author specifically notes that this Agent node has no tools attached and simply returns structured JSON—essentially a constrained text generation rather than letting the model call external systems to make judgments. This detail reduces the complexity and uncertainty of the workflow.

The structured JSON output here refers to using prompt constraints or the model's structured output capabilities to make the model return a JSON object with fixed fields (such as recommendations and customer messages), rather than free-form prose. Compared with free text, the benefit of structured output is that downstream nodes can directly retrieve, validate, and route by field, without relying on fragile string parsing. Combined with a post-processing validation code step, it can effectively intercept missing fields, format errors, or content that crosses boundaries (such as leaking internal scores)—this is also the key engineering technique that allows the workflow to hand the "expression" stage to AI without losing control.

Validation and distribution

After the AI output, there is another code step for validation to prevent format or content from going off track. High-risk accounts are pushed to Slack, and all accounts along with scores, tiers, and risk factors are written to Postgres (the author uses Supabase). The entire tech stack—n8n Cloud, Gemini, Slack, Supabase—runs within free-tier limits.

Two practical lessons

The author mentions two lessons learned from pitfalls in the post, which are useful for anyone preparing to get started with n8n.

Numbers belong to code, wording belongs to AI. This is the design principle of the entire project and a point he emphasizes repeatedly. Scoring logic is written in code—stable, reproducible, and explainable; communication talking points are left to AI—flexible and warm. The boundary between the two is clear, and when problems arise, they are easy to locate.

Slack message text must use Expression mode. Otherwise, variables inside {{ }} will not be parsed and will be displayed as plain text exactly as written. This is an easily overlooked detail in n8n.

Who this solution is for, and who it is not for

Suitable scenarios: customer success teams that want an explainable risk list before renewal and want to quickly generate initial communication materials; or any operational process that needs a combination of "rule-based scoring + AI generation." The code is already open-sourced on GitHub, including the workflow JSON, setup steps, and table creation SQL.

What needs to be viewed with clear eyes: the demo runs on simulated data, and whether the rule weights are reasonable needs to be validated on real accounts; AI-generated message drafts still need human review before being sent; and with only three types of signals—usage, tickets, and payments—coverage of the complexity of B2B renewals is limited—the author himself solicits opinions at the end of the post: "Besides usage, tickets, and payments, what other signals would you add?"

There are directions worth considering from the comments: changes in key customer-side contacts, NPS or satisfaction survey results, conversation records of competitor replacement, activity decay curves before contract expiration, and so on. If these signals can be collected in a structured way, they can likewise be incorporated into the rule layer rather than left to AI to "guess."

Supabase is an open-source backend-as-a-service (BaaS) platform based on PostgreSQL, providing auto-generated REST/Realtime APIs, authentication, row-level security (RLS), and object storage on top of standard Postgres. The article uses it as the destination for storing results; the benefit is that you can obtain a standard SQL table structure without building your own database service (the author provides table creation SQL alongside the code), making it relatively straightforward to build reports, conduct retrospective audits, or connect to BI tools later, while the free tier is sufficient to support write volumes at demo scale.

Summary

The value of this project does not lie in how complex the tech stack is, but in how it demonstrates a pragmatic way to implement enterprise AI: keep explainable judgments in code, hand language generation to the model, and use a validation step in between as a safeguard. For teams considering embedding AI into business processes, this division-of-labor principle is more worth learning from than the specific implementation.

Background notes

Expression mode is a mode for parameter input in n8n, as opposed to "Fixed" mode. In Expression mode, the field content is evaluated as an expression, and references inside {{ }} (such as {{ $json.riskScore }}) are replaced with the actual data passed in from upstream nodes; in Fixed mode, the entire content is treated as a literal, and {{ }} is output as-is. This distinction is especially easy to trip up users migrating from other automation tools, because many tools parse template variables by default.

#n8n#AI Agent#renewal risk#workflow automation#Gemini#customer success
Share:

Related articles