back
loading skill details...
Detects feature drift in tabular ML models using Superwise Compare Distribution policies (Jensen-Shannon divergence for categorical string columns). Handles everything: Superwise dataset creation, training data upload, drift policy setup, inference ingestion, and a plain-text drift summary for OpenC
---
name: superwise-drift-detection-skill
description: >
Detects feature drift in tabular ML models using Superwise Compare Distribution
policies (Jensen-Shannon divergence for categorical string columns). Handles everything:
Superwise dataset creation, training data upload, drift policy setup, inference
ingestion, and a plain-text drift summary for OpenClaw to relay. Also covers
replacing the training baseline in Superwise after the user retrains their model
(the skill never trains models itself), and an optional scheduler service
(scheduler.py) that runs the check daily and exposes a token-protected
POST /run-check endpoint for manual runs.
Use when: user says "set up drift detection", "detect model drift", "monitor my
model for drift", "check if my model is drifting", or "add drift detection to
my model".
version: 1.0.10
allowed-tools: Bash(pip install --require-hashes -r requirements.txt) Bash(python setup_dataset.py:*) Bash(python setup_drift_policy.py:*) Bash(python -c:*) Bash(python scheduler.py)
metadata:
openclaw:
requires:
env:
- SUPERWISE_CLIENT_ID
- SUPERWISE_SECRET_TOKEN
- INFERENCE_ENDPOINT_URL
bins:
- python3
primaryEnv: SUPERWISE_SECRET_TOKEN
envVars:
- {name: SUPERWISE_CLIENT_ID, required: true, description: Superwise API client ID.}
- {name: SUPERWISE_SECRET_TOKEN, required: true, description: Superwise API secret.}
- {name: INFERENCE_ENDPOINT_URL, required: true, description: "Your model endpoint returning {\"records\": [...]}; https and public unless INFERENCE_ENDPOINT_ALLOW_PRIVATE=true."}
- {name: INFERENCE_ENDPOINT_ALLOW_PRIVATE, required: false, description: Set true only for local development (allows http and private hosts).}
- {name: MODEL_NAME, required: false, description: Label used in dataset names and alerts.}
- {name: SUPERWISE_AUTO_TRIGGER, required: false, description: Trigger policy evaluation after ingest (true/false).}
- {name: SUPERWISE_TRAINING_DATASET_ID, required: false, description: Set from setup_dataset.py output.}
- {name: SUPERWISE_TRAINING_DATASET_NAME, required: false, description: Set from setup_dataset.py output.}
- {name: SUPERWISE_TRAINING_CUBE_NAME, required: false, description: Set from setup_dataset.py output.}
- {name: SUPERWISE_INFERENCE_DATASET_ID, required: false, description: Set from setup_dataset.py output.}
- {name: SUPERWISE_INFERENCE_DATASET_NAME, required: false, description: Set from setup_dataset.py output.}
- {name: SUPERWISE_INFERENCE_CUBE_NAME, required: false, description: Set from setup_dataset.py output.}
- {name: SUPERWISE_DRIFT_POLICY_ID, required: false, description: Primary policy ID from setup_drift_policy.py.}
- {name: "SUPERWISE_DRIFT_POLICY_ID_<column>", required: false, description: Per-column policy IDs from setup_drift_policy.py; the skill reads env vars with this prefix only.}
- {name: RUN_CHECK_TOKEN, required: false, description: "scheduler.py only: bearer token for POST /run-check (endpoint disabled if unset)."}
- {name: RUN_CHECK_MIN_INTERVAL_SEC, required: false, description: "scheduler.py only: minimum seconds between manual checks (default 300)."}
- {name: SCHEDULE_HOUR_UTC, required: false, description: "scheduler.py only: daily run hour (default 6)."}
- {name: SCHEDULE_MINUTE_UTC, required: false, description: "scheduler.py only: daily run minute (default 0)."}
- {name: PORT, required: false, description: "scheduler.py only: HTTP port (default 5000)."}
permissions:
env: [see metadata.openclaw.envVars]
network:
- outbound https://api.superwise.ai (dataset setup, ingest, policy trigger/poll)
- outbound INFERENCE_ENDPOINT_URL (user-configured, GET)
- inbound POST /run-check (bearer token) and GET /health (scheduler.py only, when deployed)
file_read:
- the training CSV passed to setup_dataset.py
- .env (user-created)
file_write:
- .env (created by the user during setup; holds Superwise credentials; keep chmod 600 and out of version control)
- superwise_policy_debug.json, superwise_policy_response.json (Superwise policy metadata, no credentials)
- drift_check.log (optional, if the check is run in the background as described)
shell:
- pip install --require-hashes -r requirements.txt
- python setup_dataset.py / setup_drift_policy.py / scheduler.py
- python -c "from skill import run; run()"
---
# Superwise Drift Detection Skill
When the user wants to set up drift detection for their model, guide them through
the steps below in order. Complete each step before moving to the next.
## What You Need From the User
Ask the user to provide the following before starting:
1. **Superwise credentials** — `SUPERWISE_CLIENT_ID` and `SUPERWISE_SECRET_TOKEN`
(found in their Superwise account under Settings → API Keys)
2. **Training CSV** — the CSV file their model was trained on (feature columns only;
a `row_id` column will be added automatically)
3. **Model name** — a short label with no spaces (e.g. `my_churn_model`); used to
name datasets in Superwise
4. **Inference endpoint** — one of two options:
- **Option A**: They already have a running model endpoint. Ask for the URL.
It must return JSON shaped as `{"records": [{...}, ...]}` where each record
contains the same columns as the training CSV.
- **Option B**: They need to deploy one. Any small web service works if a
GET returns `{"records": [...]}` built from their model's recent inputs and
predictions. This package does not ship one. For local testing, bind it to
`127.0.0.1` only and set `INFERENCE_ENDPOINT_URL=http://localhost:5001/predict`
and `INFERENCE_ENDPOINT_ALLOW_PRIVATE=true`.
## Step 1 — Install dependencies
```bash
pip install --require-hashes -r requirements.txt
```
Dependencies are pinned with hashes. `requirements.in` lists the top-level
pins; regenerate with `uv pip compile requirements.in --generate-hashes -o requirements.txt`.
Create a `.env` file in the skill root directory with the following contents,
filling in the values the user provided:
```
SUPERWISE_CLIENT_ID=<from user>
SUPERWISE_SECRET_TOKEN=<from user>
MODEL_NAME=<model name>
INFERENCE_ENDPOINT_URL=<from user's answer to question 4>
# Only for local development (allows http and localhost/private hosts):
# INFERENCE_ENDPOINT_ALLOW_PRIVATE=true
SUPERWISE_AUTO_TRIGGER=true
SUPERWISE_TRAINING_DATASET_ID=
SUPERWISE_TRAINING_DATASET_NAME=
SUPERWISE_TRAINING_CUBE_NAME=
SUPERWISE_INFERENCE_DATASET_ID=
SUPERWISE_INFERENCE_DATASET_NAME=
SUPERWISE_INFERENCE_CUBE_NAME=
SUPERWISE_DRIFT_POLICY_ID=
# Additional per-column policies — add one line per column printed by setup_drift_policy.py:
# SUPERWISE_DRIFT_POLICY_ID_<column>=<policy ID>
SCHEDULE_HOUR_UTC=6
SCHEDULE_MINUTE_UTC=0
PORT=5000
```
The dataset and policy ID fields will be filled in after Steps 2 and 3.
## Step 2 — Create Superwise datasets and upload training data
```bash
python setup_dataset.py \
--training-csv path/to/training.csv \
--model-name their_model_name
```
This creates a training dataset and an inference dataset in Superwise, uploads
the training CSV row by row, and prints the dataset IDs and cube names.
Copy the printed values into `.env`:
```
SUPERWISE_TRAINING_DATASET_ID=<printed value>
SUPERWISE_TRAINING_DATASET_NAME=<printed value>
SUPERWISE_TRAINING_CUBE_NAME=<printed value>
SUPERWISE_INFERENCE_DATASET_ID=<printed value>
SUPERWISE_INFERENCE_DATASET_NAME=<printed value>
SUPERWISE_INFERENCE_CUBE_NAME=<printed value>
```
Note: training CSV column names must use only letters, numbers, and underscores,
and must start with a letter. Warn the user if any column names violate this.
## Step 3 — Create drift policies
```bash
python setup_drift_policy.py \
--training-csv path/to/training.csv \
--policy-name their_model_drift
```
This creates one Jensen-Shannon divergence policy per categorical (string)
column in the training CSV, comparing the training dataset against the inference
dataset. Other columns are skipped with a warning:
- **Numeric columns:** a known Superwise platform limitation (wasserstein
distance for numeric columns is not yet supported).
- **Boolean columns:** not monitored as-is. To include them, store them as
strings (`"true"`/`"false"`) in both the training CSV and the inference
records, then re-run this script. Tell the user which Boolean columns were
skipped so they don't assume those features are covered.
Copy the primary printed policy ID into `.env`:
```
SUPERWISE_DRIFT_POLICY_ID=<primary policy ID>
SUPERWISE_DRIFT_POLICY_ID_<column2>=<policy ID>
SUPERWISE_DRIFT_POLICY_ID_<column3>=<policy ID>
# ... one line per additional column policy printed by setup_drift_policy.py
```
Copy all printed policy lines (not just the first) — `_check_drift()` will trigger
and check every `SUPERWISE_DRIFT_POLICY_ID*` env var automatically.
If the user wants to monitor only specific columns, add `--columns col1 col2 col3`.
## Step 4 — Run an end-to-end drift check
```bash
python -c "
import os; os.chdir('.')
from dotenv import load_dotenv; load_dotenv()
from skill import run
result = run()
print(result)
"
```
This will:
1. Fetch inference records from `INFERENCE_ENDPOINT_URL`
2. Ingest them into the Superwise inference dataset
3. Trigger all configured drift policy evaluations
4. Poll until each evaluation completes
5. Print and return a plain-text drift summary
**Note:** The full check can take 5-10 minutes (inference fetch + ingest + policy
polling across all columns). If your agent's command runner has a short timeout,
run it with output to a log file and follow the log:
```bash
python -c "from skill import run; run()" > drift_check.log 2>&1 &
tail -f drift_check.log
```
The process ends when the check finishes. For recurring checks, use Step 5
rather than leaving processes running.
## Step 5 — Schedule recurring drift checks
Register the skill with OpenClaw using the metadata in `skill.py`:
- **Trigger command:** `/drift_check`
- **Schedule:** `0 6 * * *` (06:00 UTC daily — adjust to the user's inference cadence)
- **Alerts:** the skill returns a plain-text summary; route it to chat or email
through OpenClaw's own delivery (see "Drift summary" below)
For a production deployment, guide the user to deploy `scheduler.py` to Render
using the included `render.yaml`. Set all `.env` values as Render environment
variables.
`scheduler.py` exposes `POST /run-check` for manual checks. It is protected:
- It requires `Authorization: Bearer <RUN_CHECK_TOKEN>`. `render.yaml`
generates a random `RUN_CHECK_TOKEN`; copy it into whatever calls the
endpoint. If `RUN_CHECK_TOKEN` is unset, the endpoint is disabled (503).
- Only one check runs at a time (409 if busy), and manual checks are limited
to one per `RUN_CHECK_MIN_INTERVAL_SEC` (default 300 s; 429 otherwise).
- Errors return a generic message; details go to the server log only.
```bash
curl -X POST -H "Authorization: Bearer $RUN_CHECK_TOKEN" https://<your-app>.onrender.com/run-check
```
## Drift summary
The skill sends no alerts itself and reads no messaging credentials. `run()`
prints a plain-text summary and returns it as `result["message"]`, along with
`alert_fired` and `high_drift_features`. OpenClaw (or whatever calls the skill)
delivers it through its own configured channels, e.g. its Telegram connection.
Summaries look like:
- **Unhealthy:** lists features with high drift (score > 0.2), flags that
predictions may be unreliable
- **Healthy:** confirms no significant drift with per-feature scores
## What this skill touches
Review this before installing or deploying:
- **Outbound network:**
- `INFERENCE_ENDPOINT_URL` (GET). It must be https and resolve only to public
addresses unless `INFERENCE_ENDPOINT_ALLOW_PRIVATE=true`. The request
connects to the exact address that passed that check (so a DNS answer that
changes in between cannot redirect it), and TLS is verified against the real
hostname. Redirects are not followed, and responses over 50 MB are rejected.
- The Superwise API, to create datasets, ingest records and trigger and
poll drift policies. **Every inference record fetched from your endpoint is
sent to Superwise**, so only use data approved for processing there.
- **Inbound network (only if you deploy `scheduler.py`):** `POST /run-check`
(token-protected, see Step 5) and `GET /health`.
- **Credentials read from env:** `SUPERWISE_CLIENT_ID`, `SUPERWISE_SECRET_TOKEN`
and `RUN_CHECK_TOKEN` (scheduler only). No messaging credentials.
The skill also lists env vars whose names start with
`SUPERWISE_DRIFT_POLICY_ID_` to find per-column policy IDs. It reads no
other environment variables by pattern.
- **Files:**
- `setup_dataset.py` reads the training CSV you point it at.
- The skill writes two debug files to the working directory:
`superwise_policy_debug.json` (last policy response, from `skill.py`) and
`superwise_policy_response.json` (created policies, from
`setup_drift_policy.py`). They contain Superwise policy metadata, not
credentials.
- The skill's code never writes credentials. **Setup does ask you to store
`SUPERWISE_CLIENT_ID` and `SUPERWISE_SECRET_TOKEN` in a
plaintext `.env` file.** Keep `.env` out of version control and backups
(add it to `.gitignore`), and restrict it with `chmod 600 .env`. In
production, use your host's secret store (e.g. Render environment
variables) instead of a `.env` file.
## Retraining
This section is about replacing the **baseline** in Superwise after the user has
retrained their model on their own. The skill does not train or modify models.
When the user retrains their model:
```bash
python setup_dataset.py \
--training-csv path/to/new_training.csv \
--model-name their_model_name \
--retrain
```
This creates a versioned replacement training dataset and preserves the inference
history. Update `.env` with the new training dataset ID and cube name, then re-run
`setup_drift_policy.py` to create a new policy pointing at the updated baseline.
## Troubleshooting
- **Policy stays `pending` forever:** Check that inference records were successfully
ingested before triggering. The inference dataset must have data for the policy
to evaluate.
- **`unhealthy` on first run:** Expected if inference records are a single time-slice
snapshot (all same hour/day/season). Accumulate inference records over time for
a more representative distribution.
- **Numeric columns skipped:** Wasserstein distance for numeric dimensions is a
known Superwise platform bug. Use categorical bucketing as a workaround, or
wait for the Superwise platform fix.
- **CubeJS cube not found after upload:** New datasets take a few minutes to
register in Superwise's CubeJS layer. Wait 2–3 minutes and retry verification.
- **Drift check killed / no output (SIGTERM):** The full check takes 5-10 minutes and will
be killed by any exec timeout in your environment. Run it with output to a log
file as shown in Step 4, then `tail -f drift_check.log` to follow progress.
don't have the plugin yet? install it then click "run inline in claude" again.