Drug-Safety Agent on Databricks · Checks · Output contract
The shape of the draft
The model's final reply must be a JSON object with fixed fields: drug, event, cases, prr, on_label, assessment, uncertainty and recommendation. The check is strict about types because a downstream screen should never have to guess: a count is an integer, and "on the label" is true or false, not the word "yes".
What it catches. A missing field, a blank text field, a number returned as a string, or a verdict written as prose. It does not judge whether the content is right: that is the grounding check's job.
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/agent.py:116validate_body(): every problem, in plain words, so the repair turn can quote themdef validate_body(b: object) -> list[str]:
"""The output contract: types and required fields of the final JSON. Checked before the grounding check."""
if not isinstance(b, dict):
return ["reply must be a JSON object"]
out = []
for k in ("drug", "event", "assessment", "uncertainty", "recommendation"):
if not isinstance(b.get(k), str) or not b[k].strip():
out.append(f"{k} must be a non-empty string")
if not isinstance(b.get("cases"), int) or isinstance(b.get("cases"), bool):
out.append("cases must be an integer")
if b.get("prr") is not None and (not isinstance(b["prr"], (int, float)) or isinstance(b["prr"], bool)):
out.append("prr must be a number or null")
if not isinstance(b.get("on_label"), bool):
out.append("on_label must be true or false, not text")
return out