Ask AI in a workflow
fromAi(instructions) asks your deployment’s AI model and brings the answer back as typed columns. It is a line in a formula node’s node file, so the statements after it check and shape the answer like any other data.
The Learn AI generation in workflows catalog has a runnable lesson for each shape below: 01 Classify rows, 02 Extract fields from free text, 03 Summarise a whole table, 04 Check the AI’s answer with a formula, and 05 One row in, many rows out.
Ask once per row
Section titled “Ask once per row”eachRow().fromAi(`Classify this support ticket. Return the category that fits best, and how urgent it is.`) .send("subject", "body") .returns("category", "text", "billing, access, bug or other") .returns("urgency", "text", "high or low") .numRowsToProcess(-1).send(name, …)names the columns the model sees. Nothing else of the row leaves Fontana, and the instructions carry no row values..send()with no names sends every column..returns(name, type, description)declares one answer field as a typed column:text,number,date,boolean, or a list such aslist<text>. The description tells the model what belongs there. Every declared field is required, so an answer that leaves one out fails that row.- Without
.returns, the answer is one text column,ai_answer.
Choose how many rows are sent
Section titled “Choose how many rows are sent”.numRowsToProcess(n) sends the first n rows; -1 sends every row. .offset(n) starts further down.
Without .numRowsToProcess, a workflow run sends no rows: only the test in the node editor does. A new AI node therefore costs nothing until you decide how many rows it may send. Rows outside the page keep empty answer columns.
One row in, many rows out
Section titled “One row in, many rows out”.oneToMany() turns each item of the answer into a row of its own, with the input row’s columns copied onto it. An answer with no items drops the row.
eachRow().fromAi(`List every product this customer message orders.`) .send("customer", "message") .oneToMany() .returns("product", "text") .returns("quantity", "number") .numRowsToProcess(-1)Ask once over the whole table
Section titled “Ask once over the whole table”Without eachRow(), fromAi asks once over the rows it sends. The answer replaces the rows:
fromAi(`These are today's trades. Write a summary of two or three sentences for the head of trading.`) .send() .returns("summary", "text") .returns("trade_count", "number") .numRowsToProcess(-1)To keep the rows and hold the answer as one value, put context("name") in front, then read it with context().prop("name"):
context("brief").fromAi(`Write one sentence for the warehouse team about these order lines.`) .send("customer", "product", "quantity") .returns("headline", "text") .numRowsToProcess(-1)setProp("headline", context().prop("brief").prop("headline"))inputs("name").fromAi(...) writes the answer to a named table instead.
Instructions from a file
Section titled “Instructions from a file”Long instructions can live in a Workspace file. Read the file’s text into a context value and pass that as the instructions:
context("instructions").fromFile("../instructions/order-lines.md")eachRow().fromAi(context("instructions")) .send("customer", "message") .returns("product", "text") .numRowsToProcess(-1)Model, agent, and knowledge
Section titled “Model, agent, and knowledge”| Option | Use |
|---|---|
.model("<model id>") |
Uses that model instead of the deployment’s default; see Models |
.from(agent("<agent id>")) |
Runs the call as one of your agents, with its model, settings, and instructions |
.kgSearch(true) |
Lets the call search the Knowledge Graph |
Check the answer
Section titled “Check the answer”An AI answer is data like any other. Check it in the same node or the next one, and raise an exception on a value you cannot accept, so the export after it waits:
if( not(prop("quantity") > 0), raiseException("quantity") .setProp("severityLevel", 3) .setProp("message", "The quantity is not above zero"))See Exception management for severities and tickets.
Related
Section titled “Related”- Formula: the language, from loading to exporting
- Formula node: node files and every statement
- Templates, queries, and scripts
- Learn by example: every seeded lesson