Things to keep in mind while developing your own chat bot

4 min read
chatbotguardrailsPII maskingLLM securityLLM intakeproduct

A chatbot on a personal site has a job: talk to a hiring manager, a client, or a fellow developer, collect what you still need, and stop when the visit is ready for a human.

This is for tech managers and HR recruiters who will brief an engineer. I shipped one on this site. Put this in the ticket before anyone picks a model.

Know who the chatbot is for

A hiring manager and someone just saying hi should get different chats.

On this site the visitor picks a path: hiring manager, client project, fellow developer, or just saying hi. A recruiter needs the role and the company. A client needs what they want built and why. A hello chat needs almost nothing. It should not hunt for an email.

Write the visitor types on one page. Next to each, write what "enough" looks like. Skip that and the bot interrogates everyone, or it finishes with an empty inbox.

Decide the end intent before you write prompts

End intent is when the bot should stop talking and hand the visit to a person.

For a recruiter: role known, company known, a way to reply on file. For a client: the work and the goal, plus contact. For a light hello, a turn cap is enough. Six short turns, then close.

DONE_WHEN = {
    "recruiter": ["role", "company", "contact"],
    "client": ["scope", "goal", "contact"],
    "hello": [],  # close after a turn cap
}

Ask one question at a time. If they already named the company, leave it. If they declined a phone number, leave it.

When the required list is complete, close the chat and send it on. An open window "in case they want more" just burns turns.

Put guardrails in front of the model

Run cheap checks first. Only then call the model.

The same line three times in a minute earns a short wait. Five messages in a few seconds earns a short wait. Abuse gets a calm canned line, then the chat closes on the second hit, with no email. A message that tries to steal the instructions is dropped and stored as a placeholder. Homework or weather, after you already have their details, gets a redirect. Four times in a row with no hiring or project in the text, the chat closes.

These checks are boring if statements. They keep junk out of the model and out of your inbox.

Cut cost by skipping the model

A small model with a short reply budget is enough. Cap the reply length, the turns in one chat, and the tokens the site may spend in a day. When the daily cap hits, show "come back tomorrow".

A burst of repeats, a blocked insult, and a question about pay can all be answered from a template. Those skipped calls leave budget for chats about a role or a project.

Mask personal data before the model sees it

Recruiters paste emails. Clients paste phone numbers. Someone will paste a card or an ID.

Mask first. Keep the raw email and phone in a private place only you can read. Show [email] and [phone] in the transcript, in the visitor's bubble, and in anything the model sees. For cards and national IDs, keep the last four characters. Run the same mask on the model's reply.

import re

EMAIL = re.compile(r"[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}", re.I)

def mask(text: str) -> str:
    return EMAIL.sub("[email]", text)

Pattern checks miss names and odd formats. That is fine if the model never needs the raw value.

Hand the chat to a human with a reason

A useful chatbot ends in a person's inbox with enough context to reply.

Send the email when the chat wraps up, when the visitor asks to talk to you, when the turn cap hits, or after the window sits idle. Skip it for abuse and for chats that never left the weather. Set Reply-To to the visitor's address so a hiring manager gets a normal reply.

The note should answer: why this landed, what is still missing, how to reach them, and what they already told you. Attach the redacted transcript. You read the private contact. They never see it echoed in the widget.

A one-page brief

If you are a tech manager or a recruiter asking someone to build this, the brief can be this short:

  1. Who talks to the bot, and what "done" means for each of them.
  2. Which checks run before any model call.
  3. A daily spend cap and a cheap model for short replies.
  4. How email, phone, and IDs are masked.
  5. When a human gets the thread, and what that email contains.

Put this list in the ticket. The model name can wait.

All posts