Skip to content

Guardrails: what is enforced, and by what

PharmaSkills produces drafts for qualified people. PRD section 13 lists the rules that keep that honest. This page maps every rule to the exact test or tool that enforces it, and says plainly where a rule is enforced only by instruction text that a model may or may not follow.

Run the suite (deterministic, no model calls):

uv run pytest tests/unit/test_safety_suite.py -q

The manifest is tests/evals/safety/cases.yaml; the runner is tests/unit/test_safety_suite.py. 100 percent of cases must pass. Three kinds of enforcement are used:

  • tool: deterministic code that blocks, flags or records, with a test.
  • refusal-sample: a committed refusal sample for an adversarial eval, replayed through the eval harness refusal check. It proves the expected behaviour is specified and checkable; it does not prove that a given model produces it (the nightly model-mode run measures that).
  • instruction: the rule exists only as text in SKILL.md. The test proves the text is present in every skill, not that a model obeys it.

Rule to enforcement map

PRD s13 rule Case ids Enforced by Kind Honest limits
Draft banner SAF-BAN-01 pharmaskills.banners.banner_text and docs.builders.build_docx (header and first paragraph), docs banner --apply tool Only documents built or processed with the builder carry the banner automatically
Draft banner SAF-BAN-02 has_banner over every .md and .docx under examples/*/*/out tool Refusal samples (refusal_*.md) are chat replies and are exempt, listed in the manifest
Draft banner SAF-BAN-03 skill lint rule SK009 and the suite check on every SKILL.md instruction Telling the agent to insert the banner is text; the builder does the inserting
GxP status SAF-GXP-01 DISCLAIMER.md statements, the csv-gamp5 skill and its validating-pharmaskills.md reference, the example validate_pharmaskills document tool Documentation check only
Audit trail (ALCOA+) SAF-AUD-01 pharmaskills.manifest.RunManifest records hashes, versions, model and verification tool Only sdtm run writes a run manifest today; other commands write JSON reports carrying the banner
Audit trail (ALCOA+) SAF-AUD-02 pharmaskills.history.safe_write_text and build_docx move the previous version to .history/ tool Applies to files written through these helpers; a tool that writes with plain file I/O would not archive
Patient data SAF-PHI-01 pharmaskills docs detect-pii flags identifiers (exit 2), never echoes values, recommends de-identification tool Pattern based; it can miss free-text identifiers and can raise false positives
Patient data SAF-PHI-02 detect-pii over examples/ and every skills/*/evals/fixtures tool Reviewed false positives are listed with reasons in the manifest
Local processing SAF-LOC-01 pyproject.toml has no telemetry or analytics runtime dependency; SECURITY.md states no telemetry tool Dependency scan only; model routing is the user's agent's choice and is documented, not enforced
Licensed content SAF-LIC-01 pharmaskills.qa.licenseguard.scan_dictionaries flags dictionary-like data files without the PSK-DICT header tool Heuristic on file names and header tokens
Licensed content SAF-LIC-02 The same guard over the whole repository plus a scan for MedDRA-style distribution file names tool Cannot detect licensed text pasted into prose
Fabrication SAF-FAB-01 Every SKILL.md instructs the [DATA NEEDED: ...] placeholder and forbids fabrication instruction Text only
Fabrication SAF-FAB-02 Every skill has an adversarial eval with a committed refusal sample that passes the refusal check refusal-sample Specifies and checks the behaviour; model compliance is measured in model mode
Fabrication SAF-FAB-03 evalharness.checks.check_no_fabrication flags an NCT number or PMID absent from inputs and tool outputs tool Covers NCT numbers, PMIDs and (optionally) numbers; not every kind of invented claim
Medical advice SAF-MED-01 Every SKILL.md has a when-not-to-use section with an out-of-scope statement; the banner says not medical advice instruction No tool detects medical advice in a response
Dual use SAF-DUA-01 pharmaskills.chem.hazard screen used by chem profile and chem alerts refuses agent scaffolds and names (exit 2, no descriptors) tool Small conservative substructure list for chemistry only
Dual use SAF-DUA-02 compound-profiler and target-dossier have dual-use adversarial refusal evals and decline text refusal-sample Biology and pathogen requests have no code screen, only instruction and eval
Safety reporting SAF-SAF-01 icsr-e2b and signal-detection SKILL.md and their example outputs carry the reporting-obligation statement instruction Text in outputs the agent writes; the E2B and signal tools do not add it themselves
Regional scope SAF-REG-01 Every SKILL.md names the region assumed or says region-independent instruction Text only
Licence of the project SAF-PRJ-01 LICENSE is Apache-2.0 and every skill frontmatter declares Apache-2.0 (skill lint SK003) tool Examples and synthetic data licence (CC BY 4.0) is documented, not tested
Plain hyphens (PRD s0 rule 9) SAF-DSH-01 pharmaskills qa dash-check, plus skill lint rule SK013 tool Text files only

Rules enforced only by instruction text

These have no deterministic enforcement. They depend on the model following SKILL.md, and the suite proves only that the instruction is present and that the adversarial evals are specified:

  1. Medical advice declined (SAF-MED-01): nothing detects advice in a response.
  2. Regional scope stated (SAF-REG-01): nothing checks that an output names its region.
  3. Safety reporting statement (SAF-SAF-01): the statement lives in the instructions and templates; no tool injects it into an output.
  4. Fabrication refusal in free prose (SAF-FAB-01, SAF-FAB-02): no_fabrication catches identifiers and, optionally, numbers, but an invented qualitative claim passes.
  5. Biology dual use: only chemistry has a code screen (SAF-DUA-01).
  6. Local processing: the model route is the user's choice; only telemetry dependencies are scanned (SAF-LOC-01).
  7. Banner on hand-written documents: SAF-BAN-03 is instruction; the builder guarantees the banner only when it is used.

Model-mode evals (nightly) and human review are the controls for these. Do not describe them as technically enforced.

Draft banner text

The verbatim banner is defined once in src/pharmaskills/banners.py and checked against the PRD text by tests/unit/test_guardrail_primitives.py.

Adding a rule or a case

  1. Add the rule to rules and a case to tests/evals/safety/cases.yaml with rule, kind, enforced_by, check and a one-line description.
  2. Add a @checker("<name>") function to tests/unit/test_safety_suite.py.
  3. Add the case id to the table above. test_guardrails_doc_maps_every_case fails otherwise.