Drug-Safety Agent on Databricks · Business flow · The desk
The receiver: the desk
The desk is the other end of the flow. It is one small web page. A person can ask the agent a question, see what is waiting for them, read a draft with its numbers and label verdict, and approve, edit or reject it. Their name and the time are recorded with the decision.
What a reviewer sees. A table of drafts waiting, each with the drug, the event, the number of reports and whether it is on the label. Opening one shows the numbers, the assessment, the uncertainty and the recommendation. The numbers cannot be edited here, because they come from the data; only the words can.
What it will not do. It sends nothing anywhere. An approved draft only changes status. There is no login yet: the reviewer types their name, which is recorded but not verified. That is a stated gap.
Run it. .venv/bin/python scripts/run_desk.py --model groq opens it on a local port. Without a model, counts, label checks, refusals and hand-offs still work.
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/desk.py:110The desk: a standard-library web handlerdef make_handler(store: AssessmentStore, llm: Any = None) -> type[BaseHTTPRequestHandler]:
class Desk(BaseHTTPRequestHandler):
def _send(self, body: bytes, code: int = 200) -> None:
self.send_response(code)
self.send_header("Content-Type", "text/html; charset=utf-8")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def _form(self) -> dict[str, str]:
n = int(self.headers.get("Content-Length") or 0)
return {k: v[0] for k, v in parse_qs(self.rfile.read(n).decode()).items()}
def log_message(self, *a: Any) -> None: # keep the terminal quiet
return
def do_GET(self) -> None: # noqa: N802
path = urlparse(self.path).path
if path == "/":
return self._send(home(store))
if path.startswith("/a/"):
try:
return self._send(detail(store.get(path[3:])))
except StoreError as e:
return self._send(home(store, error=str(e)), 404)
self._send(page("Not found", "<p>Not found.</p>"), 404)
def do_POST(self) -> None: # noqa: N802
f, path = self._form(), urlparse(self.path).path
try:tests/test_desk.py:43Tested over real HTTP, one table of decisionsCASES = [
("approve with a name", {"decision": "approve", "reviewer": "Dr Rao"}, 200, "Recorded: approved by Dr Rao", 0),
("approve with no name", {"decision": "approve", "reviewer": ""}, 400, "must name the reviewer", 1),
("reject", {"decision": "reject", "reviewer": "Dr Rao", "note": "known"}, 200, "Recorded: rejected", 0),
("edit the words", {"decision": "edit", "reviewer": "Dr Rao", "assessment": "Reworded.", "uncertainty": "u", "recommendation": "r"}, 200, "Recorded: edited", 0),
("edit to blank words", {"decision": "edit", "reviewer": "Dr Rao", "assessment": "", "uncertainty": "u", "recommendation": "r"}, 400, "not valid", 1),
]