agentleFS
HarrypatriaHarrypatria/data-mining-ml/skills/model-deployment/SKILL.md

model-deployment

Skill2 starsChanged 12 days agoMITView on GitHub

Model Deployment. Serve a trained model in production - load a pickled pipeline safely, FastAPI prediction service (predict, batch, what-if, SHAP explanations, LLM narrative), Pydantic validation from schema.json, Docker multi-stage image, docker-compose with nginx, health checks, API keys, CORS, rate limits, JSON logging, Prometheus metrics, drift monitoring (PSI, KS), batch scoring, ONNX or PMML export and air-gapped installs. Use for deploy, serve, productionize, REST API, MLOps, model serving, monitoring or containerizing a model.

4 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 0 are distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 4 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Verify the bundle: bin/data-mining-ml verify-model models/<version>.

    line 12
  2. Very specific:

    Run tests: cd api && pytest (schema validation, predict, what-if additivity, explanations, narrative with the provider mocked, grounding, …

    line 14
  3. Very specific:

    Run locally: uvicorn app.main:create_app --factory --port 8000 with MODEL_DIR=../models APP_ENV=development.

    line 15

“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Model Deployment

Scaffold: templates/ml-service/ (becomes api/ via bin/data-mining-ml init). The pickled pipeline from model-training is the model of record.

Steps

  1. Verify the bundle: bin/data-mining-ml verify-model models/<version>.
  2. Copy the scaffold, install src/<package> into the image, pin api/requirements.txt to metadata.json libraries.
  3. Run tests: cd api && pytest (schema validation, predict, what-if additivity, explanations, narrative with the provider mocked, grounding, security limits, tamper detection).
  4. Run locally: uvicorn app.main:create_app --factory --port 8000 with MODEL_DIR=../models APP_ENV=development.
  5. Build and run: docker compose up --build (API plus nginx serving the React app; nginx injects the API key).
  6. Wire monitoring: scrape /metrics; alert on feature_drift_psi above 0.2, rising input_range_violations_total, and explainer fallbacks.

Endpoints

RoutePurpose
GET /health/live, GET /health/readyLiveness; readiness means loaded and verified
GET /v1/model, GET /v1/schemaVersion, metrics with intervals, threshold, limits; predictor definitions for the UI
POST /v1/predict, POST /v1/predict/batchProbability or value, label at the stored threshold, version, request id, extrapolation flags
POST /v1/whatifBaseline versus scenario, delta, contributions for both
POST /v1/explain/local, POST /v1/explain/counterfactualsShapley contributions; smallest threshold-crossing changes
POST /v1/explain/narrativeServer-built RTCC context, LLM answer, grounding check, SSE stream

Engineering rules

  • Load once in the lifespan handler; keep it on app.state; never load inside a route.
  • Inference is blocking: plain def routes (FastAPI threadpool) or run_in_threadpool.
  • Pydantic models generated from schema.json; unknown fields rejected; categories enumerated; out-of-range numerics need allow_extrapolation and come back flagged.
  • Column order and dtypes come from the schema, enforced before predict.
  • The server recomputes everything it sends to the LLM; clients never send explanation values.
  • API key dependency, explicit CORS allowlist without credentials, body size limit, rate limit, no upload endpoint.
  • JSON logs with request id and no raw personal data; /metrics with request counts, latency, prediction distribution, range violations and PSI drift.
  • Docker: multi-stage, slim base, pinned requirements, non-root user, no --reload, HEALTHCHECK, model directory mounted read-only. Each worker holds its own model copy; size workers to memory.
  • Air-gapped: vendored wheels (pip download then --no-index --find-links), LLM_PROVIDER=none makes no external calls and uses template explanations.

Details, batch scoring, ONNX and PMML, Java and .NET: references/fastapi-serving.md.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.