Metadata-Version: 2.4
Name: phm-relay-guardrail
Version: 0.1.0
Summary: Deterministic physics/bounds guardrail for NVIDIA NeMo Relay tool calls (no LLM, recomputable verdicts)
Author: PHM-Audit
License: Apache-2.0
Project-URL: Homepage, https://github.com/PHM-Audit/phm-relay-guardrail
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: nemo-relay-plugin<2.0,>=1.0.0
Dynamic: license-file

# phm-relay-guardrail

Rule-table-based physics/bounds guardrail for [NVIDIA NeMo Relay](https://github.com/nvidia/nemo-relay) tool calls — no LLM in the loop. Rejects tool arguments that violate the shipped physics rule table **before execution**, with three-state verdicts designed to be recomputable from the rule table and the payload.

Part of the [PHM-Audit](https://github.com/PHM-Audit) verification stack (also shipping as a [Dify Marketplace plugin](https://github.com/PHM-Audit/phm-lite-check) and an MCP-registry-listed package).

## What it catches

| Rule | Example rejected | Example allowed |
|---|---|---|
| Probability bounds | `{"probability": 1.8}` | `{"probability": 0.7}` |
| Share/percent bounds | `{"percent_share": 150}` | `{"note": "power increased by 150%"}` (growth, not share) |
| Mass non-negative | `{"mass_kg": -3.0}` | `{"energy_eV": -13.6}` (binding energy, signed) |
| Speed of light | `{"velocity": 5.0e8}` (m/s) | `{"velocity": -1.5e3}` (direction is fine) |
| Absolute zero | `{"temp_c": -300.0}` | `{"temp_c": -196.0}` |
| NaN/Inf | `{"top_k": NaN}` | any finite number |

Design lessons carried over from a maintainer-reviewed upstream implementation ([microsoft/PyRIT #3507](https://github.com/microsoft/PyRIT/pull/3507) — approval there refers to that implementation, not to this plugin): negative energies are legal; growth percentages are not shares; signed velocities are legal; malformed payloads never crash the gate.

NVIDIA maintainer guidance in [NeMo-Relay #1690](https://github.com/NVIDIA/NeMo-Relay/issues/1690) concerned publishing mechanics (build your own plugin, publish separately) — it is not an endorsement.

## Install

Install from source (PyPI release pending):

```bash
pip install git+https://github.com/PHM-Audit/phm-relay-guardrail.git
```

Requires the `nemo-relay-plugin` SDK (`>=1.0.0,<2.0`).

## Use

Serve as a Relay worker plugin:

```bash
python -m phm_relay_guardrail
```

Or embed in your own worker:

```python
from phm_relay_guardrail import PhmPhysicsGuardrailPlugin

plugin = PhmPhysicsGuardrailPlugin()
# pass to your Relay worker bootstrap / serve_plugin(...)
```

Runtime configuration (operator-declared, JSON from the plugin record):

```json
{
  "rules": {"probability_bounds": true, "nan_reject": true, "speed_of_light": true},
  "skip_keys": ["probability"],
  "force_keys": {"altitude": "count"}
}
```

## Status

- Rule-table unit tests: 15/15 passing (`tests/test_rules.py`) — 15 unit-level cases covering the six rule families above, including signed/boundary cases; not exhaustive
- Host end-to-end: smoke-tested against a live `nemo-relay` host pipeline, 3 cases (`tests/e2e_host.py`) — 1 benign call executed normally, 2 physics-invalid calls (out-of-range probability, NaN) vetoed **before** the tool ran
- PyPI package: pending
- Not affiliated with or endorsed by NVIDIA. Apache-2.0.
