Free workshop
SEO in 90 minutes: audit your own website. Seats are limited.SEO in 90 minutes: audit your own site.
00d00h00m00s

Lead scoring with a language model: a small, honest build

A language model can read a form and suggest a score. It should not decide alone. Here is a small build with a strict output schema, a back-test and clear limits.
Sooraj PFull-stack developer and SEO strategist
5 min read
0 views
Lead scoring with a language model: a small, honest build
Lead cards falling into a funnel through an AI chip and coming out scored 92, 74 and 31

A language model can read a contact form and say whether the lead looks like a good fit. That is useful. It is also easy to overtrust. This guide shows a small, honest build: define a good lead, score with simple rules first, add a model that returns a strict JSON result, test it on past leads and keep a person in charge. It makes no claim about accuracy. You must measure that on your own data.

01

What this build does

Lead scoring gives each new enquiry a number that says how well it fits what you sell. The score helps you reply first to the leads that matter.

The model reads the free-text parts of a form, such as the message and the company description. It returns a short, structured result. A person decides what to do with it.

02

Step 1: start with plain rules

Do not begin with a model. Begin with the rules you could write on a sticky note.

A rule-based baseline
SignalExample rule
Budget statedAdd points if the budget fits your lowest package
TimelineAdd points if the project starts within three months
Service matchAdd points if they ask for something you sell
Contact qualitySubtract points for a throwaway email or an empty message

These rules are my own examples. Change them to match your business. Keep this baseline. You will need it to judge the model.

03

Step 2: force a strict output

Free text from a model is hard to use. A fixed shape is easy. OpenAI Structured Outputs makes a response follow a JSON Schema you supply, using strict mode.1

JSON mode only helps the output be valid JSON. Structured Outputs aims at matching your schema.1 The model can also refuse, and then a refusal field is set.1

lead_score.py
1from openai import OpenAI2import json34client = OpenAI()56schema = {7    "type": "object",8    "properties": {9        "fit": {"type": "integer", "enum": [1, 2, 3, 4, 5]},10        "reasons": {"type": "array", "items": {"type": "string"}},11        "missing_info": {"type": "array", "items": {"type": "string"}},12        "needs_human": {"type": "boolean"}13    },14    "required": ["fit", "reasons", "missing_info", "needs_human"],15    "additionalProperties": False16}1718resp = client.chat.completions.create(19    model="YOUR_MODEL_NAME",20    messages=[21        {"role": "system", "content": "Score the lead from 1 to 5 for fit. Use only the text given. If unsure, set needs_human to true."},22        {"role": "user", "content": lead_text},23    ],24    response_format={25        "type": "json_schema",26        "json_schema": {"name": "lead_score", "strict": True, "schema": schema},27    },28)29result = json.loads(resp.choices[0].message.content)
Limits the vendor lists
LimitWhat the announcement says
Schema supportOnly a subset of JSON Schema is supported1
First requestA new schema adds latency to the first request1
Cut-off outputIf output stops early, such as at max_tokens, it may not match the schema1
Wrong valuesValues can still be wrong even when the shape is right1
04

Step 3: test on past leads

A schema makes the shape reliable. It does not make the score right. Test it.

  1. 1

    Collect past leads

    Pull 50 to 100 old enquiries where you know what happened: won, lost or ignored.

  2. 2

    Remove private data

    Strip names, emails and phone numbers before you send any text to a model.

  3. 3

    Score them blind

    Run the model without showing it the outcome.

  4. 4

    Compare with outcomes

    Check how often high scores became customers, and how often low scores did.

  5. 5

    Compare with your rules

    Does the model beat the sticky-note baseline? If not, keep the baseline.

  6. 6

    Read the misses

    Look at every wrong call. They show what your prompt or schema lacks.

05

Step 4: wire it in safely

Safe handling rules
RuleWhy
Never auto-rejectA wrong low score would silently lose a real customer
Show the reasonsA person can spot a bad call in seconds
Route needs_human to a personUnsure cases should not be guessed
Log every score and every outcomeYou need data to improve and to audit
Re-run the back-test each quarterYour market and your prompt both drift
06

How I would approach it

I would build the rules first and ship them. They work on day one, and they set the bar.

I also would not publish a result like “improves conversion by X percent” unless I had measured it on a real pipeline. This guide has no such number.

07

Common mistakes

  • Skipping the simple rule baseline.

  • Trusting the score without a back-test.

  • Sending raw personal data to a model.

  • Letting the score reject leads automatically.

  • Never checking the results again after launch.

Quick questions

Does a strict schema make the score accurate?

No. It makes the shape reliable. The values can still be wrong.1

How many past leads do I need?

There is no fixed number. Fifty to a hundred is a practical start for a small business, but treat the result as a sanity check.

Can I use a different model provider?

Yes. Many providers offer a way to return structured output. The same steps apply: baseline, schema, back-test, human review.

Should the model write the reply too?

Keep that separate. Scoring and writing are different jobs, and a person should review any message that goes out.

08 · The short version

Key takeaways

  • A model suggests a lead score. A person decides.

  • Build a plain rule baseline first and keep it.

  • Use a strict JSON schema so the output has a reliable shape.

  • A valid shape does not mean a right answer. Back-test on past leads.

  • Never auto-reject, show the reasons and keep a log.


Join the conversation

Say hello · I reply personally

Tell me how I can help

1 · Details2 · Done

Message received

Thanks, there. I read every message myself and will reply to your inbox within one business day.