Mobile businesses in the UK (cleaners, locksmiths, mobile mechanics, dog groomers) often split work by area. The enquiry form collects a postcode, then someone reads it and forwards the job. That step is easy to automate if you keep it small.
I work at NxFlowAI, an AI automation agency building job routing for UK small businesses, serving UK businesses remotely from Mumbai. This is the minimal pattern we start with.
Step 1: extract the outward code
A UK postcode has an outward code (area plus district, like M14 or SW1A) and an inward code (like 4PX). For routing you usually need only the outward code.
import re
OUTWARD = re.compile(r"^\s*([A-Z]{1,2}[0-9][A-Z0-9]?)\s*([0-9][A-Z]{2})?\s*$", re.I)
def outward_code(raw):
m = OUTWARD.match(raw or "")
return m.group(1).upper() if m else None
This is intentionally loose. It accepts sensible inputs and rejects obvious junk; it does not prove a postcode exists.
Step 2: map districts to teams
ROUTES = {
"M14": "team_south", "M20": "team_south",
"M1": "team_city", "M4": "team_city",
}
def route(raw):
code = outward_code(raw)
if not code:
return "human", "postcode unreadable"
team = ROUTES.get(code)
return (team, "matched") if team else ("human", f"no team for {code}")
Step 3: keep the map out of the code
Store routes in a sheet the owner edits. Load it at start-up or on a schedule. When the business takes on a new area, nobody needs a developer.
Things that go wrong
- Customers type the town instead of the postcode. Ask again politely rather than guessing.
- Border districts belong to two teams. Pick one default and let a person reassign.
- Lower-case and missing spaces. Normalise before matching.
Logging
Record the raw input, the parsed code and the route chosen. When a job goes to the wrong team, you can see why in seconds.
If you want the bigger picture of how to decide what to automate first, see deciding which workflow to automate first.
Top comments (0)