Domain-correctness gate
Across every field the top complaint is code that executes cleanly but is
scientifically wrong. This gate intercepts that field's classic error classes
deterministically — by analysing the code you actually wrote, not by
recalling rules. It verifies specific error classes; it never proves correctness.
Run it as a normal step of any analysis — it is fast, offline, and stdlib-only.
When to run
- Before executing analysis code you generated (catch the bug before it
produces a plausible-but-wrong number).
- After generating results, as a final gate before you report figures or
numbers to the user.
- Whenever the user asks to check, validate, or audit an analysis for
correctness.
How to run
The gate ships beside this SKILL.md. Run it on the code files in play (or with
no arguments to scan the workspace):
python "$XDG_CONFIG_HOME/opencode/skills/domain-check/domain_check.py" <file.py|notebook.ipynb|analysis.R ...>
It prints exactly one ```review fenced JSON block on stdout.
What it catches (one rule set per discipline)
- physics · units — adding/subtracting/comparing quantities of different
dimensions (e.g.
t_seconds + d_meters); trig on a degree-valued angle.
- earth · crs — Euclidean/Pythagorean distance on latitude/longitude
(
sqrt((lat1-lat2)**2 + (lon1-lon2)**2)); a geopandas geometric op with no
CRS ever set.
- biology · coords / strand — off-by-one on BED intervals (0-based
half-open, so length is
end - start, never +1); a sequence sliced from a
stranded feature file (GFF/GTF/BED) with no reverse-complement for the -
strand.
- chem · valence — a SMILES string literal (assigned to a
smiles/smi
variable, or passed to MolFromSmiles/MolFromSmarts) that cannot be a real
molecule. If RDKit is installed it is used as the authoritative judge —
Chem.MolFromSmiles sanitizes the parse, so it catches far more than a
five-bond carbon (bad ring closures, impossible aromaticity, over-valent
N/O/S) and, being authoritative, clears molecules a heuristic would
wrongly flag. Without RDKit it falls back to a stdlib bond-counter (carbon
4, over-bonded halogen; bails on bracket atoms for precision).
- social · multiple-comparisons — a significance test (
ttest_ind,
pearsonr, f_oneway, chi2_contingency, …) run inside a loop or ≥3 times
with no multipletests/FDR/Bonferroni correction anywhere — the inflated
family-wise false-positive rate that silent p-hacking produces.
- social · categorical — a numeric reduction (
.mean()/.median()/.std()
…) taken directly on a nominal category code (gender, race, region,
condition, …), treating an unordered label as an interval quantity. A
groupby('gender') key is correct usage and is not flagged.
- bioprocess · unconstrained-kinetics —
curve_fit fitting a local model
function whose parameters are classic non-negative kinetic constants
(Monod/Haldane mu_max/Ks/Ki, Pirt/yield Yxs/Yps, Luedeking-Piret
alpha/beta, …) with no bounds=, letting a noisy or sparse fit converge
to a physically impossible negative value. Names that belong to any curve at
all (alpha, beta, kd, ka) count only beside an unambiguous one or in
a file that otherwise reads as a fermentation, so a plain power law, whose
exponent is routinely negative, is left alone.
- bioprocess · kla-driving-force — in a file that computes
kLa, taking
log() of the raw dissolved-oxygen reading instead of the (C* - C)
driving force the dynamic gassing-out method requires (dC/dt = kLa(C*-C),
so the regression is on ln(C* - C), not ln(C)).
- bioprocess · cfu-log-scale — a numeric reduction (
.mean()/.std()/…)
taken directly on a raw CFU (colony-forming-unit) plate count. Microbial
counts are approximately log-normal; the convention is to average
log10(CFU), not the raw count. A variable already named as the log
quantity (log_cfu) or a .mean() taken after np.log10(...) is not
flagged.
- bioprocess · anova-assumptions —
f_oneway/anova_lm/
pairwise_tukeyhsd/tukey_hsd run in a file with no normality
(shapiro/normaltest/anderson) or variance-homogeneity
(levene/bartlett/fligner) check anywhere in it — the two assumptions
the test's stated false-positive rate depends on. Scoped to files that read
as a fermentation (biomass, bioreactor, CFU, fed-batch, …): the
statistics generalize, but a finding tagged bioprocess on a three-arm
survey does not.
- bioprocess · rsm-first-order-fit — a Box-Behnken/central-composite
design (
bbdesign/ccdesign/box_behnken/central_composite in the
file) fit through a statsmodels formula with no quadratic (I(x**2)) or
interaction (x1:x2) term — the design was built to estimate curvature, so
a first-order model wastes it and cannot locate an interior optimum.
- bioprocess · cross-scale-fit — a real model fit (
.fit(...), guarded to
a file that imports scikit-learn, XGBoost, statsmodels, PyTorch,
TensorFlow, or Keras — a plain scipy.curve_fit never counts) in a file
that mentions both a small-scale (flask, bench-scale) and a large-scale
(bioreactor, fermenter, fed-batch, pilot-scale) process vocabulary, e.g.
trained on flask data and applied to a bioreactor. Advisory: a warn, not a
defect. Silent once a calibration / scaling-factor / cross-validation term is
in the file, and silent on batch_size and friends — bare batch matched the
training knobs of the very libraries this rule requires.
Rules favour precision: an unrecognized unit, arithmetic with no discipline
signal, a SMILES using bracket atoms (which carry their own valence/charge), a
single significance test, or a categorical used only as a groupby key is left
silent rather than flagged.
Reporting findings
Copy the ```review block the tool prints as the **last thing** in your
message — the app renders it as dismissible reviewer cards. Do not paraphrase
the findings into prose and drop the block; the structured block is the
contract. If the gate found nothing, say so plainly and keep the block (its
note states that no findings is not a guarantee of correctness).
Never tell the user the code is "correct" or "error-free" — the gate checks
known error classes only.
Adding a discipline
Add a check_<field>(ctx) function in domain_check.py and append it to
VALIDATORS. No other change is needed — the review contract and the app's
rendering are discipline-agnostic (each finding carries its own tag).
1---2name: domain-check3description: Use whenever you write or run scientific analysis code (physics, earth/geo, biology, chemistry, social science, or bioprocess/fermentation) in this workspace — before executing it and again after generating results. Runs a deterministic domain-correctness gate that catches code which runs but is scientifically wrong (unit/dimension mismatch, Euclidean distance on lat/lon without a CRS, 0-based/1-based coordinate and strand errors, impossible SMILES valence, uncorrected multiple comparisons, averaging a categorical code, unconstrained kinetic-parameter fits, kLa computed from raw DO instead of the driving force, arithmetic mean of raw CFU counts, ANOVA/Tukey with no assumption check, a curvature DOE design fit with a first-order model, an ML model fit across process scales with no correction). Surfaces structured findings; never claims the code is correct.4---56# Domain-correctness gate78Across every field the top complaint is code that **executes cleanly but is9scientifically wrong**. This gate intercepts that field's classic error classes10**deterministically** — by analysing the code you actually wrote, not by11recalling rules. It verifies specific error classes; it never proves correctness.1213Run it as a normal step of any analysis — it is fast, offline, and stdlib-only.1415## When to run1617- **Before executing** analysis code you generated (catch the bug before it18 produces a plausible-but-wrong number).19- **After generating results**, as a final gate before you report figures or20 numbers to the user.21- Whenever the user asks to check, validate, or audit an analysis for22 correctness.2324## How to run2526The gate ships beside this SKILL.md. Run it on the code files in play (or with27no arguments to scan the workspace):2829```bash30python "$XDG_CONFIG_HOME/opencode/skills/domain-check/domain_check.py" <file.py|notebook.ipynb|analysis.R ...>31```3233It prints exactly one ` ```review ` fenced JSON block on stdout.3435## What it catches (one rule set per discipline)3637- **physics · units** — adding/subtracting/comparing quantities of different38 dimensions (e.g. `t_seconds + d_meters`); trig on a degree-valued angle.39- **earth · crs** — Euclidean/Pythagorean distance on latitude/longitude40 (`sqrt((lat1-lat2)**2 + (lon1-lon2)**2)`); a geopandas geometric op with no41 CRS ever set.42- **biology · coords / strand** — off-by-one on BED intervals (0-based43 half-open, so length is `end - start`, never `+1`); a sequence sliced from a44 stranded feature file (GFF/GTF/BED) with no reverse-complement for the `-`45 strand.46- **chem · valence** — a SMILES string literal (assigned to a `smiles`/`smi`47 variable, or passed to `MolFromSmiles`/`MolFromSmarts`) that cannot be a real48 molecule. **If RDKit is installed it is used as the authoritative judge** —49 `Chem.MolFromSmiles` sanitizes the parse, so it catches far more than a50 five-bond carbon (bad ring closures, impossible aromaticity, over-valent51 N/O/S) and, being authoritative, clears molecules a heuristic would52 wrongly flag. Without RDKit it falls back to a stdlib bond-counter (carbon53 >4, over-bonded halogen; bails on bracket atoms for precision).54- **social · multiple-comparisons** — a significance test (`ttest_ind`,55 `pearsonr`, `f_oneway`, `chi2_contingency`, …) run inside a loop or ≥3 times56 with no `multipletests`/FDR/Bonferroni correction anywhere — the inflated57 family-wise false-positive rate that silent p-hacking produces.58- **social · categorical** — a numeric reduction (`.mean()`/`.median()`/`.std()`59 …) taken directly on a nominal category code (`gender`, `race`, `region`,60 `condition`, …), treating an unordered label as an interval quantity. A61 `groupby('gender')` key is correct usage and is not flagged.62- **bioprocess · unconstrained-kinetics** — `curve_fit` fitting a local model63 function whose parameters are classic non-negative kinetic constants64 (Monod/Haldane `mu_max`/`Ks`/`Ki`, Pirt/yield `Yxs`/`Yps`, Luedeking-Piret65 `alpha`/`beta`, …) with no `bounds=`, letting a noisy or sparse fit converge66 to a physically impossible negative value. Names that belong to any curve at67 all (`alpha`, `beta`, `kd`, `ka`) count only beside an unambiguous one or in68 a file that otherwise reads as a fermentation, so a plain power law, whose69 exponent is routinely negative, is left alone.70- **bioprocess · kla-driving-force** — in a file that computes `kLa`, taking71 `log()` of the raw dissolved-oxygen reading instead of the `(C* - C)`72 driving force the dynamic gassing-out method requires (`dC/dt = kLa(C*-C)`,73 so the regression is on `ln(C* - C)`, not `ln(C)`).74- **bioprocess · cfu-log-scale** — a numeric reduction (`.mean()`/`.std()`/…)75 taken directly on a raw CFU (colony-forming-unit) plate count. Microbial76 counts are approximately log-normal; the convention is to average77 `log10(CFU)`, not the raw count. A variable already named as the log78 quantity (`log_cfu`) or a `.mean()` taken after `np.log10(...)` is not79 flagged.80- **bioprocess · anova-assumptions** — `f_oneway`/`anova_lm`/81 `pairwise_tukeyhsd`/`tukey_hsd` run in a file with no normality82 (`shapiro`/`normaltest`/`anderson`) or variance-homogeneity83 (`levene`/`bartlett`/`fligner`) check anywhere in it — the two assumptions84 the test's stated false-positive rate depends on. Scoped to files that read85 as a fermentation (`biomass`, `bioreactor`, `CFU`, `fed-batch`, …): the86 statistics generalize, but a finding tagged `bioprocess` on a three-arm87 survey does not.88- **bioprocess · rsm-first-order-fit** — a Box-Behnken/central-composite89 design (`bbdesign`/`ccdesign`/`box_behnken`/`central_composite` in the90 file) fit through a `statsmodels` formula with no quadratic (`I(x**2)`) or91 interaction (`x1:x2`) term — the design was built to estimate curvature, so92 a first-order model wastes it and cannot locate an interior optimum.93- **bioprocess · cross-scale-fit** — a real model fit (`.fit(...)`, guarded to94 a file that imports scikit-learn, XGBoost, statsmodels, PyTorch,95 TensorFlow, or Keras — a plain `scipy.curve_fit` never counts) in a file96 that mentions both a small-scale (flask, bench-scale) and a large-scale97 (bioreactor, fermenter, fed-batch, pilot-scale) process vocabulary, e.g.98 trained on flask data and applied to a bioreactor. Advisory: a warn, not a99 defect. Silent once a calibration / scaling-factor / cross-validation term is100 in the file, and silent on `batch_size` and friends — bare `batch` matched the101 training knobs of the very libraries this rule requires.102103Rules favour precision: an unrecognized unit, arithmetic with no discipline104signal, a SMILES using bracket atoms (which carry their own valence/charge), a105single significance test, or a categorical used only as a groupby key is left106silent rather than flagged.107108## Reporting findings109110Copy the ` ```review ` block the tool prints as the **last thing** in your111message — the app renders it as dismissible reviewer cards. Do not paraphrase112the findings into prose and drop the block; the structured block is the113contract. If the gate found nothing, say so plainly and keep the block (its114`note` states that no findings is not a guarantee of correctness).115116Never tell the user the code is "correct" or "error-free" — the gate checks117known error classes only.118119## Adding a discipline120121Add a `check_<field>(ctx)` function in `domain_check.py` and append it to122`VALIDATORS`. No other change is needed — the review contract and the app's123rendering are discipline-agnostic (each finding carries its own `tag`).