%pip install -q validmindRun documentation tests with custom configurations
When running documentation tests, you can configure inputs and parameters for individual tests by passing a config as a parameter.
As a model developer, configuring individual tests is useful in various models development scenarios. For instance, based on a use case, a model might require changing inputs and/or parameters for certain tests. The run_documentation_tests() function allows you to directly configure tests through config, thus giving you flexibility to run tests according to your use case.
This interactive notebook includes the code required to load the demo dataset, preprocess the raw dataset, train a model for testing, initialize ValidMind objects, and run documentation tests with custom configurations.
About ValidMind
ValidMind is a suite of tools for managing risk, including risk associated with AI and statistical models.
You use the ValidMind Library to automate documentation and validation tests, and then use the ValidMind Platform to collaborate on documentation. Together, these products simplify risk management, facilitate compliance with regulations and institutional standards, and enhance collaboration between yourself and validators.
Before you begin
This notebook assumes you have basic familiarity with Python, including an understanding of how functions work. If you are new to Python, you can still run the notebook but we recommend further familiarizing yourself with the language.
If you encounter errors due to missing modules in your Python environment, install the modules with pip install, and then re-run the notebook. For more help, refer to Installing Python Modules.
New to ValidMind?
If you haven't already seen our documentation on the ValidMind Library, we recommend you begin by exploring the available resources in this section. There, you can learn more about documenting records such as models and running tests, as well as find code samples and our Python Library API reference.
Register with ValidMind
Key concepts
record: A tool tracked in the ValidMind inventory, such as a model. Records include traditional statistical models, legacy systems, artificial intelligence/machine learning models, large language models (LLMs), agentic AI systems, and other documentable items that benefit from oversight, testing, and lifecycle management.
model: SR 26-2 (which supersedes SR 11-7) defines a model as a "complex quantitative method, system, or approach that applies statistical, economic, or financial theories to process input data into quantitative estimates." Simple arithmetic, deterministic rule-based processes, or software without statistical, economic, or financial theories underpinning their design or use are generally outside SR 26-2’s definition of a model. Within ValidMind, a model is a type of record tracked in the inventory.
documentation, model documentation: A structured and detailed document pertaining to a record, encompassing key components such as its underlying assumptions, methodologies, data sources, inputs, performance metrics, evaluations, limitations, and intended uses. Within the realm of risk management, this documentation serves to ensure transparency, adherence to regulatory requirements, and a clear understanding of potential risks associated with the record's application.
document template: Lays out the structure of documents, segmented into various sections and sub-sections, and functions as a test suite specifying the tests that should be run, and how the results should be displayed. Document templates help automate your development, validation, monitoring, and other risk management processes. Document templates are available for default ValidMind document types as well as custom document types.
documentation template: A default ValidMind document type that serves as a standardized framework for developing and documenting records, including sections designated for record details, data descriptions, test results, and performance metrics. By outlining required documentation and recommended analyses, document templates ensure consistency and completeness across documentation and help guide developers through a systematic development process while promoting comparability and traceability of development outcomes.
test: A function contained in the ValidMind Library, designed to run a specific quantitative test on the dataset or record. Test results are logged to the ValidMind Platform, where they are attached to documents. Tests are the building blocks of ValidMind, used to evaluate and document records and datasets, and can be run individually or as part of a suite defined by your templates.
test suite: A collection of tests designed to run together to automate and generate documentation end-to-end for specific use cases. (Learn more: test_suites)
metric: A subset of tests that do not have thresholds. In the context of this notebook, metrics and tests can be thought of as interchangeable concepts.
custom test: Functions that you define to evaluate your record or dataset. These functions can be registered with the ValidMind Library to be used in the ValidMind Platform.
inputs: Objects to be evaluated and documented in the ValidMind Library. They can be any of the following:
- model: A single record that has been initialized in ValidMind with
init_model(). Despite the naming convention, model objects can be any type of record you want to test, document, validate, or monitor with ValidMind. - dataset: A single dataset that has been initialized in ValidMind with
init_dataset(). - models: A list of ValidMind records - usually this is used when you want to compare multiple records in your custom tests.
- datasets: A list of ValidMind datasets - usually this is used when you want to compare multiple datasets in your custom tests. (Learn more: Run tests with multiple datasets)
parameters: Additional arguments that can be passed when running a ValidMind test, used to pass additional information to a test, customize its behavior, or provide additional context.
outputs: Custom tests can return elements like tables or plots. Tables may be a list of dictionaries (each representing a row) or a pandas DataFrame. Plots may be matplotlib or plotly figures.
Setting up
Install the ValidMind Library
To install the library:
Initialize the ValidMind Library
Register sample model
Let's first register a sample record (model) for use with this notebook:
In a browser, log in to ValidMind.
In the left sidebar, select Inventory.
Under the RECORD TYPE drop-down, select
Modeland click + Register Model. (Learn more: Register records in the inventory)Enter the model details and click Next > to continue to assignment of inventory record stakeholders.
Select your own name under the RECORD OWNER drop-down.
Click Register Model to add the model to your inventory.
Apply documentation template
Once you've registered your model, let's select a documentation template. A template predefines sections for your documentation and provides a general outline to follow, making the documentation process much easier.
In the left sidebar that appears for your model, click Documents and select Development.
If you cannot locate your Development document, make sure Development type documents are enabled for model records and create a new document. (Learn more: Manage documents)
Under TEMPLATE, select
Binary classification.Click Use Template to apply the template.
Get your code snippet
Initialize the ValidMind Library with the code snippet unique to each record per document, ensuring your test results are uploaded to the correct record and automatically populated in the right document in the ValidMind Platform when you run the Library.
On the left sidebar that appears for your model, select Getting Started and select
Developmentfrom the DOCUMENT drop-down menu.Click Copy snippet to clipboard.
Next, load your model identifier credentials from an
.envfile or replace the placeholder with your own code snippet:
# Load your model identifier credentials from an `.env` file
%load_ext dotenv
%dotenv .env
# Or replace with your code snippet
import validmind as vm
vm.init(
# api_host="...",
# api_key="...",
# api_secret="...",
# model="...",
document="documentation",
)Preview the documentation template
Let's verify that you have connected the ValidMind Library to the ValidMind Platform and that the appropriate template is selected for your model.
You will upload documentation and test results unique to your model based on this template later on. For now, take a look at the default structure that the template provides with the vm.preview_template() function from the ValidMind library and note the empty sections:
vm.preview_template()Load the sample dataset
The sample dataset used here is provided by the ValidMind library. To be able to use it, you need to import the dataset and load it into a pandas DataFrame, a two-dimensional tabular data structure that makes use of rows and columns:
# Import the sample dataset from the library
from validmind.datasets.classification import customer_churn as demo_dataset
print(
f"Loaded demo dataset with: \n\n\t• Target column: '{demo_dataset.target_column}' \n\t• Class labels: {demo_dataset.class_labels}"
)
raw_df = demo_dataset.load_data()
raw_df.head()Document the model
As part of documenting the model with the ValidMind Library, you need to preprocess the raw dataset, initialize some training and test datasets, initialize a model object you can use for testing, and then run the full suite of tests.
Prepocess the raw dataset
Preprocessing performs a number of operations to get ready for the subsequent steps:
- Preprocess the data: Splits the DataFrame (
df) into multiple datasets (train_df,validation_df, andtest_df) usingdemo_dataset.preprocessto simplify preprocessing. - Separate features and targets: Drops the target column to create feature sets (
x_train,x_val) and target sets (y_train,y_val). - Initialize XGBoost classifier: Creates an
XGBClassifierobject with early stopping rounds set to 10. - Set evaluation metrics: Specifies metrics for model evaluation as "error," "logloss," and "auc."
- Fit the model: Trains the model on
x_trainandy_trainusing the validation set(x_val, y_val). Verbose output is disabled.
train_df, validation_df, test_df = demo_dataset.preprocess(raw_df)Train a model for testing
We train a simple customer churn model for our test.
import xgboost
%matplotlib inline
x_train = train_df.drop(demo_dataset.target_column, axis=1)
y_train = train_df[demo_dataset.target_column]
x_val = validation_df.drop(demo_dataset.target_column, axis=1)
y_val = validation_df[demo_dataset.target_column]
xgb = xgboost.XGBClassifier(early_stopping_rounds=10)
xgb.set_params(
eval_metric=["error", "logloss", "auc"],
)
xgb.fit(
x_train,
y_train,
eval_set=[(x_val, y_val)],
verbose=False,
)Initialize ValidMind objects
Initialize the ValidMind model
Before you run tests, you'll need to initialize a ValidMind model object (vm_model) that can be passed to other functions for analysis and tests on the data for our model.
- Despite the naming convention, ValidMind model objects can be any type of record you want to test, document, validate, or monitor with the ValidMind Library.
- From classical statistical and machine learning models, to generative and agentic AI systems and more, the ValidMind model object provides a consistent wrapper around your record so it can be passed as a unified input to any ValidMind test or test suite, with results sent directly to the ValidMind Platform.
Initialize your model object with vm.init_model():
# FUNCTION ARGUMENTS:
# model - the model that you want to provide as input to tests
# input_id - a unique identifier that allows tracking what inputs are used when running each individual test
vm_model_xgb = vm.init_model(
xgb,
input_id="xgb",
)Initialize the ValidMind datasets
Similarly, initialize a ValidMind dataset object using the init_dataset function from the ValidMind (vm) module.
This function takes a number of arguments:
dataset— the raw dataset that you want to provide as input to testsinput_id- a unique identifier that allows tracking what inputs are used when running each individual testtarget_column— a required argument if tests require access to true values. This is the name of the target column in the datasetclass_labels— an optional value to map predicted classes to class labels
With all datasets ready, you can now initialize the raw, training and test datasets (raw_df, train_df and test_df) created earlier into their own dataset objects using vm.init_dataset():
vm_raw_ds = vm.init_dataset(
input_id="raw_dataset",
dataset=raw_df,
target_column=demo_dataset.target_column,
)
feature_columns = [
"CreditScore",
"Gender",
"Age",
"Tenure",
"Balance",
"NumOfProducts",
"HasCrCard",
"IsActiveMember",
"EstimatedSalary",
"Geography_France",
"Geography_Germany",
"Geography_Spain",
]
vm_train_ds = vm.init_dataset(
input_id="train_dataset",
dataset=train_df,
target_column=demo_dataset.target_column,
feature_columns=feature_columns,
)
vm_test_ds = vm.init_dataset(
input_id="test_dataset",
dataset=test_df,
target_column=demo_dataset.target_column,
feature_columns=feature_columns,
)Run predictions through assign_predictions interface
We can use assign_predictions() to run and assign model predictions to our training and test datasets:
vm_train_ds.assign_predictions(model=vm_model_xgb)
vm_test_ds.assign_predictions(model=vm_model_xgb)Run documentation tests
Preview config
You can preview the default config for the documentation template using the vm.get_test_suite().get_default_config() interface.
import json
model_test_suite = vm.get_test_suite()
config = model_test_suite.get_default_config()
print("Suite Config: \n", json.dumps(config, indent=2))Updating config
The test configuration can be updated to fit with your use case and requirements
config = {
"validmind.data_validation.DatasetSplit": {
"inputs": {"datasets": (vm_train_ds, vm_test_ds)},
},
"validmind.model_validation.sklearn.PopulationStabilityIndex": {
"inputs": {"model": vm_model_xgb, "datasets": (vm_train_ds, vm_test_ds)},
},
"validmind.model_validation.sklearn.ConfusionMatrix": {
"inputs": {"model": vm_model_xgb, "dataset": vm_test_ds},
},
"validmind.model_validation.sklearn.ClassifierPerformance:in_sample": {
"inputs": {"model": vm_model_xgb, "dataset": vm_train_ds},
},
"validmind.model_validation.sklearn.ClassifierPerformance:out_of_sample": {
"inputs": {"model": vm_model_xgb, "dataset": vm_test_ds},
},
"validmind.model_validation.sklearn.PrecisionRecallCurve": {
"inputs": {"model": vm_model_xgb, "dataset": vm_test_ds},
},
"validmind.model_validation.sklearn.ROCCurve": {
"inputs": {"model": vm_model_xgb, "dataset": vm_test_ds},
},
"validmind.model_validation.sklearn.TrainingTestDegradation": {
"inputs": {"model": vm_model_xgb, "datasets": (vm_train_ds, vm_test_ds)},
},
"validmind.model_validation.sklearn.MinimumAccuracy": {
"inputs": {"model": vm_model_xgb, "dataset": vm_test_ds},
},
"validmind.model_validation.sklearn.MinimumF1Score": {
"inputs": {"model": vm_model_xgb, "dataset": vm_test_ds},
},
"validmind.model_validation.sklearn.MinimumROCAUCScore": {
"inputs": {"model": vm_model_xgb, "dataset": vm_test_ds},
},
"validmind.model_validation.sklearn.PermutationFeatureImportance": {
"inputs": {"model": vm_model_xgb, "dataset": vm_test_ds},
},
"validmind.model_validation.sklearn.SHAPGlobalImportance": {
"inputs": {"model": vm_model_xgb, "dataset": vm_test_ds},
},
"validmind.model_validation.sklearn.WeakspotsDiagnosis": {
"inputs": {"model": vm_model_xgb, "datasets": (vm_train_ds, vm_test_ds)},
},
"validmind.model_validation.sklearn.OverfitDiagnosis": {
"inputs": {"model": vm_model_xgb, "datasets": (vm_train_ds, vm_test_ds)},
},
"validmind.model_validation.sklearn.RobustnessDiagnosis": {
"inputs": {"model": vm_model_xgb, "datasets": (vm_train_ds, vm_test_ds)},
},
}Run documentation tests
You can now run all documentation tests and pass an extra config parameter that overrides input and parameter configuration for the tests specified in the object.
full_suite = vm.run_documentation_tests(
inputs={
"dataset": vm_raw_ds,
"model": vm_model_xgb,
},
config=config,
)Next steps
You can look at the results of this test suite right in the notebook where you ran the code, as you would expect. But there is a better way — use the ValidMind Platform to work with your model documentation.
Work with your documentation
From the Inventory in the ValidMind Platform, go to the model you registered earlier. (Learn more: Working with the inventory)
In the left sidebar that appears for your model, click Development under Documents.
What you see is the full draft of your documentation in a more easily consumable version. From here, you can make qualitative edits to documentation, view guidelines, collaborate with validators, and submit your documentation for approval when it's ready. (Learn more: Working with documentation)
Discover more learning resources
We also offer many interactive notebooks to help you use the ValidMind Library to streamline your work:
Or, visit our documentation to learn more about ValidMind.
Upgrade ValidMind
Retrieve the information for the currently installed version of ValidMind:
%pip show validmindIf the version returned is lower than the version indicated in our production open-source code, restart your notebook and run:
%pip install --upgrade validmindYou may need to restart your kernel after running the upgrade package for changes to be applied.
Copyright © 2023-2026 ValidMind Inc. All rights reserved.
Refer to LICENSE for details.
SPDX-License-Identifier: AGPL-3.0 AND ValidMind Commercial