PeaBox Lab › PeaLang › Learn › Chapter 21 › Lesson 1

Part IV — Expert Production Engineering · Chapter 21 · Lesson 1 of 6 · 4 min read

Lesson 1: Portable Pipeline Loading and Serving Commands

Lesson level: Expert

Purpose: Start a prediction service that loads a verified pipeline from a bundle, exposes a stable request and response contract, and behaves identically on a laptop, a test server, and production.

Learning objectives

By the end of this lesson you will be able to:

1.1 Anatomy of a prediction service

Keep the model layer free of transport details. The same scoring function should be callable from the HTTP handler, a batch job, and a test, which is exactly the separation of host and logic that Chapter 15 recommended for embedding.

1.2 Portable loading

Portable loading separates immutable pipeline data from environment-specific configuration. In RC2, pealang.mlops_portable.load_pipeline(path) reads a local JSON pipeline and returns (pipeline, metadata); it checks the format and reconstructs supported transformers and model classes. A registry, trusted-signature policy, secret provider, and schema admission are host responsibilities layered around this loader. An approved local path is valid; accepting arbitrary caller-supplied paths is not.

Verified RC2 command forms. These examples assume an approved pipeline.json already exists. The local serving example is for isolated smoke tests only; production requires authenticated hosting and the controls in later lessons.

pea-serve deploy-check deployment.json pipeline.json
pea-serve execute deployment.json
pea-serve serve pipeline.json --version 1 --host 127.0.0.1 --port 8000

The deploy-check command validates required top-level manifest fields and pipeline loadability. execute returns the checked manifest and resolved pipeline path; it does not submit resources to Kubernetes or start a server. serve starts the FastAPI application through the optional uvicorn dependency. The CLI accepts --api-key, but avoid exposing production secrets in shell history or process arguments; use an approved host configuration path instead.

1.3 Supported Pipeline Format and Model Boundary

The format marker is pealang.pipeline.v1. save_pipeline persists feature names, target, fitted transformers, model parameters, and metadata. The loader reconstructs StandardScaler or MinMaxScaler and LinearRegression, LogisticRegression, RidgeRegression, or LassoRegression. This is not arbitrary Python-object deserialization. Unsupported transformer records fail; unknown model classes do not become executable plugins. Verify your Chapter 19 pipeline is actually representable before promising portability.

from pealang.mlops_portable import load_pipeline
pipeline, metadata = load_pipeline("pipeline.json")

Annotation: This is Python host code, not .pea syntax. Inspect metadata and validate a known fixture before admitting the pipeline. load_pipeline alone is not trusted-signature verification or complete schema governance.

1.4 Request and Response Contracts

The shipped /predict route accepts a JSON list of record maps, not an envelope with a records property. Required feature fields must match the fitted pipeline. A successful response contains model_version, predictions, and latency_ms. x-api-key and Authorization carry configured authentication; x-routing-key supplies the base runtime routing key. Add application contract versions, safe error bodies, and correlation policies in the host without pretending they are existing response fields.

[{"tenure_months": 12, "monthly_charge": 40}]

Annotation: This illustrative request is valid only for a pipeline trained on those exact features and compatible numeric values. The response values depend on the fitted model; no prediction is asserted here.

1.5 Guided Practice and Common Mistakes

Compare a direct load with the serving path using the same fixture. Explain which layer verifies authenticity and which checks representability. Common mistakes are passing a bundle directory where pipeline JSON is expected, treating execute as a deployment engine, exposing an unauthenticated listener, or assuming CLI serving automatically enables ResilientRuntime.

1.6 Hands-On Lab: Prove Portable Loading

Deliverable: Artifact identity, dependency record, request fixtures, observed responses, and a table separating built-in checks from host controls. Passing means valid fixtures agree, invalid artifacts fail before admission, and no secret appears in evidence.

1.7 Review Questions and Applied Challenge

Which objects does load_pipeline reconstruct? Why is an approved local path different from an arbitrary request path? What does execute actually return? Which controls are absent from a plain serve command?

Applied challenge: Wrap pipeline loading with an approved artifact allowlist, explicit signature verification, and a schema smoke test. Demonstrate that a failed replacement never changes the active pipeline. Keep the wrapper clearly labelled as host application code.

Lesson Summary

Portable serving requires a supported pipeline representation, a reproducible environment, and an explicit host admission policy. The CLI provides local validation and serving, not an automatic secure production deployment. Request contracts and operational controls must match the actual selected runtime.

Lesson status: Draft complete; ready for review. Examples checked against the attached source, not executed in this review.

← Previous Next →