Skip to content

Commit

Permalink
Merge pull request #59 from kestra-io/docs/llm-error-alert
Browse files Browse the repository at this point in the history
docs: explain-error-with-llm
  • Loading branch information
anna-geller authored Feb 11, 2025
2 parents 1cbec63 + d50daa5 commit 3296832
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions flows/explain-error-with-llm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
id: explain-error-with-llm
namespace: blueprints

tasks:
- id: bad_python_task
type: io.kestra.plugin.scripts.python.Script
script: |
myvar = 1
print(myvar[0])
errors:
- id: ai
type: io.kestra.plugin.openai.ChatCompletion
apiKey: "{{secret('OPENAI_API_KEY')}}"
model: gpt-4o
clientTimeout: 100
prompt: |
My task generated an error. Explain what might have caused it.
Do not use backticks, quotes, asterisks, or any Markdown formatting.
Ensure all text is treated as plain text without any special characters or indentation.
If mentioning code or error messages, format them as inline text with no special symbols.
Don't use any quotes in your response and if you do,
make sure to escape them with back-slashes e.g. \"Command failed with exit code 1\".
Error log — {{errorLogs()}}
- id: alert
type: io.kestra.plugin.notifications.slack.SlackIncomingWebhook
url: "{{secret('SLACK_WEBHOOK_URL')}}"
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Failure alert for flow *{{flow.namespace}}.{{flow.id}}* with ID `{{execution.id}}`. \n\n*Error:* {{outputs.ai.choices[0].message.content}}"
}
}
]
}
extend:
title: Use an OpenAI LLM to explain errors on failed executions within Slack alerts
description: >-
This flow detects errors in a Python script and uses an LLM to explain the cause.
- The `bad_python_code` task executes a Python script that contains an intentional error.
- If an error occurs, the `ai` task explains the error logs.
- The `alert` task sends a Slack notification with a summary of the failure, including the LLM-generated explanation.
tags:
- AI
- API
- Fail
- Notifications
ee: false
demo: false
meta_description: Send automated Slack alerts with AI-generated explanations of errors in failed workflows.

0 comments on commit 3296832

Please sign in to comment.