Lead Qualifier

Automatically qualify and score sales leads using AI in a local-first workflow.

Quick Example

1import { relay } from "@relayplane/workflows";
2
3const result = await relay
4 .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";
3
4// Define lead qualification schema
5const 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});
14
15async function qualifyLead(lead: {
16 email: string;
17 company: string;
18 title?: string;
19 message?: string;
20 source?: string;
21}) {
22 const result = await relay
23 .workflow("lead-qualifier")
24
25 // Step 1: Enrich lead data from public sources
26 .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 announcements
31 - Contact's role and seniority level
32 - Social media presence and activity
33 Return enriched profile data.`,
34 })
35 .with("openai:gpt-4o")
36
37 // Step 2: Score and qualify the lead
38 .step("score", {
39 schema: LeadScoreSchema,
40 systemPrompt: `Qualify this lead based on ICP criteria:
41
42 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)
47
48 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)
53
54 TIER ASSIGNMENT:
55 - Hot (80-100): High fit + high intent, route to AE immediately
56 - Warm (60-79): Good fit or intent, nurture sequence
57 - Cold (40-59): Some potential, long-term nurture
58 - Disqualified (<40): Not a fit, archive
59
60 Provide reasoning and specific next steps.`,
61 })
62 .with("anthropic:claude-3.5-sonnet")
63 .depends("enrich")
64
65 // Step 3: Generate personalized outreach
66 .step("draft-outreach", {
67 systemPrompt: `Draft personalized outreach email:
68 - Reference their specific company/industry
69 - Address pain points mentioned in their inquiry
70 - Suggest relevant case studies or resources
71 - Include clear CTA based on tier
72 Tone: Professional but conversational, value-focused`,
73 })
74 .with("openai:gpt-4o-mini")
75 .depends("score")
76
77 .run(lead);
78
79 return {
80 enriched: result.steps.enrich,
81 qualification: result.steps.score as z.infer,
82 outreach: result.steps["draft-outreach"],
83 };
84}
85
86// Example usage
87const 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});
94
95console.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 submissions
2curl -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.

See Also