cleandataengineering.aiDrug-Safety Agent on Databricks, drawn simply
You are here: Tools

Drug-Safety Agent on Databricks · Tools

The three tools

The model can call three tools and nothing else. All three are read-only. None takes free text that could be used as a database query: each takes a drug name and an event name. That makes the question "what could the agent do wrong with its tools?" easy to answer: it can look things up.

Goes inA drug name and an event name
What happensLook up a row by key; for the statistics, code computes the ratios from the counts
Comes outA small JSON result, or an error that lists what the data does hold
On Databricks each tool is a Unity Catalog function; locally the same tools are plain Python, and a test proves they agree.
ToolTakesReturnsWhere the arithmetic is
get_report_countsdrug, eventa, b, c, d and the fetch datenone: it is a lookup
get_signal_statsdrug, eventcases, PRR, ROR and its 95% interval, whether it screens as a signalcode, never the model
get_label_mentionsdrug, eventon the label or not, boxed warning or not, short quotes with the sectionnone: text search with listed synonyms

A note on names. The specification calls the tools get_report_counts, get_signal_stats and get_label_mentions, and the tool facade presents those names. The local Python versions have shorter names (report_counts and so on), as the registry below shows.

Why not let the model write SQL? A model that writes its own queries can read what it should not and can be tricked by text in the data into running something unintended. Three fixed tools remove that whole class of risk.

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/tools.py:121The registry: the model sees these three names and nothing else
TOOLS = {"report_counts": report_counts, "signal_stats": signal_stats, "label_mentions": label_mentions}

Look inside