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

Drug-Safety Agent on Databricks · End to end · Direct reads

Direct reads: counts and label, no model

If someone only wants the report counts, or only wants to know whether the label mentions an effect, a model adds nothing but cost and risk. These two requests are answered straight from the tools.

Goes inA route of counts_only or label_only, with a drug and an event
What happensCall one read tool through the same tool client the loop uses; format the answer in a fixed sentence
Comes outOne sentence with the numbers, or a statement naming what the data does hold

Unknown pairs. If the drug or event is not in the data, the reply lists what the data does hold. It does not guess and it does not return zeros, because a zero would look like a real finding.

Worked example. Asked for the counts, the reply is: lisinopril and ANGIOEDEMA: 7,015 reports with both; 309,818 for the drug without the event; 37,265 for other drugs with the event; 20,700,061 for other drugs without it (openFDA, fetched 2026-11-19).

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/entrypoint.py:44_direct(): one tool call, one fixed sentence
async def _direct(r: Route, tools, who: Identity) -> str:
    seen: list[dict] = []
    facade = PairTools(tools, seen)
    name = "get_report_counts" if r.intent == "counts_only" else "get_label_mentions"
    key = IdempotencyKey(run_id=RunId(f"run_direct_{who.customer_id}"), step=0, iteration=0)
    got = await facade.call(name, {"drug": r.drug, "event": r.event}, who, key)
    out: dict[str, Any] = dict(got.structured) if isinstance(got.structured, dict) else {}
    if "error" in out:
        drugs, events = ", ".join(out["drugs"]), ", ".join(out["events"])
        return f"The data does not hold that pair. It holds drugs: {drugs}; events: {events}."
    if r.intent == "counts_only":
        return (
            f"{out['drug']} and {out['event']}: {out['a']} reports with both; {out['b']} for the drug without the event; "
            f"{out['c']} for other drugs with the event; {out['d']} for other drugs without it "
            f"(openFDA, fetched {out['fetched']})."
        )
    where = "yes" if out["on_label"] else "no"
    return f"Does the {out['drug']} label mention {out['event'].lower()}? {where}. Label version {out['label_version']}."