superwise-drift-detection-skill
Latest: v1.0.10
Boolean columns are now reported by name as not monitored (previously skipped under a misleading "numeric" warning), with instructions to store them as strings to include them; docs no longer claim Boolean support.
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:
- Superwise credentials —
SUPERWISE_CLIENT_IDandSUPERWISE_SECRET_TOKEN(found in their Superwise account under Settings → API Keys) - Training CSV — the CSV file their model was trained on (feature columns only;
a
row_idcolumn will be added automatically) - Model name — a short label with no spaces (e.g.
my_churn_model); used to name datasets in Superwise - 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 to127.0.0.1only and setINFERENCE_ENDPOINT_URL=http://localhost:5001/predictandINFERENCE_ENDPOINT_ALLOW_PRIVATE=true.
- Option A: They already have a running model endpoint. Ask for the URL.
It must return JSON shaped as
Step 1 — Install dependencies
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
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
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
python -c "
import os; os.chdir('.')
from dotenv import load_dotenv; load_dotenv()
from skill import run
result = run()
print(result)
"
This will:
- Fetch inference records from
INFERENCE_ENDPOINT_URL - Ingest them into the Superwise inference dataset
- Trigger all configured drift policy evaluations
- Poll until each evaluation completes
- 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:
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.yamlgenerates a randomRUN_CHECK_TOKEN; copy it into whatever calls the endpoint. IfRUN_CHECK_TOKENis 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.
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 unlessINFERENCE_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) andGET /health. - Credentials read from env:
SUPERWISE_CLIENT_ID,SUPERWISE_SECRET_TOKENandRUN_CHECK_TOKEN(scheduler only). No messaging credentials. The skill also lists env vars whose names start withSUPERWISE_DRIFT_POLICY_ID_to find per-column policy IDs. It reads no other environment variables by pattern. - Files:
setup_dataset.pyreads the training CSV you point it at.- The skill writes two debug files to the working directory:
superwise_policy_debug.json(last policy response, fromskill.py) andsuperwise_policy_response.json(created policies, fromsetup_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_IDandSUPERWISE_SECRET_TOKENin a plaintext.envfile. Keep.envout of version control and backups (add it to.gitignore), and restrict it withchmod 600 .env. In production, use your host's secret store (e.g. Render environment variables) instead of a.envfile.
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:
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
pendingforever: Check that inference records were successfully ingested before triggering. The inference dataset must have data for the policy to evaluate. unhealthyon 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.logto follow progress.
