Lead Qualifier
Automatically qualify and score sales leads using AI in a local-first workflow.
Quick Example
1import { relay } from "@relayplane/workflows";23const result = await relay4 .workflow("lead-qualifier")5 .step("enrich").with("openai:gpt-4o")6 .step("score").with("anthropic:claude-3.5-sonnet").depends("enrich")7 .run({ email: "prospect@company.com", company: "Acme Corp" });Full Implementation
1import { relay } from "@relayplane/workflows";2import { z } from "zod";34// Define lead qualification schema5const LeadScoreSchema = z.object({6 score: z.number().min(0).max(100),7 tier: z.enum(["hot", "warm", "cold", "disqualified"]),8 fitScore: z.number().min(0).max(100),9 intentScore: z.number().min(0).max(100),10 reasoning: z.string(),11 nextSteps: z.array(z.string()),12 assignTo: z.string().optional(),13});1415async function qualifyLead(lead: {16 email: string;17 company: string;18 title?: string;19 message?: string;20 source?: string;21}) {22 const result = await relay23 .workflow("lead-qualifier")2425 // Step 1: Enrich lead data from public sources26 .step("enrich", {27 systemPrompt: `Research company and contact information:28 - Company size, industry, and revenue (if public)29 - Technologies used (from job postings, tech stack data)30 - Recent news or funding announcements31 - Contact's role and seniority level32 - Social media presence and activity33 Return enriched profile data.`,34 })35 .with("openai:gpt-4o")3637 // Step 2: Score and qualify the lead38 .step("score", {39 schema: LeadScoreSchema,40 systemPrompt: `Qualify this lead based on ICP criteria:4142 FIT SCORE (0-100):43 - Company size: 100-1000 employees (30 points)44 - Industry: B2B SaaS, Tech, or Professional Services (25 points)45 - Budget: $10k+ ARR budget (25 points)46 - Tech stack: Uses modern development tools (20 points)4748 INTENT SCORE (0-100):49 - Source quality: Inbound demo request (40 points)50 - Message specificity: Mentions specific pain points (30 points)51 - Timeline: Needs solution in next quarter (20 points)52 - Authority: Director level or above (10 points)5354 TIER ASSIGNMENT:55 - Hot (80-100): High fit + high intent, route to AE immediately56 - Warm (60-79): Good fit or intent, nurture sequence57 - Cold (40-59): Some potential, long-term nurture58 - Disqualified (<40): Not a fit, archive5960 Provide reasoning and specific next steps.`,61 })62 .with("anthropic:claude-3.5-sonnet")63 .depends("enrich")6465 // Step 3: Generate personalized outreach66 .step("draft-outreach", {67 systemPrompt: `Draft personalized outreach email:68 - Reference their specific company/industry69 - Address pain points mentioned in their inquiry70 - Suggest relevant case studies or resources71 - Include clear CTA based on tier72 Tone: Professional but conversational, value-focused`,73 })74 .with("openai:gpt-4o-mini")75 .depends("score")7677 .run(lead);7879 return {80 enriched: result.steps.enrich,81 qualification: result.steps.score as z.infer, 82 outreach: result.steps["draft-outreach"],83 };84}8586// Example usage87const qualified = await qualifyLead({88 email: "john@acmecorp.com",89 company: "Acme Corp",90 title: "VP of Engineering",91 message: "Looking for workflow automation solution for our team",92 source: "website-demo-request",93});9495console.log("Lead Tier:", qualified.qualification.tier);96console.log("Score:", qualified.qualification.score);97console.log("Next Steps:", qualified.qualification.nextSteps);98console.log("\nDraft Email:", qualified.outreach);Use Cases
- Inbound lead qualification and routing
- Event attendee follow-up prioritization
- Trial user qualification
- Partnership inquiry screening
- Demo request triage
Automation with Webhooks
1# Trigger from form submissions2curl -X POST https://api.relayplane.com/webhooks/trigger \3 -H "Authorization: Bearer YOUR_API_KEY" \4 -d '{5 "workflowName": "lead-qualifier",6 "input": {7 "email": "prospect@company.com",8 "company": "Acme Corp",9 "source": "website-form"10 }11 }'Best Practices
- Define clear ICP (Ideal Customer Profile) criteria in prompts
- Use GPT-4 for enrichment research, Claude for scoring logic
- Customize scoring weights based on your sales data
- Route hot leads to sales immediately via webhook
- Track qualification accuracy and retune prompts
Cost optimization: This workflow costs ~$0.03 per lead. At 1000 leads/month, that's $30 in AI costs vs. $5000+ for manual SDR qualification.