aiRule validates data using a plain-English instruction. Datris generates a Python validation script from your instruction via an LLM (single API call) when the pipeline is saved, stores it, and runs the stored script against all data on every run, in an isolated runner container.
Configuration
Define the AI rule in theaiRule field within the dataQuality block of the pipeline configuration.
How it works
- Prompt generation — At pipeline save, Datris combines the source schema (delimiter, column names and types) with your instruction and sends a single prompt to the configured AI model. When a run has to generate the script instead (see When the script is generated), it uses the column names and a few sample rows from that run’s data.
- Script generation — The AI model generates a self-contained Python 3 validation script (stdlib only, no pip packages).
- Local execution — On every run, the stored script is written to a temp file and executed via
python3against the full data file. Runs make no model call. - Result parsing — The script outputs a JSON array of failures:
[{"index": <row_number>, "reason": "..."}]. Datris parses this and maps failures back to the original data. Theindexis 0-based: the first record is index0, the second is index1, and so on. - Cleanup — Temp files are deleted after execution.
Example
Works with all file types
This approach works for:- CSV/delimited files — The script reads the CSV with the appropriate delimiter and validates each row.
- JSON files — The script parses the JSON array and validates each record.
- XML files — The script uses
xml.etree.ElementTreeto parse and validate each element.
When the script is generated
The script is generated once and stored, not on every run:- At save — Saving a pipeline with an AI rule (
POST /api/v1/pipeline, the MCPcreate_pipelinetool, or the UI wizard) generates the script from the source schema: the delimiter and the ordered field names and types. No sample rows are available when a pipeline is saved, so state any format the rule depends on in the instruction (for example “dates are YYYY-MM-DD”). The script is stored in the built-in object store underpipeline-scripts/<pipeline>/, or committed to the code repository when one is enabled (see Pipeline scripts). - Every run — Each run executes the stored script. A run makes no model call, gives the same result for the same data, and keeps working if the model is unreachable. The status shows “Running stored CodeGen script generated at …”.
- Re-saving — Saving again regenerates only when the instruction or the source schema (delimiter, field names, types or order) changed. Re-saving an unchanged pipeline makes no model call. A changed CodeGen model does not regenerate: the script keeps the model that wrote it.
- Pending — If the script cannot be generated at save (no AI key, model unreachable, AI disabled), the pipeline is still saved, the save response carries a warning and
codegenScriptslists the script aspendingwith the reason. JSON and XML pipelines have no column schema to generate from, so they are always saved pending. The first run generates the script from its data, stores it, and later runs reuse it. - Header differs — If the header that reaches the rule differs from the one the script was written for (for example a column was removed by field protection or is missing from the file), that run generates a script for itself only and keeps the stored one. The status says why.
- Failures — A stored script that exits with an error, times out, or prints output that is not a JSON array fails the run. It is not regenerated automatically: the error names when the script was generated and the regenerate endpoint.
GET /api/v1/pipelines/{name}/codegen-scripts. To replace it (for example to adopt a new CodeGen model, or after a wrong script), call POST /api/v1/pipelines/{name}/codegen-scripts/dataQuality/regenerate, which needs the pipeline:update capability. If generation fails there, the current script stays in place.
Every change to the script (generated at save or at a run, regenerated, adopted from the code repository, imported by a catalog restore, or restored) is kept as a numbered version with its text. List them with GET /api/v1/pipelines/{name}/codegen-scripts/dataQuality/versions, compare two with .../versions/{version}/diff?against={other}, and go back to one with POST .../versions/{version}/restore (needs pipeline:update): the chosen text becomes a new latest version, with no model call, and the pipeline’s definition version does not change. A restore is refused when the version was written for a different instruction or source schema than the pipeline has now. In the UI, open a run of the pipeline and choose Script history.
With a code repository configured under Configuration > Code Repository, the script for a new pipeline is committed to it as <pathPrefix>pipelines/<pipeline>/data-quality.py and every run executes the recorded commit. You can review it, blame it and edit it in the repository; an edit is used only after you adopt it with POST /api/v1/pipelines/{name}/codegen-scripts/dataQuality/pull. See Pipeline scripts for commit messages, conflicts, and what happens when the repository is unreachable.
Pipelines created before stored scripts generate their script on the first run after the upgrade and reuse it after that.
Values withheld
When the server setsDATRIS_AI_SAMPLE_VALUES=false, the prompt carries the column names and schema types (or a value-free skeleton of a JSON or XML file) and the line “Sample rows withheld by configuration” instead of sample rows. The generated script still runs on the full data. Because the model cannot see what the values look like, state any format the rule depends on in the instruction (for example “dates are YYYY-MM-DD”). See Field Protection.
Behavior
- An
aiRulewhoseinstructionis empty or only whitespace is ignored: no script is generated at save and the run skips the stage with a status line saying so. - The AI rule’s Python script is generated when the pipeline is saved (or by the first run that needs one) and reused by every run until the instruction or source schema changes
- The generated script runs via
python3with a 5-minute timeout, in the isolateddatris-codegen-runnercontainer on a compose install (see below) - Scripts are constrained to Python standard library only (no external packages)
- Rules with
onFailureIsError: trueare counted as errors;onFailureIsError: falseare warnings - All rows are evaluated; the abort message lists the first 100 errors and a count of any remaining
- After all rows are evaluated, if any errors exist, processing is aborted
- Warnings are summarized at the end of validation
Where the script runs
On a compose install the generated script runs indatris-codegen-runner, an isolated container with no platform secrets, no access to the server’s files, and no route to the internal services or the internet. The server sends it the script and the data file and reads back the result. If the runner is stopped or unreachable the rule fails with an error naming it; it never falls back to running the script in the server. See Generated data-quality and transformation scripts.
Requirements
ai.enabled: truemust be set inapplication.yaml- The Vault secret for the AI provider must be configured (see AI Configuration)
