/ai-research-workflows:hardening-research-codefrom ai-research-workflows
Hardens research and scientific code for verifiable correctness, regression safety, and numerical stability using golden tests, analytic references, and tolerance-based comparisons.
Ships in ai-research-workflows. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Make research and scientific code trustworthy: correct, regression-safe, and numerically stable by establishing explicit criteria and backing them with targeted tests.
This skill leans Direct by default. For the full Collaborative-vs-Direct protocol and override rules, see the Interaction Modes reference in the ai-research-workflows:using-research-workflows skill.
Research code often starts as exploratory scripts. Hardening turns it into trustworthy software: outputs are verifiably correct, regressions are caught automatically, and numerical behavior is documented and bounded.
Pinning the current outputs proves only that behavior hasn't changed — not that it is right. Never label outputs as a verified or "golden" baseline until they are checked against an independent reference (analytic limit, reference implementation, published result, or invariant).
Before falling back to regression-pinning, you MUST confirm no analytic limit,
reference implementation, or invariant is reasonably derivable. If one is,
verify against it first — "the output looks plausible" is not verification. If
you pin outputs that have NOT been independently verified, label the baseline
UNVERIFIED so it is never mistaken for established-correct values, and say so
to whoever relies on it.
Before writing any test, decide what "correct" means for this code:
Document the chosen criterion explicitly before writing tests. A test without a stated criterion is uninterpretable when it fails.
Compute expected outputs from a trusted source — an analytic formula, a reference implementation, or a published dataset — and assert that the code under test matches those outputs within tolerance. Store expected values and any input data in a versioned file alongside the tests.
Never use exact float equality. Always use absolute or relative tolerances appropriate to the domain:
# strategy-level pseudocode — defer mechanics to python-testing skill
assert |result - expected| < atol + rtol * |expected|
Document the tolerance choice: what physical or numerical argument justifies it? If tolerance is tightened or loosened later, the justification must be updated.
Choosing the bound: start from the floating-point floor — roughly machine
epsilon times the number of accumulating operations (atol ≈ N · eps · scale)
— and widen only for a documented reason (iterative-solver tolerance, stochastic
variance). Use rtol for values spanning orders of magnitude, atol for values
near zero. Never tune the tolerance to make a failing test pass — a bound
chosen to fit the result is a silent correctness hole; derive it from the
numerics, not the output.
Use this only after confirming no analytic limit, reference implementation,
or invariant is reasonably derivable (see the Iron Law) — a regression baseline
is a fallback, not a substitute for verification. When it genuinely is the only
option: run the code on canonical inputs, check the outputs against whatever
partial criteria you can (ranges, signs, invariants, expected trends), and pin
them. Future runs must stay within tolerance of that baseline. If the pinned
values were not verified against an independent reference, label the baseline
UNVERIFIED so it is never mistaken for established-correct output. Update the
baseline deliberately, with a commit message explaining why the output changed.
Perturb inputs, random seeds, data types (e.g., float32 vs float64), or batch sizes, and verify that outputs vary by a bounded amount. A result that changes dramatically under small perturbations is not trustworthy, regardless of how close it is to a reference on the nominal input.
Assert structural properties that must hold regardless of the specific input values: symmetry, monotonicity, conservation, idempotence, or range bounds. These catch whole classes of bugs that value-comparison tests miss.
Defer pytest fixtures, parametrization, numpy.testing / torch.testing
assertion mechanics, and CI configuration to the
scientific-python-development:python-testing skill. This skill is the
research-specific strategy layer: what to validate and why. Apply the
same principles to R, Julia, Fortran, or any other runtime.
ai-research-workflows:ensuring-reproducibility skill for test-data provenance (content hashes,
retrieval dates, lockfile references).The deadline temptation is to pin whatever the script prints and call it hardened:
| Thought | Reality |
|---|---|
| "The output looks plausible, I'll pin it as the baseline" | Plausible ≠ correct. Check a derivable reference/invariant first; otherwise label it UNVERIFIED. |
| "There's an analytic case but it'd take a while to derive" | That derivation is the correctness anchor. Do it before pinning, or mark the baseline UNVERIFIED. |
"float == is fine here, it's the same machine" | It won't be the same machine in CI or for the next person. Use tolerances. |
| "I'll widen the tolerance so the test passes" | Tuning the bound to the result hides the bug. Derive the bound from the numerics. |
| "It passed on the first run, so it's correct" | A test never seen to fail proves nothing. Make it go red, then green. |
== on floating-point results fails on trivially different hardware or library versions; always use absolute or relative tolerances appropriate to the domain.Before marking hardening complete:
UNVERIFIEDIntegrates with the ai-research-workflows:validating-implementations skill (confirming the
hardened code still satisfies its plan's success criteria) and the
ai-research-workflows:ensuring-reproducibility skill (provenance for reference data and pinned
baselines).
What SKILL.md sets; muted values are Claude Code's defaults
10 skills in this plugin
/creating-handoffsUse when work context must transfer to another session or person. Triggers: create a handoff, hand off this work, summarize context for the next session, prepare a handoff./ensuring-reproducibilityUse when a result, experiment, or analysis must be reproducible by others or by a future session. Triggers: make this reproducible, capture provenance, pin the environment for this result, why can't I reproduce X./implementing-plansUse when an approved implementation plan (a docs/rse/specs/plan-*.md file) exists and the next step is writing the code. Triggers: implement the plan, execute the plan, start building, run the plan./iterating-plansUse when an existing implementation plan needs changes before or during execution. Triggers: update the plan, change the plan, add a phase, revise scope, incorporate experiment results./planning-implementationsUse when a feature, refactor, or multi-file change needs to be designed before coding. Triggers: plan X, design the implementation, how should we build X, create an implementation plan./researchingUse when you need to understand how an existing codebase works and/or survey external prior work (papers, methods, tools) before planning or changing something. Traces function call paths, maps module dependencies, searches academic papers and documentation, compares library alternatives. Triggers: research the codebase, research how X works before changing it, what tools or libraries exist for X, prior art on X, has this been done before, survey approaches to X.npx claudepluginhub uw-ssec/savvy --plugin ai-research-workflowsOther plugins' skills for the same job