Drug-Safety Agent on Databricks · End to end · The router
The router: who answers this?
The router reads the words, finds the drug and the side effect the data knows about, and applies a short list of rules in order. The same text always gives the same answer, and a test can say why.
Rules instead of a model. A classifier would be one more thing that can be wrong in a new way. Rules are cheap and predictable, and a refusal that depends on a model being polite is not a refusal. The cost is that unusual wording may fall through to the investigate path, where the checks still protect the output.
Finding the pair. The drug and event names come from what the data holds, not from guessing. The longest event name wins, so gastrointestinal haemorrhage is not mistaken for plain haemorrhage.
| The scientist writes | Route | Answered by |
|---|---|---|
| Is there a signal for lisinopril and angioedema? | investigate | the loop |
| How many angioedema reports for lisinopril? | counts_only | a direct read |
| Is angioedema on the lisinopril label? | label_only | a direct read |
| I want to talk to a person | human | hand-off |
| Does lisinopril cause angioedema? | causality_question | refusal R-CAUSALITY |
| Send this to the FDA | submission_request | refusal R-SUBMISSION |
The real code
Cut from the repository each time this site is built, so it always matches what runs. Each header names the file and the line it was cut from.
src/drugsafety/router.py:92route(): rules first, then direct reads, then the loopdef route(text: str) -> Route:
t = _fold(text)
drug, event = find_drug_event(text)
for pattern, intent, by, refusal in _RULES:
if pattern.search(t):
return Route(intent, by, refusal, drug, event)
if drug and event and not _SIGNAL_WORDS.search(t):
direct = "label_only" if _LABEL.search(t) else "counts_only" if _COUNTS.search(t) else None
if direct:
return Route(direct, "direct", None, drug, event)
return Route("investigate" if drug and event else "other", "loop", None, drug, event)