AGENT SKILL

notebook-to-production

Refactor analysis notebooks into production-grade code — triage what deserves productionizing, extract modules with tests, parameterize hardcoded values, pin environments for reproducibility, and schedule unattended runs with alerting. Owns general analysis/reporting notebooks; notebooks that feed model TRAINING (feature engineering + training DAGs, scheduled retraining) → ml-pipeline-design.

License 许可
MIT
最近更新
2026-11-12
Stars
★ 1
Forks
1

01 前言 Front Matter

name
notebook-to-production
description
Refactor analysis notebooks into production-grade code — triage what deserves productionizing, extract modules with tests, parameterize hardcoded values, pin environments for reproducibility, and schedule unattended runs with alerting. Owns general analysis/reporting notebooks; notebooks that feed model TRAINING (feature engineering + training DAGs, scheduled retraining) → ml-pipeline-design.
when_to_use
Triggers: productionize this notebook, notebook to script, notebook to module, refactor my notebook, parameterize notebook, papermill, schedule this analysis, reproducible analysis, notebook is a mess.

02 资源文件 1

03 SKILL.md 正文

Notebook to Production

Turn exploratory notebooks into code that runs unattended, produces the same result twice, and fails loudly. The refactor is incremental — the notebook keeps working at every step — never a from-scratch rewrite.

Workflow

1. Triage — not every notebook earns this

Productionize by re-run frequency × business impact. A notebook someone re-runs by hand every quarter is the first candidate; a one-off exploration is not — archive it reproducibly instead: the query or a data snapshot, a pinned environment (pip freeze at minimum), and a one-line header (question, finding, date, author). "Archived" without the data recipe and environment is deleted-with-extra-steps.

For a backlog of many notebooks, also: extract logic duplicated across them into a shared utility package (one fix, not N), and set a lightweight convention for future notebooks likely to graduate — imports at top, parameters in the first cell, logic in functions — so the next migration is cheap.

2. Extract logic into modules

Move transformations out of cells into importable, typed functions in a real package (src/), leaving the notebook as a thin driver that imports and calls. Separate I/O (load/save) from transformation logic — pure transformation functions are what you can test. Restartability check: does it run top-to-bottom in a fresh kernel? Hidden execution-order state is the first bug this flushes out.

3. Parameterize everything hardcoded

Dates, paths, connection strings, thresholds → function arguments driven by a config file or CLI args (or papermill parameters if the notebook itself stays the execution vehicle). The run for "last month" and the backfill for "March 2024" must be the same code with different parameters.

4. Test the transformations

The extracted pure functions get unit tests: known-input → known-output cases, plus edge cases the data will eventually throw (empty frame, nulls, duplicate keys, timezone boundaries). A small golden sample of real data as a fixture catches most regressions. No tests, no schedule — an untested unattended job is a silent-corruption machine.

5. Pin the environment

Reproducibility means the same code AND the same dependencies: a lock file (uv lock, poetry.lock, pip-compile) or a container image. Pin the data too where possible — snapshot inputs or record query + as-of timestamp, so a rerun of last month's report produces last month's numbers.

6. Schedule and operate

Size the scheduler to the team: cron or a CI schedule (GitHub Actions) first; an orchestrator (Airflow/Dagster) only when there are real DAG dependencies across jobs. Unattended means operated: fail loudly (alert on failure AND on suspicious output — empty result, row count off), log enough to debug a 6am failure, and make the job idempotent so a retry can't double-append or double-send.

Principles

  • Incremental (KISS): extract one section at a time; the notebook keeps running throughout.
  • YAGNI: no orchestrator, feature store, or microservice for a weekly report — cron + a tested module is production.
  • SRP: load, transform, and render are separate functions with separate tests.

Cross-skill boundaries

  • The notebook trains a model (feature engineering, training, evaluation, retraining schedule) → ml-pipeline-design — training pipelines have their own stage/validation/gating design.
  • Recurring ELT into a warehouse feeding many consumers → data-pipeline-design.
  • Still figuring out what the analysis should say → exploratory-data-analysis.
  • CI mechanics for the scheduled run → cicd-pipeline; test design depth → test-suite-design.

04 同仓库更多 Skills

SWEStash
SWEStash/swe-workflow-skills

writing-skills

Use when authoring, editing, or reviewing a skill in this library — a new SKILL.md, one that under-triggers, or hardening an existing one. Covers description and listing-budget rules, frontmatter, progressive disclosure, the 3-eval rule, and pressure-testing against rationalizations.

★ 1
SWEStash
SWEStash/swe-workflow-skills

working-agreement

Define and validate how a multi-session project is run — where plans, status and decisions live, session routines, new work, milestone close. README/CONTRIBUTING → project-documentation.

★ 1
SWEStash
SWEStash/swe-workflow-skills

verification-before-completion

Evidence gate before any claim that work is done, fixed, passing, or deployed. Route here when a message declares the work finished or asks to commit, push, merge, ship, or close it out, including a brief sign-off, and before git-workflow or release-management act on it. Writing the commit message or PR text itself → git-workflow.

★ 1
SWEStash
SWEStash/swe-workflow-skills

ui-ux-design

Design user experiences from an engineer's perspective — user flows, wireframes, interaction patterns, responsive strategy, navigation, loading/error/empty states. Triggers: design the UI, user flow, wireframe, how should this screen look, loading state, error state, empty state, responsive design, navigation, page layout, form design, mockup.

★ 1
SWEStash
SWEStash/swe-workflow-skills

threat-modeling

Design-time security analysis of a system or feature before it's built — trust boundaries, attack surface, STRIDE per element, abuse cases, prioritized mitigations that become security requirements. Triggers: threat model, STRIDE, trust boundary, attack surface, what could go wrong security-wise, security design review, abuse case, secure this design, security requirements. Reviewing EXISTING code/config for vulnerabilities → security-audit; use this skill while the design is still on the whiteboard.

★ 1
SWEStash
SWEStash/swe-workflow-skills

test-suite-design

Design comprehensive test suites for existing code — strategy across unit/integration/e2e, fixtures, factories, helpers. Triggers: add tests, write tests for, increase coverage, test this module, testing strategy, test plan, what tests do I need, test infrastructure, test helpers, this has no tests. Not for TDD — use tdd-workflow.

★ 1