Skip to main content
Version: 1.5.11

Trigger actions

Use Actions to notify the appropriate parties of the results of your Validation runs. These Actions can be triggered for either successful or failed Validation runs. Validations are executed using Checkpoints, which each have a list of Actions that will be executed when each run has finished. By default, GX Cloud creates a Checkpoint for each Data Asset that you create. Optionally, you can also use a Checkpoint that you have created manually. This example will demonstrate how to create a SlackNotificationAction and append it to the list of Actions on a given Checkpoint.

Prerequisites

Procedure

  1. Import the relevant modules and instantiate your Context.

    Python
    import great_expectations as gx
    from great_expectations.checkpoint import SlackNotificationAction

    context = gx.get_context()
  2. Retrieve the Checkpoint to append the Action to.

    Python
    checkpoint_name = "my_checkpoint"
    checkpoint = context.checkpoints.get(checkpoint_name)
    The GX-managed Checkpoint name can be found through the UI

    For the Data Asset of interest, go to the Validations tab. If you have more than one Expectation Suite, select the GX-managed one. Then, click the code snippet icon next to the Validate button and click Generate snippet.

  3. Define the Actions that the Checkpoint will trigger.

    The following is an example of how to define a SlackNotificationAction.

    Python
    action = SlackNotificationAction(
    name="send_slack_notification_on_failed_expectations",
    slack_token="${bot_user_oauth_token}",
    slack_channel="#my_channel",
    notify_on="failure",
    show_failed_expectations=True,
    )
  4. Append the newly-created Action to the Checkpoint Action list and save the Checkpoint.

    Python
    checkpoint.actions.append(action)
    checkpoint.save()
  5. Optional. Run a Validation to ensure the newly-created Action is triggered as expected.