Skip to content

Typed inputs, straight from your data.

MLschema reads a pandas DataFrame and returns a validated, JSON-serialisable list of fields. Each field carries a kind, a label, nullability and the backend target the model expects.
schema.py
import pandas as pd
from mlschema import infer_schema
df = pd.DataFrame(
{
"score": [98.5, 86.0, 91.0],
"role": pd.Categorical(["engineer", "engineer", "scientist"]),
"active": [True, False, True],
}
)
fields = infer_schema(df)
fields
[
{ "label": "score", "required": true, "mappedTo": "score", "kind": "number", "step": 0.1 },
{
"label": "role",
"required": true,
"mappedTo": "role",
"kind": "category",
"options": ["engineer", "scientist"]
},
{ "label": "active", "required": true, "mappedTo": "active", "kind": "boolean" }
]

Every field is checked against a strict Pydantic model before it is returned. Constraints that contradict each other, unknown attributes and unknown kinds fail during inference instead of reaching your interface.

MLschema is open source under the MIT license and part of eshkra. Install it from PyPI, try it in the playground, or read the source on GitHub.