ChatCompletion icon
GoogleGemini icon
OutputValues icon
Request icon
If icon
Log icon
SlackIncomingWebhook icon
Pause icon
Webhook icon

Generate and Validate Kestra Flows with AI and Compiler Reflection

Generate Kestra 2.0 flows from plain English, validate against the compiler API, auto-repair violations with AI reflection, and gate deployment.

Categories
AICore

Asking an LLM to write a workflow often produces YAML with small errors: an unquoted Pebble expression, a misspelled task property, or a missing required field. When someone copies that YAML straight into Kestra, it fails validation and requires manual troubleshooting.

This blueprint generates Kestra 2.0 YAML from a natural language requirement using Google Gemini, posts the draft directly to Kestra's /api/v1/flows/validate endpoint, and if any compiler violations are returned, feeds those errors back to the model to fix the YAML before posting a preview to Slack.

Safety

  • Validation gate: The flow checks the YAML with Kestra's validation API before anything is posted or saved.
  • Bounded repair: If the first draft has errors, it runs a single repair pass with the compiler output rather than looping indefinitely.
  • No automatic deployment: auto_deploy defaults to false. The flow only generates and tests the YAML.
  • Operator approval: When auto_deploy is enabled, a Pause task requires manual confirmation before creating the flow in the cluster.
  • Namespace boundary: Generated flows are placed into target_namespace.

How it works

  1. architect_initial_flow (io.kestra.plugin.ai.completion.ChatCompletion) prompts Google Gemini to write a Kestra 2.0 flow for the requirement.
  2. clean_draft_yaml (io.kestra.plugin.core.output.OutputValues) removes markdown code fences from the model output.
  3. validate_draft_compiler_syntax (io.kestra.plugin.core.http.Request) sends the draft YAML to Kestra's /api/v1/flows/validate endpoint.
  4. evaluate_validation_diagnostics (io.kestra.plugin.core.output.OutputValues) checks whether the compiler returned any constraint violations.
  5. handle_compiler_reflection (io.kestra.plugin.core.flow.If) branches: if errors occurred, reflect_and_repair_flow sends the compiler message back to Gemini to fix the YAML, then revalidate_repaired_flow tests the result.
  6. resolve_certified_yaml picks the repaired YAML if reflection ran, or the first draft if it was clean.
  7. notify_slack_preview (io.kestra.plugin.slack.notifications.SlackIncomingWebhook) posts the requirement and the final YAML to Slack.
  8. evaluate_deployment_intent (io.kestra.plugin.core.flow.If) pauses for approval if auto_deploy is enabled, then saves the flow to Kestra via POST /api/v1/flows.

What you get

  • A draft Kestra 2.0 flow generated from a plain English prompt.
  • Automatic validation against Kestra's compiler API before human review.
  • An automatic repair step that uses the compiler error message to fix broken YAML.
  • A Slack preview showing the prompt, the validation outcome, and the final YAML.
  • An optional approval gate to deploy the validated flow directly into your cluster.

Who it's for

  • Platform Engineers building internal developer platforms and self-service workflow generators.
  • Data Engineers scaffolding pipelines from natural language requirements.
  • Teams looking for AI-assisted workflow generation with automated validation.

Why orchestrate this with Kestra

Kestra can validate flows using its own API and handle human approvals with native Pause tasks. Combining AI generation with native validation in a single flow gives you an automated, reviewable process without external wrapper scripts.

Pitfalls

  • Ambiguous prompts: Vague specifications like "sync data" will generate generic HTTP tasks. Provide concrete endpoints, schemas, or schedules in the prompt for best results.
  • Custom plugin availability: The flow generates standard Kestra core and official plugin tasks. Ensure any specialized plugins referenced in generated YAML are installed on your cluster.
  • API authentication: When validating or deploying against secured clusters, provide a valid token in api_token.

Prerequisites

  • Accessible Kestra 2.0+ cluster webserver API.
  • Google Gemini API key configured as a Kestra secret.
  • Slack incoming webhook URL for notifications.

Secrets

  • GEMINI_API_KEY: API key for Google Gemini completion tasks.
  • SLACK_WEBHOOK_URL: Slack incoming webhook URL for flow previews and alerts.
  • AI_ARCHITECT_WEBHOOK_KEY: Secret key for authenticating the inbound trigger webhook.

Quick start

  1. Configure GEMINI_API_KEY and SLACK_WEBHOOK_URL in your Kestra namespace secrets.
  2. Run the flow with auto_deploy: false to test generation, validation, and Slack preview.
  3. Review the generated YAML delivered to Slack.
  4. Enable auto_deploy: true and resume the Pause approval to create the flow in Kestra.

How to extend

  • Swap the GoogleGemini provider for OpenAI or Anthropic based on your organization's standards.
  • Add a GitHub pull request creation task using io.kestra.plugin.git to commit the validated YAML to a repository instead of direct cluster deployment.
  • Extend the validation gate with custom governance policies (e.g. enforcing mandatory tags or execution timeouts).

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.