Drug-Safety Agent on Databricks · Tools · Defined twice, and the goal
Defined twice today; one definition is the goal
The rule: define each tool once, where the data and the authority live, and let the agent be a client of it. This agent does not meet that rule yet, and this page says exactly how.
| Question | Answer today | Goal |
|---|---|---|
| Where is a tool defined? | Twice: Python in tools.py and SQL in sql/. | Once: the Unity Catalog function. |
| What keeps the two equal? | A parity script over all 80 pairs; it reports how many differ. | Not needed once there is one definition. |
| What does the agent hold? | The Python tools for local runs; a thin facade for server runs. | Only the thin typed view. |
| Is the agent calling the live functions? | Not yet. The functions are deployed and tested separately; the agent is wired to local files and to a simulated server. | The agent reaches them through a tool connection on Databricks. |
Why not fix it now. The Python copy is what makes unit tests fast and makes the scenarios work offline. Removing it is the right last step, after the live connection exists, not before.
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.
scripts/parity_uc.py:17The parity check: every pair, Python against SQLbad, n = [], 0
for (drug, event) in T._pairs():
n += 1
py, ps = T.signal_stats(drug, event), None
sql = [r for r in q(f"SELECT cases, prr, ror, ror_ci_low, ror_ci_high, screens_as_signal FROM workspace.drugsafety.signal_stats('{drug}', '{event}')")]
if not sql: bad.append((drug, event, "no row")); continue
cases, prr, ror, lo, hi, sig = sql[0]
def close(a, b): return (a is None and b is None) or (a is not None and b is not None and math.isclose(float(a), float(b), rel_tol=1e-9))
ci = py["ror_ci95"]
ok = (int(cases) == py["cases"] and close(prr, py["prr"]) and close(ror, py["ror"])
and close(lo, ci[0] if ci else None) and close(hi, ci[1] if ci else None)
and (str(sig).lower() == "true") == py["screens_as_signal"])
if not ok: bad.append((drug, event, "stats", sql[0], py))
lm = T.label_mentions(drug, event)
rows = q(f"SELECT section FROM workspace.drugsafety.label_mentions('{drug}', '{event}')")
sections = {r[0] for r in rows}
if bool(rows) != lm["on_label"] or ("boxed_warning" in sections) != lm["in_boxed_warning"]:
bad.append((drug, event, "label", sorted(sections), lm["on_label"], lm["in_boxed_warning"]))
print(f"{n} pairs checked, {len(bad)} differ")
for b in bad[:10]: print(b)
sys.exit(1 if bad else 0)