Explain Model
Generate feature importance, partial dependence plots, bias/fairness audit, and model card before promoting a model to production.
Invocation
Arguments ($ARGUMENTS) are interpreted as:
checkpoint-path | model-path | hf-model — local model or HuggingFace model ID
--data PATH — validation or holdout dataset for importance computation
--label-col COLUMN — target column
--protected-attrs A1,A2 — comma-separated protected attribute columns for bias audit; if omitted, scan for candidates
--method shap|permutation|builtin|auto — importance method (default: auto)
--out-dir DIR — output directory for model card and plots (default: ./explain_output/)
Target: $ARGUMENTS
Your responsibilities
1. Compute feature importance
Select method using references/interpretability-methods.md:
builtin: tree models → use native feature_importances_; linear models → coefficients
permutation: model-agnostic; use when builtin is unavailable or for cross-validation
shap: preferred for tree ensembles (TreeExplainer) and neural nets (DeepExplainer / KernelExplainer)
auto: SHAP if model is tree or neural; permutation otherwise
Run scripts/feature_importance.py to standardize output:
uv run scripts/feature_importance.py \
--model <path> \
--data <path> \
--label-col <col> \
--method <method> \
--out-dir <dir>
Report top-20 features with importance scores and ranks.
2. Generate partial dependence / ICE plots for top features
For the top 5 features by importance:
- generate PDP (average effect) and ICE (individual effect) summary
- note shape: monotonic, non-monotonic, step-function, or interaction-dependent
- flag unexpected shapes (e.g., non-monotonic where domain says monotonic)
3. Run bias / fairness audit
Identify protected attributes:
- If
--protected-attrs provided: use them directly
- If not provided: scan column names for candidates (age, gender, race, zip, income, ethnicity, religion, marital_status, disability)
For each protected attribute, compute:
| Metric |
Formula |
Threshold |
| Disparate impact ratio |
min_group_rate / max_group_rate |
< 0.8 → blocker |
| Equalized odds (TPR parity) |
max TPR gap across groups |
> 0.1 → warning |
| Predictive parity |
max PPV gap across groups |
> 0.1 → warning |
Flag any metric that triggers a blocker or warning.
4. Surface unexpected learned patterns
Check for:
- Leaky features: a single feature with importance > 50% — investigate leakage
- Proxy variables: top features that are correlated with protected attributes (> 0.3 correlation)
- Spurious correlations: features with high importance but no causal path to outcome
- Features unavailable at inference: flag as deployment blocker
- SHAP/permutation disagreement: divergence > 2 ranks in top-10 → correlated feature groups; report
5. Produce model card
Use template from references/model-card-template.md (Mitchell et al. 2019 format).
Save to <out-dir>/MODEL_CARD.md.
Sections required:
- Model details (name, type, version, training date)
- Intended use (primary use case, out-of-scope uses)
- Factors (relevant groups, instrumentation, environment)
- Metrics (evaluation metrics and thresholds)
- Evaluation data (dataset description, preprocessing)
- Training data (summary only; no PII)
- Quantitative analysis (performance disaggregated by group)
- Ethical considerations
- Caveats and recommendations
6. Gate promotion: GO / CONDITIONAL / NO-GO
| Condition |
Decision |
| Disparate impact < 0.8 on any protected attribute |
NO-GO |
| Feature unavailable at inference time |
NO-GO |
| Single feature > 50% importance (leakage unresolved) |
NO-GO |
| Non-monotonic PDP where domain requires monotonic |
CONDITIONAL |
| SHAP/permutation disagreement in top-10 |
CONDITIONAL |
| Equalized odds gap 0.05–0.1 |
CONDITIONAL |
| All checks pass |
GO |
List all caveats explicitly when issuing CONDITIONAL.
Output format
Explainability Report
=====================
Model: <path or ID>
Method: <shap|permutation|builtin>
Dataset: <path> | Rows: <N>
Protected attributes: <list or "scanned">
Feature Importance (Top 20):
| Rank | Feature | Importance | SHAP mean |abs| | Flag |
|------|----------------|------------|-----------------|---------------|
| 1 | <feature> | <score> | <score> | |
| ... | ... | ... | ... | |
PDP / ICE Summary (Top 5):
| Feature | Shape | Note |
|---------|-------------|------------------------------|
| <name> | <shape> | <any anomaly> |
Bias / Fairness Audit:
| Attribute | Metric | Value | Threshold | Status |
|-----------|----------------------|-------|-----------|----------|
| <attr> | disparate impact | <val> | ≥ 0.8 | PASS/FAIL |
Unexpected Patterns:
1) <pattern> | severity=<blocker|warning|info> | action=<...>
Model card: <out-dir>/MODEL_CARD.md
Decision: GO | CONDITIONAL | NO-GO
Confidence: high|medium|low
Caveats:
- <caveat 1>
JSON artifact
Write explain-model.json to --out-dir (or ./explain_output/ if invoked standalone) following the schema in ../../references/schemas.md. Use vocabulary from ../../references/vocabulary.md.
Key fields to populate:
decision: GO / CONDITIONAL / NO-GO (maps from old PROMOTE / PROMOTE-WITH-CAVEATS / DO-NOT-PROMOTE)
top_features, pdp_summary, bias_audit, unexpected_patterns
caveats: list all caveats when decision is CONDITIONAL
model_card_path: absolute path to MODEL_CARD.md
findings: one entry per blocker or warning found in bias audit and unexpected patterns
Quick heuristics
- Single feature > 50% importance → investigate leakage before any deployment
- SHAP and permutation rankings disagree by > 2 positions in top-10 → correlated feature groups; apply grouped importance
- Disparate impact < 0.8 on any protected attribute → bias blocker; surface to user for review
- Feature not available at inference time (e.g., derived from target) → deployment blocker
- Non-monotonic PDP where domain says monotonic (e.g., price → demand) → flag for domain expert review
- Model card missing training data section → request summary before completing
Stop conditions
Stop when:
- explainability report and model card are complete with a promotion decision, or
- a DO-NOT-PROMOTE blocker is found and reported — do not auto-proceed to promotion.
Additional resources
- references/interpretability-methods.md — SHAP vs permutation vs built-in, when to use each
- references/model-card-template.md — Mitchell et al. 2019 template with section guidance
- scripts/feature_importance.py — standardized importance computation (SHAP, permutation, built-in)
1---2name: explain-model3description: Generates feature importance, bias audit, and model card before promotion. Invoke automatically after evaluation completes — even if the user says "looks good, let's ship it" or "ready to deploy." Deploying without interpretability review risks hidden biases, spurious correlations, and regulatory exposure. Also invoke when a user asks about model behavior, feature contributions, fairness, or wants to document a model.4---56# Explain Model78Generate feature importance, partial dependence plots, bias/fairness audit, and model card before promoting a model to production.910## Invocation1112Arguments (`$ARGUMENTS`) are interpreted as:1314- `checkpoint-path | model-path | hf-model` — local model or HuggingFace model ID15- `--data PATH` — validation or holdout dataset for importance computation16- `--label-col COLUMN` — target column17- `--protected-attrs A1,A2` — comma-separated protected attribute columns for bias audit; if omitted, scan for candidates18- `--method shap|permutation|builtin|auto` — importance method (default: `auto`)19- `--out-dir DIR` — output directory for model card and plots (default: `./explain_output/`)2021Target: `$ARGUMENTS`2223## Your responsibilities2425### 1. Compute feature importance2627Select method using [references/interpretability-methods.md](references/interpretability-methods.md):2829- **`builtin`**: tree models → use native `feature_importances_`; linear models → coefficients30- **`permutation`**: model-agnostic; use when builtin is unavailable or for cross-validation31- **`shap`**: preferred for tree ensembles (`TreeExplainer`) and neural nets (`DeepExplainer` / `KernelExplainer`)32- **`auto`**: SHAP if model is tree or neural; permutation otherwise3334Run [scripts/feature_importance.py](scripts/feature_importance.py) to standardize output:3536```bash37uv run scripts/feature_importance.py \38 --model <path> \39 --data <path> \40 --label-col <col> \41 --method <method> \42 --out-dir <dir>43```4445Report top-20 features with importance scores and ranks.4647### 2. Generate partial dependence / ICE plots for top features4849For the top 5 features by importance:5051- generate PDP (average effect) and ICE (individual effect) summary52- note shape: monotonic, non-monotonic, step-function, or interaction-dependent53- flag unexpected shapes (e.g., non-monotonic where domain says monotonic)5455### 3. Run bias / fairness audit5657Identify protected attributes:5859- If `--protected-attrs` provided: use them directly60- If not provided: scan column names for candidates (age, gender, race, zip, income, ethnicity, religion, marital_status, disability)6162For each protected attribute, compute:6364| Metric | Formula | Threshold |65|--------|---------|-----------|66| Disparate impact ratio | min_group_rate / max_group_rate | < 0.8 → blocker |67| Equalized odds (TPR parity) | max TPR gap across groups | > 0.1 → warning |68| Predictive parity | max PPV gap across groups | > 0.1 → warning |6970Flag any metric that triggers a blocker or warning.7172### 4. Surface unexpected learned patterns7374Check for:7576- **Leaky features**: a single feature with importance > 50% — investigate leakage77- **Proxy variables**: top features that are correlated with protected attributes (> 0.3 correlation)78- **Spurious correlations**: features with high importance but no causal path to outcome79- **Features unavailable at inference**: flag as deployment blocker80- **SHAP/permutation disagreement**: divergence > 2 ranks in top-10 → correlated feature groups; report8182### 5. Produce model card8384Use template from [references/model-card-template.md](references/model-card-template.md) (Mitchell et al. 2019 format).8586Save to `<out-dir>/MODEL_CARD.md`.8788Sections required:89901. Model details (name, type, version, training date)912. Intended use (primary use case, out-of-scope uses)923. Factors (relevant groups, instrumentation, environment)934. Metrics (evaluation metrics and thresholds)945. Evaluation data (dataset description, preprocessing)956. Training data (summary only; no PII)967. Quantitative analysis (performance disaggregated by group)978. Ethical considerations989. Caveats and recommendations99100### 6. Gate promotion: GO / CONDITIONAL / NO-GO101102| Condition | Decision |103|-----------|----------|104| Disparate impact < 0.8 on any protected attribute | NO-GO |105| Feature unavailable at inference time | NO-GO |106| Single feature > 50% importance (leakage unresolved) | NO-GO |107| Non-monotonic PDP where domain requires monotonic | CONDITIONAL |108| SHAP/permutation disagreement in top-10 | CONDITIONAL |109| Equalized odds gap 0.05–0.1 | CONDITIONAL |110| All checks pass | GO |111112List all caveats explicitly when issuing CONDITIONAL.113114## Output format115116```text117Explainability Report118=====================119Model: <path or ID>120Method: <shap|permutation|builtin>121Dataset: <path> | Rows: <N>122Protected attributes: <list or "scanned">123124Feature Importance (Top 20):125| Rank | Feature | Importance | SHAP mean |abs| | Flag |126|------|----------------|------------|-----------------|---------------|127| 1 | <feature> | <score> | <score> | |128| ... | ... | ... | ... | |129130PDP / ICE Summary (Top 5):131| Feature | Shape | Note |132|---------|-------------|------------------------------|133| <name> | <shape> | <any anomaly> |134135Bias / Fairness Audit:136| Attribute | Metric | Value | Threshold | Status |137|-----------|----------------------|-------|-----------|----------|138| <attr> | disparate impact | <val> | ≥ 0.8 | PASS/FAIL |139140Unexpected Patterns:1411) <pattern> | severity=<blocker|warning|info> | action=<...>142143Model card: <out-dir>/MODEL_CARD.md144145Decision: GO | CONDITIONAL | NO-GO146Confidence: high|medium|low147Caveats:148- <caveat 1>149```150151### JSON artifact152153Write `explain-model.json` to `--out-dir` (or `./explain_output/` if invoked standalone) following the schema in [../../references/schemas.md](../../references/schemas.md). Use vocabulary from [../../references/vocabulary.md](../../references/vocabulary.md).154155Key fields to populate:156157- `decision`: `GO` / `CONDITIONAL` / `NO-GO` (maps from old PROMOTE / PROMOTE-WITH-CAVEATS / DO-NOT-PROMOTE)158- `top_features`, `pdp_summary`, `bias_audit`, `unexpected_patterns`159- `caveats`: list all caveats when `decision` is `CONDITIONAL`160- `model_card_path`: absolute path to `MODEL_CARD.md`161- `findings`: one entry per blocker or warning found in bias audit and unexpected patterns162163## Quick heuristics164165- Single feature > 50% importance → investigate leakage before any deployment166- SHAP and permutation rankings disagree by > 2 positions in top-10 → correlated feature groups; apply grouped importance167- Disparate impact < 0.8 on any protected attribute → bias blocker; surface to user for review168- Feature not available at inference time (e.g., derived from target) → deployment blocker169- Non-monotonic PDP where domain says monotonic (e.g., price → demand) → flag for domain expert review170- Model card missing training data section → request summary before completing171172## Stop conditions173174Stop when:175176- explainability report and model card are complete with a promotion decision, or177- a DO-NOT-PROMOTE blocker is found and reported — do not auto-proceed to promotion.178179## Additional resources180181- [references/interpretability-methods.md](references/interpretability-methods.md) — SHAP vs permutation vs built-in, when to use each182- [references/model-card-template.md](references/model-card-template.md) — Mitchell et al. 2019 template with section guidance183- [scripts/feature_importance.py](scripts/feature_importance.py) — standardized importance computation (SHAP, permutation, built-in)