Metadata-Version: 2.5
Name: healthcareai-mgr
Version: 0.1.1
Summary: Reference implementation of the Model Governance Record (MGR) v0.1 — an open, vendor-neutral interchange format for healthcare AI governance evidence.
Project-URL: Homepage, https://healthcareaiops.com/standards/mgr/
Project-URL: Specification, https://healthcareaiops.com/standards/mgr-v0.1.schema.json
License-Expression: CC-BY-4.0
License-File: LICENSE
Keywords: ai-governance,audit,clinical-ai,healthcare,mgr,model-governance-record
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# healthcareai-mgr

Reference implementation of the **Model Governance Record (MGR) v0.1** for
Python. Standard library only — nothing to vendor into a locked-down hospital
environment, and nothing to review in a third-party dependency audit.

```sh
pip install healthcareai-mgr
```

Requires Python ≥ 3.10.

## Build a record

```python
from healthcareai_mgr import record, seal, validate

doc = (record(name="Sepsis early warning",
              kind="predictive_model",
              purpose="Flag deterioration risk on adult inpatients",
              vendor="Acme Clinical AI")
       .owned_by("A. Rivera", "Chief Medical Information Officer",
                 "AI Oversight Committee")
       .approved("2026-03-14", "AI Oversight Committee",
                 scope_of_use="Adult inpatient units only",
                 metric="AUROC", value=0.81, decay_threshold=0.05)
       .monitored(date="2026-06-30", metric="AUROC", value=0.79,
                  within_threshold=True)
       .monitored(date="2026-09-30", metric="AUROC", value=0.74,
                  subgroup="65+", within_threshold=False,
                  attested_by="A. Rivera")
       .build())          # raises MgrValidationError if incomplete

sealed = seal(doc)        # adds integrity["head_hash"]
```

Optional arguments you do not pass are **omitted**, never written as `null`.
An absent member and a member present as null are different records and hash
differently.

## Validate one you were given

```python
result = validate(incoming)
if not result.valid:
    for issue in result.errors:
        print(issue)          # "approval.approved_on: must be a calendar date…"
```

`ValidationResult` is truthy when valid. `valid` reflects **errors** only — a
warning marks a place where the v0.1 prose says more than the v0.1 JSON Schema
can express, and a reference implementation that rejected documents the
published schema accepts would fork the standard it exists to serve.

`assert_valid(doc)` is the raising form.

## Verify from the shell, no code

```
pip install healthcareai-mgr
mgr-verify vendor-record.json
```

Structure check, then chain verification, in one command — the ten-second
check for anyone handed a sealed record. Exit codes: ``0`` valid and
intact, ``1`` invalid or tampered, ``2`` unreadable.

## Verify a record has not been edited

```python
v = verify(sealed)
# {"intact": True, "entries": 2, "head_hash": "…", "claimed_hash": "…"}
```

`intact` has three values, not two:

| value | meaning |
|---|---|
| `True` | the chain recomputes to the hash the record claims |
| `False` | it does not — an entry was altered, inserted, removed or reordered |
| `None` | the record carries no integrity block, so there is nothing to check |

The third matters: reporting an unsealed record as `False` would tell a
surveyor that a record was tampered with, when what happened is that nobody
sealed it.

## Canonical JSON, and why this package does not use `json.dumps`

The chain is `sha256hex(prev + "\n" + canonical(entry))`, seeded with the
literal string `genesis`, over `monitoring`, then `incidents`, then
`status_history` in document order.

`json.dumps` cannot produce the canonical bytes, and each way it differs from
JavaScript would silently break verification across a vendor/health-system
boundary:

| case | `json.dumps` | JavaScript, and this package |
|---|---|---|
| non-ASCII (`Frühwarnung`) | `"Frühwarnung"` | `"Frühwarnung"` |
| integral float `1.0` | `1.0` | `1` |
| `1e-7` | `1e-07` | `1e-7` |
| `1e17` | `1e+17` | `100000000000000000` |

`healthcareai_mgr.canonical` renders numbers by JavaScript's rules, which are
the rules the specification names. The test suite cross-checks both
implementations over the awkward values.

## Known v0.1 gaps

* **`agent_privileging` for agents.** The v0.1 schema describes it as required
  when `subject["kind"]` is `"agent"` but expresses no conditional enforcing
  it. This package emits a `conditional_required` warning and leaves the
  document valid, matching the published schema. Slated for v0.2.

## Tests

```sh
python3 -m unittest discover -s tests
```

## Licence

CC BY 4.0, matching the specification.
