Lead Qualification

A Mastra workflow triages and qualifies leads received through a JSON API or Attio CRM. It researches each company, compares the findings with your sales team's ideal customer profile (ICP), and produces a score and qualification outcome with supporting sources. Results go to a local report or Attio; uncertain cases go to human review.

Why we built this

Sales teams need to know whether incoming leads match their ICP. Manually researching every company and checking it against the qualification criteria is tedious, so we built this template to automate the initial research and triage.

Demo

Prerequisites

  • OpenAI API key: set OPENAI_API_KEY for the default GPT-6 Luna research provider, which searches company sources and checks extracted facts.
  • Attio workspace token: optional. Set ATTIO_API_TOKEN and generate the list mapping to use Attio output. Attio input also requires ATTIO_WEBHOOK_SECRET. See Attio configuration.

Quickstart πŸš€

  1. Create the project
    • Run npx create-mastra@latest lead-qualification --template lead-qualification, then cd lead-qualification and npm install.
  2. Add your API key
    • Run cp .env.example .env and fill in the key described under Prerequisites. Both providers default to local.
  3. Start the server
    • Run npm run dev and open Mastra Studio.
    • Submit the request below, then open the returned statusUrl to read the assessment and business.state. Inspect the run under Workflows β†’ lead-intake in Studio. The result explains the company's fit and flags facts that need review.
curl http://localhost:4111/lead-qualification/events \
  -H 'Content-Type: application/json' \
  -d '{"version":1,"type":"lead.received","eventId":"company-1","lead":{"reference":"mastra","domain":"mastra.ai"}}'

Try it out

  • Add a genuine lead.inquiry using the input contract. Its date and request type contribute to buying intent; a company's own demo offer doesn't.
  • For an uncertain result, open Tools β†’ reviewLead in Studio and copy the current packet's references from the run response. Approve, reject, or request changes, then read /lead-qualification/runs/<runId>/output for the local Markdown report.
  • Select Attio input and output to qualify new Triage entries and review uncertain cases by moving Stage.
  • Resend an event with the same ID to retrieve its existing run. To research a completed lead again, submit a new ID and its latest supersedesAssessmentId.

Customization

About Mastra templates

This is an official Mastra template. Official templates live in the Mastra monorepo and are synchronized to standalone repositories.

Want to contribute?