Skip to main content

AI in TransformScript

AI in TransformScript is in Limited Preview and is not generally available yet. To request access, contact your Account Manager. Access is typically granted to customers who already use TransformScript in production.

TransformScript can call an AI model from inside a transformation and feed the result back into your workflow. This is how you handle input that isn't cleanly structured: extract specific fields from a document, classify a message, or summarize content, then use that output like any other value in your script.

The AI call returns machine-readable output with the field names and types defined by your schema.

Calling AI

You provide a prompt, the input to work from, and an output schema. Supply text or structured data as inputs. For a PDF or other document, extract its text first. The AI call does not read scanned pages directly or perform optical character recognition (OCR); use a separate OCR tool to turn a scan into text before supplying it as input.

In Automations v2, the Extract node reads text from documents and makes it available as attributes.extract.content_text. A following Transform node can supply that value as the AI call's inputs.

This example extracts invoice fields from text already available as payload:

---
{
  extraction: ai(
    prompt: "Extract the invoice number, invoice total amount, and invoice currency from the provided invoice.",
    inputs: payload,
  ) as {
    invoiceNumber: String,
    total: Number,
    currency: String
  }
}

The schema is the contract for the result. The model's answer is shaped to match it, so downstream steps can rely on the field names and types. If the output doesn't match the schema, you can fail fast or configure a fallback.

Matching the schema does not establish that the values are correct or satisfy your business rules. Validate generated values before using them in calculations or later workflow actions. For the invoice example, compare the fields with the source text and check that the amount and currency meet the receiving system's requirements.

When to Use AI

Use an AI call when the input is unstructured or inconsistent and a fixed parser can't reliably read it: text extracted from documents, free-form email bodies, or spreadsheet data whose layout varies between senders. For input that already has a dependable structure, the Function Library and selectors extract and reshape it without a model call, which is faster and fully deterministic.