cleandataengineering.aiDrug-Safety Agent on Databricks, drawn simply
You are here: End to end › The router

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.

Goes inThe scientist's sentence
What happensFold to lower case; find the drug and event; apply the rules top to bottom; fall through to investigate
Comes outA route: the intent, who answers (loop, direct, hand-off or refusal), and the drug and event found

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 writesRouteAnswered by
Is there a signal for lisinopril and angioedema?investigatethe loop
How many angioedema reports for lisinopril?counts_onlya direct read
Is angioedema on the lisinopril label?label_onlya direct read
I want to talk to a personhumanhand-off
Does lisinopril cause angioedema?causality_questionrefusal R-CAUSALITY
Send this to the FDAsubmission_requestrefusal 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 loop
def 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)

Look inside