---
title: Alert RCA with Autopilot and Slack
source: https://docs.newrelic.com/docs/workflow-automation/workflow-examples/integrations/autopilot-slack-rca
---

This template runs [Autopilot](https://docs.newrelic.com/docs/agentic-ai/autopilot/overview) on a New Relic alert and posts the root cause analysis to a Slack channel. If Autopilot returns no usable response, the workflow sends an error notice instead. For shared prerequisites and configuration notes, see [Autopilot RCA workflow templates](https://docs.newrelic.com/docs/workflow-automation/workflow-examples/integrations/autopilot-rca).

Before using this workflow, ensure you have:

-   A Slack destination configured in New Relic — see [Create destinations](https://docs.newrelic.com/docs/workflow-automation/setup-and-configure/create-destinations)
-   The destination's UUID and the target Slack channel name

This workflow completes the following steps:

1.  Sends an initial Slack message to acknowledge the alert and let the team know RCA is underway
2.  Runs Autopilot with a root cause analysis prompt scoped to the alert issue ID
3.  Checks whether Autopilot returned a usable response
4.  Reformats the response as Slack Block Kit blocks and posts findings to Slack (if Autopilot returns a response)
5.  Posts an error message with the issue ID (if Autopilot returns no response)

This workflow uses `newrelic.autopilot.run` and `newrelic.notification.sendSlack`.

```yaml
name: autopilotSlackRCA
description: Automatically analyze New Relic alerts with Autopilot and send cleanly formatted findings to Slack
workflowInputs:
  issueId:
    type: String
    required: true
    validations:
      - errorMessage: Must be a valid New Relic issue ID in UUID format
        pattern: '^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$'
        type: regex
  slackDestinationId:
    type: String
    required: true
    validations:
      - pattern: ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
        errorMessage: "Invalid format. Please provide a valid UUID."
        type: regex
  channel:
    type: String
    required: true
steps:
  - name: notifyAlertReceived
    type: action
    action: newrelic.notification.sendSlack
    version: 1
    inputs:
      destinationId: ${{ .workflowInputs.slackDestinationId }}
      channel: ${{ .workflowInputs.channel }}
      text: |-
        🔔 *Alert Received — Starting Root Cause Analysis*

        ⏳ Running Autopilot for RCA, please wait...

  - name: runAutopilot
    type: action
    action: newrelic.autopilot.run
    version: 1
    inputs:
      prompt: >-
        Perform a root cause analysis for the following New Relic alert:
        Issue ID: ${{ .workflowInputs.issueId }}
        Provide your comprehensive analysis including Summary, Root Cause, and Remediation Actions.
      selectors:
        - name: analysisRaw
          expression: .response.finalAnswer
        - name: analysisText
          expression: '(.response.finalAnswer | if type=="string" then fromjson else . end).card.body | map(.value) | join("\n\n")'
    ignoreErrors: true

  - name: checkAgentResponse
    type: switch
    switch:
      - condition: ${{ (.steps.runAutopilot.outputs.analysisRaw // "") != "" }}
        next: buildSlackBlocks
    next: sendAutopilotError

  - name: buildSlackBlocks
    type: assign
    inputs:
      blocks: '${{ (.steps.runAutopilot.outputs.analysisText // "") | gsub("\\*\\*"; "*") | gsub("### "; "*") | gsub("## "; "*") as $text | ([ $text / "\n" ]) as $lines | [ { "type": "header", "text": { "type": "plain_text", "text": "✅ Autopilot RCA Complete" } }, { "type": "divider" } ] + [ $lines[][] | select(. != "") | { "type": "section", "text": { "type": "mrkdwn", "text": . } } ] }}'
    next: sendRcaFindings

  - name: sendRcaFindings
    type: action
    action: newrelic.notification.sendSlack
    version: 1
    inputs:
      destinationId: ${{ .workflowInputs.slackDestinationId }}
      channel: ${{ .workflowInputs.channel }}
      blocks: ${{ .steps.buildSlackBlocks.outputs.blocks }}
    next: end

  - name: sendAutopilotError
    type: action
    action: newrelic.notification.sendSlack
    version: 1
    inputs:
      destinationId: ${{ .workflowInputs.slackDestinationId }}
      channel: ${{ .workflowInputs.channel }}
      text: |-
        🟥 *Autopilot RCA Failed*

        Could not extract findings from Autopilot response for issue: ${{ .workflowInputs.issueId }}
        Please investigate manually.
    next: end
```

## How it works [#how-it-works]

The `runAutopilot` step uses two selectors to handle `finalAnswer` shape variability at the data-extraction layer:

-   **`analysisRaw`** captures the raw `finalAnswer` value. The `checkAgentResponse` step uses this to determine whether Autopilot returned anything.
-   **`analysisText`** normalizes the value — if `finalAnswer` is a JSON-encoded string, it parses it first, then extracts text content from `.card.body`. The `buildSlackBlocks` step uses `analysisText` directly, without any additional parsing.

`buildSlackBlocks` converts `**bold**` and `###`/`##` heading markers to Slack mrkdwn format, splits the result on newlines, and wraps each non-empty line in a Block Kit `section` block.

## Related topics [#related-topics]

[Autopilot RCA workflow templates](https://docs.newrelic.com/docs/workflow-automation/workflow-examples/integrations/autopilot-rca)

Shared prerequisites and configuration notes for all Autopilot RCA templates

[Autopilot overview](https://docs.newrelic.com/docs/agentic-ai/autopilot/overview)

Learn how Autopilot investigates alerts and incidents

[Conditional logic](https://docs.newrelic.com/docs/workflow-automation/workflow-examples/basic-patterns/conditional-logic)

Use switch statements to branch on success or failure

[Send Slack notifications](https://docs.newrelic.com/docs/workflow-automation/setup-and-configure/actions-catalog/newrelic/notification/newrelic-notification#newrelic.notification.sendSlack)

Full reference for the sendSlack action

[Create destinations](https://docs.newrelic.com/docs/workflow-automation/setup-and-configure/create-destinations)

Configure the Slack destination required by this workflow

[Alert RCA with Autopilot and Email](https://docs.newrelic.com/docs/workflow-automation/workflow-examples/integrations/autopilot-email-rca)

Send RCA findings by email instead of Slack

[Troubleshoot Workflow Automation](https://docs.newrelic.com/docs/workflow-automation/troubleshooting)

Solutions for common Autopilot and Slack integration issues
