Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Canonical lock bytes are LF-only; any CRLF checkout would make them invalid.
playground/src/runtime/pylock.toml text eol=lf
16 changes: 10 additions & 6 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ inferred schema and model structure in one compressed `.mlbundle` file.

It owns export, metadata-only inspection and validated loading. It is the
training-side companion to MLSuite, whose runtime accepts `.mlbundle` uploads.
MLSuite does not train models. The package version is 0.2.1; format 1 is not frozen.
MLSuite does not train models. The package version is 0.3.0; format 1 is not frozen.
Implementation claims require code and test proof.

## What must remain true
Expand Down Expand Up @@ -36,7 +36,9 @@ Names, categories, learned models and structure can still reveal training inform
Support scikit-learn through skops, XGBoost through in-memory UBJSON, CatBoost
through CBM and existing ONNX bytes unchanged. Do not convert models.
Adapters import their libraries lazily; model dependencies belong in optional
`sklearn`, `xgboost`, `catboost` and `onnx` extras.
`sklearn`, `xgboost`, `catboost` and `onnx` extras. Every bundle's `pylock.toml`
locks those runtimes for Linux and Windows through uv (`lock` extra); it is a claim that
mlbundle validates and never installs. Runtimes own installation policy.

### 5. Inspection and verification mean different things

Expand Down Expand Up @@ -81,7 +83,7 @@ dead stubs and undocumented fallback behavior.
- Tests for a feature keep successful round trips and rejection cases together in one file.
- Verification claims describe commands actually run and their real results.
- `C:\software\mlsuite`, `C:\software\mlschema`, `C:\software\mlform` and `C:\software\eshkra` are read-only references. Never modify, commit or run write commands in them.
- sklearn-to-ONNX conversion, per-model environments, bundle signing and additional model libraries (including LightGBM and PyTorch) are outside scope.
- sklearn-to-ONNX conversion, provisioning per-model environments (bundles only describe them), bundle signing and additional model libraries (including LightGBM and PyTorch) are outside scope.

## Reader security

Expand All @@ -107,14 +109,15 @@ changing skops trust, fitted state or supported types.
1. A closed adapter recognizes the model and prepares it without mutating the user's object.
2. Shared extraction derives model claims and structure from native state.
3. Native serialization and reload prove those claims before export publishes the bundle.
4. Local mlschema inference supplies fields/reports; shared code resolves features, targets and environment.
4. Local mlschema inference supplies fields/reports; shared code resolves features, targets, environment and the runtime lock.
5. The writer computes integrity records, validates through the reader and writes a deterministic ZIP.
6. Inspect validates bounded container/JSON data and declarations without adapter resolution.
6. Inspect validates bounded container/JSON/lock data and declarations without adapter resolution.
7. Load uses the closed adapter and compares recomputed claims and structure.
8. The predictor and record APIs expose validated inputs and output-major report results.

The allowed members are manifest, required schema, one native member (or a declared
skops + UBJSON/CBM pair), extractable structure and explicit samples: at most six.
skops + UBJSON/CBM pair), extractable structure, explicit samples and the required
lock: at most seven.
Publication uses atomic hard links or replacement and requires explicit overwrite.
The exclusive-create fallback removes partial destinations on failure but exposes
the file during copying. Preserve that behavior and document its limits honestly.
Expand All @@ -126,6 +129,7 @@ Use the entry points and linked contracts to find the owning implementation:
- **Public I/O:** `model_io.py`, `inspection.py`, `results.py` and `cli.py`; `__init__.py` owns public exports.
- **Container:** `container.py`, `writing.py`, `_container_rules.py`, `_zip_directory.py`, `_zip_members.py`, `limits.py` and `integrity.py`.
- **Declarations:** `manifest.py`, `canonical.py`, `declarations.py`, `environment.py`, `training.py`, `schema.py` and `samples.py`.
- **Runtime lock:** `lock.py`, `_lock_toml.py`, `_wheel_tags.py`, `_lock_generation.py` and `_environment_check.py`; read `docs/format-environment.md` before changing them.
- **Adapters:** `adapters.py` and `registry.py` define closed lazy resolution; `_sklearn/`, `_xgboost/`, `_catboost/`, `_onnx/` and `_composite/` own native behavior.
- **Claims and predictions:** `claims.py`, `records.py`, `_prediction_input.py`, `_prediction_decisions.py` and `_display.py`.
- **Websites:** `landing/`, `docs/` and `playground/`; `brand/` owns the shared identity sourced from eshkra.
Expand Down
42 changes: 30 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
<a href="https://mlbundle.eshkra.dev"><img src="https://img.shields.io/badge/website-303039?style=flat&amp;logo=astro&amp;logoColor=ff6a1a" alt="Website" /></a>
<a href="https://docs.mlbundle.eshkra.dev"><img src="https://img.shields.io/badge/docs-303039?style=flat&amp;logo=readthedocs&amp;logoColor=ff6a1a" alt="Documentation" /></a>
<a href="https://playground.mlbundle.eshkra.dev"><img src="https://img.shields.io/badge/playground-303039?style=flat&amp;logo=stackblitz&amp;logoColor=ff6a1a" alt="Playground" /></a>
<a href="https://pypi.org/project/mlbundle/"><img src="https://img.shields.io/badge/version-0.2.1-b73d00?style=flat&amp;logo=pypi&amp;logoColor=white&amp;labelColor=303039" alt="Version 0.2.1" /></a>
<a href="https://pypi.org/project/mlbundle/"><img src="https://img.shields.io/badge/version-0.3.0-b73d00?style=flat&amp;logo=pypi&amp;logoColor=white&amp;labelColor=303039" alt="Version 0.3.0" /></a>
<a href="https://github.com/UlloaSP/mlbundle"><img src="https://img.shields.io/badge/source-303039?style=flat&amp;logo=github&amp;logoColor=white" alt="Source on GitHub" /></a>
<a href="https://github.com/UlloaSP/mlbundle/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/UlloaSP/mlbundle/ci.yml?branch=main&amp;style=flat&amp;label=CI&amp;labelColor=303039" alt="CI status" /></a>
<a href="https://github.com/UlloaSP/mlbundle/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-b73d00?style=flat&amp;labelColor=303039" alt="MIT license" /></a>
<a href="https://eshkra.dev"><img src="https://img.shields.io/badge/part_of-eshkra-b73d00?style=flat&amp;labelColor=303039" alt="Part of eshkra" /></a>
</p>

MLbundle packages a trained model with its manifest, locally inferred input schema
and extractable structure in one compressed `.mlbundle` file. The same library
MLbundle packages a trained model with its manifest, locally inferred input schema,
extractable structure and a lock of its runtime environment in one compressed
`.mlbundle` file. The same library
writes the bundle and validates it when loaded, preserving feature order, class
labels and output meaning across the training/runtime boundary.

Expand All @@ -39,24 +40,27 @@ model they are supposed to describe.
MLbundle keeps them together and checks model-derived claims against the loaded
model. Schema inference runs locally through [MLschema](https://github.com/UlloaSP/mlschema);
real training rows are included only when explicitly requested. Native formats
preserve the supported model without conversion.
preserve the supported model without conversion, and a PEP 751 `pylock.toml`
pins the exact wheels a Linux or Windows runtime needs to serve it.

## Installation

MLbundle **0.2.1** requires Python **3.14** for export with the schema extra.
MLbundle **0.3.0** requires Python **3.14** for export with the schema extra.
The installation command for this release is:

```bash
python -m pip install "mlbundle[sklearn,schema]==0.2.1"
python -m pip install "mlbundle[sklearn,schema,lock]==0.3.0"
```

To use a local checkout, run `python -m pip install -e ".[sklearn,schema]"`
To use a local checkout, run `python -m pip install -e ".[sklearn,schema,lock]"`
from its root. The base library requires Python >=3.14; schema inference uses
mlschema `>=0.3.0,<0.4` on Python 3.14 only.

Choose `xgboost`, `catboost` or `onnx` instead of `sklearn`, or install `[all]`.
Export always needs `schema`. Metadata-only inspection needs only the base
package; load and CLI verification need the matching model extra.
Export always needs `schema`; `lock` provides uv, which resolves the runtime lock
through your package index unless you pass `environment_lock=`. Metadata-only
inspection needs only the base package; load and CLI verification need the
matching model extra.

## Quick start

Expand Down Expand Up @@ -116,6 +120,7 @@ accept paths, bytes or streams. The native model remains available as
| `bundle.predict(data)` | Regressor predictions as plain lists. |
| `bundle.predict_record(record)` | Map one record through the schema and return frozen output-major results. |
| `bundle.row_from_record(record)` | Validate and order record values for native inference or explanations. |
| `check_environment(view)` | In the serving process, require exactly the bundle's lock plus mlbundle. |

The CLI exposes metadata inspection and full verification:

Expand All @@ -129,6 +134,18 @@ Inspection does not prove that metadata describes the model. Full verification
loads the model and compares its claims. Neither operation establishes authorship
or training history.

## Runtime environment

Export locks the installed versions of pydantic, the model libraries and their
dependencies as `pylock.toml` for CPython with the GIL on Linux `x86_64` and
`aarch64` and on Windows `amd64`. mlbundle itself is pinned by the manifest's
`writer_version`.
A runtime installs that lock plus `mlbundle==writer_version` in an isolated
environment, for example `uv pip install -r pylock.toml`, and calls
`check_environment` before loading. Installing a lock runs its packages' code:
the runtime decides which packages and indexes it trusts. See
[the lock contract](https://docs.mlbundle.eshkra.dev/format/environment/).

## Supported models

| Library | Storage | Support boundary |
Expand All @@ -147,7 +164,7 @@ structure, and all-sklearn Pipeline structure is null. The
## Some notes

Package versions and wire-format versions are independent. Format 1 is not frozen;
incompatible schema shapes require re-export. The security design has not had an
incompatible schema shapes and bundles without `pylock.toml` require re-export. The security design has not had an
independent review; do not accept bundles from untrusted parties.

The reader bounds ZIP/JSON data, verifies integrity and uses closed native loaders.
Expand All @@ -156,8 +173,8 @@ still need process isolation and application-owned resource limits.
Read [SECURITY.md](https://docs.mlbundle.eshkra.dev/security/) for guarantees, limits and private reporting.

Training rows stay local by default, but feature names, categories, labels and
learned structure can reveal information. Schemas and environment records remain
author declarations. Model training, hosting, signing and conversion are outside
learned structure can reveal information. Schemas, environment records and locks
remain author declarations. Model training, hosting, signing and conversion are outside
the library's scope.

## Documentation
Expand All @@ -171,6 +188,7 @@ repository unchanged:
- [Supported adapters and structure](https://docs.mlbundle.eshkra.dev/format/adapters/)
- [Sklearn state and trusted types](https://docs.mlbundle.eshkra.dev/format/state/)
- [Composite pipelines](https://docs.mlbundle.eshkra.dev/format/pipeline/)
- [Runtime environment lock](https://docs.mlbundle.eshkra.dev/format/environment/)
- [ONNX layouts and bounds](https://docs.mlbundle.eshkra.dev/format/onnx/)

The [playground](https://playground.mlbundle.eshkra.dev) provides editable examples and inspection of the
Expand Down
81 changes: 43 additions & 38 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Security policy

MLbundle 0.2.1 has not had an independent security review;
do not accept bundles from untrusted parties. Format version 1 is not frozen.
It implements strict manifest validation, secure container reading/writing, metadata-only
`inspect`, export/load, sklearn, XGBoost, CatBoost and ONNX adapters, local schema inference,
explicit samples, prediction-state verification and the inspect/verify CLI.
The container validates ZIP/ZIP64 layout, bounds sources and actual decompression,
checks CRC and member integrity, and rejects unsafe members and polyglot wrappers.
The writer publishes complete validated files atomically where hard links work;
the exclusive-creation fallback cleans up on failure but exposes the destination
while copying and cannot guarantee crash-atomic publication. The version 1 contract
is defined in [docs/format.md](docs/format.md).
MLbundle 0.3.0 has not had an independent security review; do not accept bundles
from untrusted parties. Format version 1 is not frozen. It implements strict
manifest validation, secure container reading/writing, metadata-only `inspect`,
export/load, sklearn, XGBoost, CatBoost and ONNX adapters, local schema inference,
explicit samples, prediction-state verification, the runtime environment lock and
the inspect/verify CLI. The container validates ZIP/ZIP64 layout, bounds sources and
actual decompression, checks CRC and member integrity, and rejects unsafe members
and polyglot wrappers. The writer publishes complete validated files atomically
where hard links work; the exclusive-creation fallback cleans up on failure but
exposes the destination while copying and cannot guarantee crash-atomic publication.
The version 1 contract is defined in [docs/format.md](docs/format.md).

## Threat model

Expand Down Expand Up @@ -44,7 +44,8 @@ make a received file trustworthy.
outside the contiguous ZIP layout. ZIP64 and validated streaming descriptors
are accepted within the same resource ceilings.
- Verify each member's SHA-256 against the manifest and validate member sizes.
- Validate the manifest strictly and reject unknown format versions.
- Validate the manifest and canonical `pylock.toml` strictly, reject unknown format
versions and never install, import or execute anything a lock names.
- Provide a metadata-only `inspect` operation that does not deserialize a model.
It must not present model-derived claims as verified against the model.
- Treat every model-derived value as a claim. Recompute it from the loaded model
Expand Down Expand Up @@ -108,10 +109,9 @@ wrapper split transformer skops bytes from UBJSON/CBM, retaining each adapter's
preflight, trust, state/claims and structure checks; no booster type enters skops.
Closed fitted-state width proofs never use data. Shared bounded names/parameters/
commitments and inner tree coordinates are recomputed before closed Pipeline
reconstruction is returned. Cache/metadata routing/unknown outer state fail;
step names and outer options are declarations, not authenticated training history.
See [the composite contract](docs/format-pipeline.md).
HistGradientBoosting's separate
reconstruction is returned. Cache/metadata routing/unknown outer state fail; step
names and outer options are declarations, not authenticated training history. See
[the composite contract](docs/format-pipeline.md). HistGradientBoosting's separate
`TreePredictor` storage is also excluded. Broadening the supplemental list requires
source review and hostile-payload tests, never author approval or bundle metadata.

Expand Down Expand Up @@ -141,20 +141,19 @@ native tree/routing/category/dropout state alongside dumps/importances.
Label agreement proves consistency with the native file, not the historical
truth of a user-supplied label mapping.

The adapter rejects oversized bytes and non-UBJSON before XGBoost sees them.
A bounded Python preflight checks document layout, feature/class/target counts,
tree counts, node arrays, output groups, iteration pointers, indices, reachability
and dump-compatible depth, keeping
numeric arrays as byte views. Native errors are translated to bounded mlbundle
errors without third-party exception text. These checks reduce cheap malformed
inputs; they are not a complete validation of XGBoost's internal model schema.
XGBoost's native parser and native inference remain a dependency boundary:
mlbundle cannot guarantee their memory safety or bound their internal memory/CPU
use. Native tree dump generation also allocates inside XGBoost before mlbundle
can inspect its returned byte size. Server consumers must isolate loading and
prediction and enforce process resource limits. All predictors reject invalid inputs and wrap remaining native failures
without echoing data cells. See the exact support and
resource boundaries in [docs/format.md](docs/format.md).
The adapter rejects oversized bytes and non-UBJSON before XGBoost sees them. A
bounded Python preflight checks document layout, feature/class/target counts, tree
counts, node arrays, output groups, iteration pointers, indices, reachability and
dump-compatible depth, keeping numeric arrays as byte views. Native errors are
translated to bounded mlbundle errors without third-party exception text. These
checks reduce cheap malformed inputs; they are not a complete validation of
XGBoost's internal model schema. XGBoost's native parser and native inference remain
a dependency boundary: mlbundle cannot guarantee their memory safety or bound their
internal memory/CPU use. Native tree dump generation also allocates inside XGBoost
before mlbundle can inspect its returned byte size. Server consumers must isolate
loading and prediction and enforce process resource limits. All predictors reject
invalid inputs and wrap remaining native failures without echoing data cells. See
the exact support and resource boundaries in [docs/format.md](docs/format.md).

## Implemented CatBoost dependency boundary

Expand Down Expand Up @@ -231,19 +230,25 @@ boundary: importing mlbundle or inspecting any bundle imports no model library.
The native result contains the exact bytes and CPU session needed for inference;
mutating a session invalidates its verified relationship with metadata.

## Runtime environment lock

`pylock.toml` is an author claim that mlbundle validates and never installs.
Installing it executes the named packages' code: runtimes own the allowlist over
the whole locked set, trusted indexes, isolated builds and networkless loading
after `check_environment`, as described in [the lock contract](docs/format-environment.md#consumers).

## Limits of these guarantees

SHA-256 hashes detect corruption, not deliberate tampering: an attacker can
replace a member and update its hash in the manifest. They do not prove who
trained the model or authenticate its provenance. Bundle signing is out of
scope. Training-environment records and free-form user metadata are assertions
by the author; checking model-derived claims does not authenticate those records.

Validation does not prove model quality, fairness, training history or the
truth of user metadata. Pickle-free formats do not sandbox model execution or
eliminate vulnerabilities in native parsers and dependencies. A consuming
runtime still owns authentication, authorization, process isolation and
execution resource limits.
scope. Training-environment records, the runtime lock and free-form user metadata
are assertions by the author; checking model-derived claims does not authenticate those records.

Validation does not prove model quality, fairness, training history or the truth of
user metadata. Pickle-free formats do not sandbox model execution or eliminate
vulnerabilities in native parsers and dependencies. A consuming runtime still owns
authentication, authorization, process isolation and execution resource limits.

Training frames are never serialized. Schema inference runs locally and includes
column names, dtype strings, inferred kinds, nullability, categorical values
Expand Down
Loading
Loading