Skip to main content
Version: 1.0 prerelease

Create a Validation Definition

A Validation Definition is a fixed reference that links a Batch of data to an Expectation Suite. It can be run by itself to validate the referenced data against the associated Expectations for testing or data exploration. Multiple Validation Definitions can also be provided to a Checkpoint which, when run, executes Actions based on the Validation Results for each provided Validation Definition.

Prerequisites

  1. Import the ValidationDefinition class from the GX 1.0 library:

    Python
    from great_expectations.core import ValidationDefinition
  2. Request a Data Context:

    Python
    import great_expectations as gx

    context = gx.get_context()
  3. Retrieve an Expectation Suite with Expectations.

    Update the value of suite_name in the following code with the name of your Expectation Suite. Then execute the code to retrieve that Expectation Suite:

    Python
    suite_name = "<NAME OF AN EXISTING EXPECTATION SUITE>"
    suite = context.get_expectation_suite(suite_name)
  4. Retrieve the Batch Definition that describes the data to associate with the Expectation Suite.

    Update the values of data_source_name, data_asset_name, and batch_definition_name in the following code with the names of your previously defined Data Source, one of its Data Assets, and a Batch Definition for that Data Asset. Then execute the code to retrieve the Batch Definition:

    Python
    data_source_name = "my_datasource"
    data_asset_name = "my_data_asset"
    batch_definition_name = "my_batch_definition"

    batch_definition = context.get_datasource(data_source_name).get(data_asset_name).get(batch_definition_name)
  5. Create a ValidationDefinition instance using the Batch Definition, Expectation Suite, and a unique name.

    Update the value of definition_name with a descriptive name that indicates the purpose of the Validation Definition. Then execute the code to create your Validation Definition:

    Python
    definition_name = "My Validation Definition"
    validation_definition = ValidationDefintion(data=batch_definition, suite=suite, name=definition_name)
  6. Optional. Save the Validation Definition to your Data Context.

    Python
    validation_definition = context.validation_definitions.add(validation_definition)
    tip

    You can add a Validation Definition to your Data Context at the same time as you create it with the following code:

    Python
    definition_name = "My second Validation Definition"
    validation_definition = context.validation_definitions.add(ValidationDefinition(data=batch_definition, suite=suite, name=definition_name))