Schedule icon
Queries icon
Query icon
Script icon
Docker icon
Log icon
If icon
Fail icon

AI-Generated Data Pipeline Test Cases

Generate and validate AI-proposed CSV data-quality tests with DuckDB, an OpenAI-compatible LLM endpoint, and a JSON report in Kestra.

Categories
AI

This blueprint demonstrates a guarded AI-assisted data-quality workflow. DuckDB profiles a sample CSV, an OpenAI-compatible chat completions endpoint can propose structured tests, and a Python validator executes only a small allowlist of safe rule types. The LLM never supplies SQL or code. Invalid or unsupported proposals are reported separately and are never treated as passed.

How it works

  1. Generate a sample CSV with DuckDB; optionally inject deliberate quality issues.
  2. Profile the dataset schema with DuckDB (shown in the execution outputs; the Python task re-profiles the file to stay self-contained).
  3. Obtain test specifications. By default, clearly labelled deterministic demo rules are used so no API key is needed. With use_llm enabled, an OpenAI-compatible endpoint proposes tests from the schema and your transformation_requirements.
  4. Validate the JSON structure, column references, rule names and column types, then run only allowlisted checks with DuckDB.
  5. Write test-report.json, log a summary, and, through an If quality gate, optionally fail the execution when any test fails or is invalid.

A disabled schedule trigger is included so the flow can be enabled for daily runs after manual testing.

What you get

  • A transformation_requirements input (used with a live LLM) that steers which tests are proposed.
  • A runnable sample CSV dataset, with an optional deliberately faulty variant.
  • A DuckDB schema profile.
  • A JSON report in which every test is passed, failed, or invalid.
  • A conditional quality gate controlled by fail_on_violation.
  • Safeguards: allowlisted rules only, validated and quoted column names, case-insensitive column matching, type checks per rule, duplicate proposals ignored, a 20-test cap, tolerant parsing of fenced or prose-wrapped JSON, retries for rate limits and server errors, no redirects, and clear invalid results for empty responses, malformed JSON, refusals, truncated output, empty datasets and unreadable files.

Who it's for

Data engineers, analytics engineers, QA engineers, and teams exploring controlled LLM-assisted data validation.

Why orchestrate this with Kestra

Kestra coordinates data generation, profiling, model requests, validation, reporting, scheduling and conditional failure in one observable workflow. Each step has its own logs, outputs and retry behaviour, and the quality gate is explicit orchestration logic rather than a script that exits silently, which a collection of disconnected scripts and cron jobs does not give you.

Prerequisites

  • A Kestra instance with the DuckDB JDBC plugin and Python script tasks available.
  • Docker available to the Kestra worker for the Python task runner, and network access to install kestra, requests and duckdb with pip.
  • For live LLM generation only: an OpenAI-compatible endpoint and API key.

Secrets

  • OPENAI_API_KEY: required only when use_llm is true. It is sent as a Bearer token to the configured endpoint and is never logged or written to the report. Demo mode does not read this secret.

Quick start

  1. Import this flow into Kestra.
  2. Run it manually with the default inputs to exercise the deterministic demo rules; all tests should pass.
  3. Run it again with inject_bad_data set to true; the duplicate ID, negative amount and invalid date are reported as failed, and the quality gate fails the execution.
  4. Set fail_on_violation to false to keep the execution successful while still producing the report.
  5. To use a live model, create the OPENAI_API_KEY secret, set use_llm to true, choose the endpoint and model, and edit transformation_requirements to describe your business rules.
  6. Inspect test-report.json in the output files of the generate_validate_and_run_tests task, then enable the schedule trigger if you want daily runs.

How to extend

Add new rule types only by implementing an explicit validation and execution branch in the Python task, and keep unknown rules classified as invalid. Replace the sample CSV with a trusted upstream dataset, expand the profile sent to the model, or add a notification task after the quality gate.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.