FinalActions
self, *args) FinalActions(
Define actions to be taken after validation is complete.
Final actions are executed after all validation steps have been completed. They provide a mechanism to respond to the overall validation results, such as sending alerts when critical failures are detected or generating summary reports.
Parameters
*actions :
-
One or more actions to execute after validation. An action can be (1) a callable function that will be executed with no arguments, or (2) a string message that will be printed to the console.
Returns
: FinalActions
-
An
FinalActions
object. This can be used when using theValidate
class (to set final actions for the validation workflow).
Types of Actions
Final actions can be defined in two different ways:
- String: A message to be displayed when the validation is complete.
- Callable: A function that is called when the validation is complete.
The actions are executed at the end of the validation workflow. When providing a string, it will simply be printed to the console. A callable will also be executed at the time of validation completion. Several strings and callables can be provided to the FinalActions
class, and they will be executed in the order they are provided.
Crafting Callables with get_validation_summary()
When creating a callable function to be used as a final action, you can use the get_validation_summary()
function to retrieve the summary of the validation results. This summary contains information about the validation workflow, including the number of test units, the number of failing test units, and the threshold levels that were exceeded. You can use this information to craft your final action message or to take specific actions based on the validation results.
Examples
Final actions provide a powerful way to respond to the overall results of a validation workflow. They’re especially useful for sending notifications, generating reports, or taking corrective actions based on the complete validation outcome.
The following example shows how to create a final action that checks for critical failures and sends an alert:
import pointblank as pb
def send_alert():
= pb.get_validation_summary()
summary if summary["highest_severity"] == "critical":
print(f"ALERT: Critical validation failures found in {summary['table_name']}")
= (
validation
pb.Validate(=my_data,
data=pb.FinalActions(send_alert)
final_actions
)="revenue", value=0)
.col_vals_gt(columns
.interrogate() )
In this example, the send_alert()
function is defined to check the validation summary for critical failures. If any are found, an alert message is printed to the console. The function is passed to the FinalActions
class, which ensures it will be executed after all validation steps are complete. Note that we used the get_validation_summary()
function to retrieve the summary of the validation results to help craft the alert message.
Multiple final actions can be provided in a sequence. They will be executed in the order they are specified after all validation steps have completed:
= (
validation
pb.Validate(=my_data,
data=pb.FinalActions(
final_actions"Validation complete.", # a string message
# a callable function
send_alert, # another callable function
generate_report
)
)="revenue", value=0)
.col_vals_gt(columns
.interrogate() )