Run a Validation Definition
Prerequisites
- Python version 3.9 to 3.12.
- An installation of GX Core.
- A preconfigured Data Context. In this guide the variable
context
is assumed to contain your Data Context. - A Validation Definition.
Procedure
- Instructions
- Sample code
-
Retrieve your Validation Definition.
If you have created a new Validation Definition you can use the object returned by your Data Context's
.validation_definitions.add(...)
method. Alternatively, you can retrieve a previously configured Validation Definition by updating the variablevalidation_definition_name
in the following code and executing it:Python name=validation_definition_name = "my_validation_definition"
validation_definition = context.validation_definitions.get(validation_definition_name) -
Execute the Validation Definition's
run()
method:Pythonvalidation_results = validation_definition.run()
Validation Results are automatically saved in your Data Context when a Validation Definition's
run()
method is called. For convenience, therun()
method also returns the Validation Results as an object you can review.Result verbosityYou can set the level of detail returned in a Validation Definition's results by passing a Result Format configuration as the
result_format
parameter of your Validation Definition'srun(...)
method. For more information on Result Formats, see Choose a result format. -
Review the Validation Results:
Pythonprint(validation_results)
When you print the returned Validation Result object you will recieve a json representation of the results. By default this will include a
"results"
list that includes each Expectation in your Validation Definition's Expectation Suite, whether the Expectation was successfully met or failed to pass, and some sumarized information explaining the why the Expectation succeeded or failed.
import great_expectations as gx
context = gx.get_context()
# Retrieve the Validation Definition
validation_definition_name = "my_validation_definition"
validation_definition = context.validation_definitions.get(validation_definition_name)
# Run the Validation Definition
validation_results = validation_definition.run()
# Review the Validation Results
print(validation_results)