Gryffin Forge
AI agentsArchitectureAutomation

Rule-based routing before LLMs: choosing a website template from a business name

Why ordered keyword rules beat both category codes and an AI model as the first step in routing businesses to industry templates — and where AI still helps.

3 min readGryffin Forge

The demo engine behind this library has seventeen industry templates. Given a business, it must pick the right one: a nail bar should not get a garage layout. That sounds like a perfect job for an AI model. In practice, the best first step turned out to be a small set of ordered keyword rules — with AI reserved for what rules cannot do.

Why not official category codes?

Registered businesses come with standard industry classification codes, so the obvious approach is a lookup table from code to template. It fails quickly. Codes are broad, and very different trades share them: hairdressing and beauty treatment sit together, "other personal service activities" covers everything from tattooists to pet groomers, and plenty of businesses register under a generic code and never update it.

The business name is usually a far better signal. "Fade District" and "Velvet Lash & Nail" say more about what the business does than any code.

Ordered keyword rules

Each template declares a list of keyword patterns. Routing walks the templates in a fixed priority order and picks the first one whose patterns match the name:

pets       → dog, pets, paws, kennel, grooming…
tattoo     → tattoo, ink, piercing…
clinic     → clinic, aesthetic, skin, dental, laser…
barber     → barber, cuts, fade, gents…
beauty     → beauty, nail, lash, brow, salon, spa…
…
restaurant → kitchen, cafe, pizza, grill, bakery…

Order matters. "Dog grooming" contains grooming, which could look like a barber term, so pets are checked first. Word boundaries matter too: \bmot\b should match "Leeds MOT Centre" but not "Motion Pilates". When nothing matches, the category code is used as a fallback, and when that fails too, a neutral business template is used.

You can try the router yourself on the AI automation page — it runs the same rules in your browser.

Why rules first?

  • Deterministic — the same name always gives the same answer, which makes debugging trivial.
  • Explainable — the system can say which keyword matched.
  • Free and instant — no API calls, no latency, no usage limits.
  • Safe — there is nothing to prompt-inject.

For a routing decision with seventeen possible outputs, these properties matter more than the extra few percent of accuracy a model might add.

Where AI genuinely helps

Rules struggle with names that carry no trade words at all — "Northgate", "The Lantern", "Smith & Daughters". That is where a model is useful: given the name plus a little context (a website snippet, a category description), it can propose a template with a confidence score. The architecture keeps that step optional and downstream:

  1. Run rules. If a rule matches, stop.
  2. If not, ask the model, constrained to the seventeen valid outputs.
  3. If confidence is low, fall back to the neutral template and flag for review.

Constraining the output space, validating the response against a schema and keeping a human-reviewable fallback are what make an AI step trustworthy in a pipeline.

Lessons

  • Look for the cheapest strong signal before reaching for a model.
  • Make ordering and boundaries explicit; most routing bugs live there.
  • Use AI for the long tail, with constrained outputs and a safe default.
  • Always be able to answer "why did it choose that?"