Configuration
Add anaiTransformation block to the transformation section:
Examples
Date format conversion:How it works
- When the pipeline is saved, Datris combines the source schema (delimiter, column names and types) with your instruction and sends a single prompt to the AI model. When a run has to generate the script instead (see When the script is generated), it uses the column names and sample rows from that run’s data.
- The AI generates a self-contained Python 3 script (stdlib only) that reads the input file, applies the transformation, and writes the output. The script is stored.
- Every run executes the stored script locally via
python3. Runs make no model call. - The transformed data replaces the original and continues through the pipeline to destinations.
datris-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 input file and streams the output file back. If the runner is stopped or unreachable the transformation fails with an error naming it; it never falls back to running the script in the server. See Generated data-quality and transformation scripts.
An aiTransformation whose instruction is empty or only whitespace is ignored: no script is generated at save and the run skips the stage with a status line saying so.
When the script is generated
The script is generated once and stored, not on every run:- At save — Saving a pipeline with an AI transformation (
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 transformation 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 transformation 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 or times out 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/transformation/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/transformation/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>/transformation.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/transformation/pull. See Pipeline scripts for commit messages, conflicts, and what happens when the repository is unreachable.
The Columns section of the lineage panel shows when and by which model the stored transformation script was generated, or “Script pending” with the reason, and offers View, History and Regenerate.
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. If the transformation depends on what values look like, spell the format out in the instruction. See Field Protection.
Works with all file types
- CSV/delimited files — The script reads and writes CSV with the appropriate delimiter.
- JSON files — The script parses JSON, transforms records, and writes JSON.
- XML files — The script uses
xml.etree.ElementTreeto parse, transform, and write XML.
CLI
Requirements
ai.enabled: truemust be set inapplication.yaml- The Vault secret for the AI provider must be configured (see AI Configuration)
python3must be available where the script runs: thedatris-codegen-runnercontainer on a compose install (USE_CODEGEN_RUNNER=true, the default), or the server itself when scripts run in-process (USE_CODEGEN_RUNNER=false)
