Portfolio
Loading... 0%

An automated n8n workflow that scores incoming leads (0–100) using an LLM grounded in a company knowledge base (RAG). It generates deterministic lead IDs via Google Apps Script, evaluates the lead's intent, and writes the score, category, and reasoning back to Google Sheets.
AI Automation
N8N, JavaScript
Nov 15, 2026 - Nov 15, 2026
Manually reading, evaluating, and prioritizing incoming contact form submissions is time-consuming. It is easy to miss high-value leads or waste time replying to spam and unqualified inquiries.
Built an end-to-end n8n automation pipeline. It uses custom Google Apps Script to generate deterministic lead IDs, Google Gemini for document embeddings, and an OpenRouter LLM for RAG-based scoring. The AI evaluates the lead's intent against a company knowledge base and updates the Google Sheet with a score, category, and reasoning.
Achieved 100% automated lead triage. High-intent leads are instantly flagged with a score above 80, while spam and off-topic messages are automatically scored below 10, allowing me to focus solely on revenue-generating opportunities.
When running a business, every incoming lead from a contact form needs to be evaluated. Doing this manually is slow, inconsistent, and prone to human bias. I wanted a system where a lead could submit a form, and within 60 seconds, it is automatically scored, categorized, and prioritized based on how well it matches my actual business model.
AI Lead Qualification is a fully automated n8n pipeline that bridges Google Sheets, custom Google Apps Script, and a RAG-powered AI Agent. It acts as an autonomous sales assistant, ensuring high-intent leads are separated from spam and unqualified inquiries.
The system operates on two separate but connected flows within a single n8n workflow:
To ground the AI in reality, I upload PDF/CSV documents detailing my business model, services, and ideal client profile. The workflow loads these documents, generates embeddings using Google Gemini, and stores them in an In-Memory Vector Store.
When a new lead arrives in the Google Sheet, the workflow triggers, fetches the lead's details, and passes their comment to an AI Agent (powered by OpenRouter/Nvidia Nemotron). The AI Agent has access to a Query Data Tool that queries the vector store. It scores the lead from 0–100, assigns a category (Hot, Warm, Cold, Spam), and writes the result back to the sheet.

To ensure data integrity, every lead needs a unique, stable identifier. I wrote a custom Google Apps Script called IDENTIFIER(). It uses SHA-256 hashing on the timestamp, email, and phone number to generate a deterministic 22-character base64url ID. This ensures that even if the data is synced across multiple systems, the ID remains identical.
// Google Apps Script snippet\nfunction IDENTIFIER(timestamp, email, phone, salt) {\n const payload = (salt ? String(salt) + '|' : '') + t + '|' + e + '|' + p;\n const bytes = Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_256, payload);\n return Utilities.base64EncodeWebSafe(bytes).slice(0, 22);\n}

LLMs are notoriously unpredictable. To ensure the workflow never breaks, the AI Agent is prompted to return a strict JSON contract. A subsequent Code node is responsible for parsing this string (handling markdown fence stripping) and flattening the response into fields that the Google Sheets update node can consume.

The AI is explicitly instructed to return the following JSON structure, which the workflow uses to update the sheet:
{\n \"identifiant\": \"\",\n \"score\": 85,\n \"category\": \"hot\",\n \"reasoning\": \"The lead mentioned a specific budget and timeline for a full-stack SaaS project.\",\n \"matched_signals\": [\"budget mentioned\", \"SaaS development\", \"urgent timeline\"]\n} 
Have a project in mind? Let's discuss how we can bring your vision to life.
Start a Project