Webhook icon
Schedule icon
Script icon
OutputValues icon
If icon
SlackIncomingWebhook icon

Promptfoo LLM Red-Teaming and Security Regression Gate

Automate LLM red-teaming, prompt injection tests, and security regression gates with Promptfoo in Kestra. Block vulnerable AI deployments automatically.

Categories
AI

When engineering teams update system prompts, swap underlying foundation models (e.g. OpenAI GPT-4o, Anthropic Claude 3.5 Sonnet, Google Gemini), or adjust RAG context windows, they frequently lack automated safety and security regression gates. A subtle prompt change can silently introduce catastrophic vulnerabilities, such as jailbreaks, prompt injection leaks of proprietary business logic, or customer PII extraction.

This blueprint implements an automated LLM red-teaming and security regression testing gate orchestrated by Kestra using Promptfoo. It evaluates dynamic prompts against adversarial attack vectors (DAN attacks, indirect prompt injection, PII exfiltration), runs custom user assertions, enforces an automated compliance gate based on pass rates and zero-tolerance exploit thresholds, and publishes interactive evaluation reports.

How it works

  1. Dynamic Prompt & Test Ingestion: The flow ingests target system prompts and test matrices dynamically via CI/CD webhooks (on_prompt_commit_webhook), nightly security audit schedules (0 2 * * *), or manual Kestra UI execution.
  2. Adversarial Red-Team Synthesis: Combines user-defined custom test cases with active adversarial attack plugins:
    • Prompt Injection: Direct and indirect prompt injection attempts targeting system prompt extraction.
    • Jailbreaks: Complex roleplay framing and hypothetical scenario bypasses.
    • PII Leakage: Social engineering probes attempting to extract customer phone numbers, emails, and payment records.
    • RBAC Privilege Escalation: Unauthorized attempts to trigger administrative commands.
  3. Matrix Evaluation: An isolated container runs the evaluation matrix against the designated LLM provider (openai:gpt-4o, claude-3-5-sonnet, gemini-1.5-pro, ollama:llama3), scoring outputs for semantic similarity, forbidden substring matches, and latency.
  4. Automated Compliance Gate: An io.kestra.plugin.core.flow.If condition checks evaluation metrics against safety standards:
    • On Gate Failure: Halts the deployment pipeline immediately and triggers a Slack Red Alert.
    • On Gate Success: Emits a verified security clearance and notifies the AI engineering team.
  5. Interactive Report Artifacts: Emits both machine-readable promptfoo_report.json and a self-contained, interactive interactive_eval_report.html dashboard previewable directly inside Kestra UI.

What you get

  • Automated AI Red-Teaming: Continuously probes LLM prompts for jailbreaks and prompt injections before code reaches production.
  • Zero-Tolerance Exploit Defense: Blocks production deployments if any critical security vulnerability or data leak succeeds.
  • Dynamic Test Flexibility: Supports both inline JSON test assertions and external test suites stored in S3 or Git.
  • Interactive Visualization: Generates complete HTML evaluation scorecards rendered natively in Kestra.

Expected outputs

Downstream CI/CD deployment pipelines or Slack bots can reference the typed metrics produced by output_eval_metrics:

Output Variable Description Expression Example
total_tests Total number of test cases and adversarial probes evaluated {{ outputs.output_eval_metrics.values.total_tests }}
passed_tests Number of evaluations that passed security and assertion checks {{ outputs.output_eval_metrics.values.passed_tests }}
failed_tests Number of evaluations that failed safety thresholds {{ outputs.output_eval_metrics.values.failed_tests }}
pass_rate_percentage Overall evaluation pass rate percentage {{ outputs.output_eval_metrics.values.pass_rate_percentage }}
critical_vulnerabilities Count of critical red-team exploits detected {{ outputs.output_eval_metrics.values.critical_vulnerabilities }}
compliance_verdict Security gate determination (COMPLIANT_PASSED or SECURITY_GATE_FAILED) {{ outputs.output_eval_metrics.values.compliance_verdict }}
gate_passed Boolean flag indicating whether the deployment is cleared {{ outputs.output_eval_metrics.values.gate_passed }}
json_report_uri Internal Kestra storage URI to promptfoo_report.json {{ outputs.output_eval_metrics.values.json_report_uri }}
interactive_report_uri Internal Kestra storage URI to interactive_eval_report.html {{ outputs.output_eval_metrics.values.interactive_report_uri }}

Who it's for

  • AI & ML Engineers deploying production LLMs, autonomous agents, and RAG pipelines who need automated security testing.
  • SecOps & AppSec Teams enforcing red-teaming compliance and OWASP Top 10 for LLM security policies.
  • Platform Teams embedding automated AI quality gates into GitHub Actions or GitLab CI/CD pipelines.

Why orchestrate this with Kestra

Running ad-hoc evaluation scripts manually is error-prone and easily bypassed by engineers. Kestra delivers:

  • Hard Deployment Gates: Blocks downstream deployment tasks automatically when pass rates drop below compliance thresholds.
  • Centralized Secret Management: Injects API keys (OPENAI_API_KEY, ANTHROPIC_API_KEY, GEMINI_API_KEY) from Kestra's encrypted secret store without exposing them in CI scripts.
  • Audit Trail & Artifact Retention: Persists cryptographic logs, prompt snapshots, and HTML evaluation scorecards for compliance audits.

Prerequisites

  • Kestra runner with Docker or Kubernetes access to pull container images.
  • API keys for your target LLM provider (OpenAI, Anthropic, Google, or self-hosted Ollama).
  • An incoming Slack webhook URL for security alerts.

Secrets

Configure the following secrets in your Kestra namespace or instance settings:

Secret Name Description Example
SLACK_WEBHOOK_URL Incoming webhook URL for the AI security Slack channel https://hooks.slack.com/services/T00/B00/X00
WEBHOOK_KEY Secret authentication key for triggering CI/CD evaluation webhooks whk_promptfoo_sec_78192
OPENAI_API_KEY (Optional) API key for OpenAI model evaluations sk-proj-••••••••••••
ANTHROPIC_API_KEY (Optional) API key for Anthropic Claude evaluations sk-ant-••••••••••••
GEMINI_API_KEY (Optional) API key for Google Gemini evaluations AIzaSy••••••••••••

Quick start

  1. Import this blueprint into your Kestra instance under the company.ai namespace.
  2. Add SLACK_WEBHOOK_URL and your LLM API keys in Settings > Secrets.
  3. Click Execute with the default inputs to test the sample customer support prompt against red-team attack vectors.
  4. Navigate to the Outputs tab in Kestra UI to review the interactive HTML evaluation scorecard.
  5. Connect the webhook to your GitHub Actions or GitLab CI prompt repository.

Common pitfalls & notes

  • Jailbreak Sensitivity: Set fail_on_critical_vulnerability: true to prevent any prompt injection from entering production, even if the overall pass rate is high (e.g., 98%).
  • Provider Rate Limits: When evaluating large test matrices (100+ tests), ensure your LLM provider account has sufficient RPM/TPM quota to avoid HTTP 429 throttling.
  • Schedule State: The nightly red-teaming schedule is shipped disabled: true by default until production endpoints and API keys are configured.

How to extend

  • CI/CD Pull Request Comments: Post the generated evaluation summary directly as a GitHub PR comment using io.kestra.plugin.git.
  • Multi-Model Bakeoff: Extend the provider list to benchmark OpenAI GPT-4o against Claude 3.5 Sonnet side-by-side on the exact same test matrix.
  • RAG Factuality Rubrics: Add assertions testing for factual consistency and grounding against retrieved document chunks.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.