Your bank deploys an LLM support chatbot. Product says it should only answer banking questions, not politics, not coding help, not therapy. Sketch the off-topic gate: what signal do you use, where does it sit, and how do you handle false positives?
Cascade an embedding-similarity check then an LLM-as-judge on the input rail; on a block show a templated message naming the policy and offering clarifying buttons.
Picture the front desk of a bank. Before you reach a banker, a receptionist asks what you are here for. If you say 'I want to open an account,' you go through. If you say 'I want to discuss yesterday's election,' the receptionist politely says the bank only handles money questions and points you to the actual help you need. The receptionist is fast and friendly, not a closed door. If the receptionist makes a mistake, turning away a real customer, there is a manager nearby who can step in. The off-topic filter is the receptionist. The point is to keep the bankers focused without making real customers feel rejected.
Detailed answer & concept explanation~5 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
9 min: sketch the input-rail position, set up the embedding+judge cascade, design the user-facing block message, close the feedback loop with sampling and a golden set, and contrast with adjacent rails.
| Approach | Latency | Cost per call | Accuracy |
|---|---|---|---|
| Embedding similarity to centroids | ~5 ms | fractions of a cent | Good on clear cases, weak on mixed-intent |
| Fine-tuned BERT-class classifier | ~20 ms on GPU | low if self-hosted | Strong if training data is fresh |
| LLM-as-judge (small model) | ~100-200 ms | noticeable at scale | Strongest on ambiguous and rare intents |
Real products, models, and research that use this idea.
- Klarna's customer-support agent uses a fast embedding-similarity gate ahead of its main GPT-class model, falling back to a heavier judge for ambiguous intents.
- Bank of America's Erica restricts intent to banking categories via a hierarchical classifier with explicit user-facing 'I can help with...' fallbacks on a miss.
- NeMo Guardrails ships a topical-rails primitive that implements exactly this cascade pattern declaratively in Colang.
- Lakera Guard 2026 bundles a configurable topic gate alongside its injection classifier for enterprise chat deployments.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow would you handle a user query that is borderline, say, 'is this Bitcoin payment legal?' for a bank that does not support crypto?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Silently refusing off-topic queries. The user has no idea what happened, gets frustrated, and the team has no signal that the classifier is misfiring.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.