Use AI blocks
AI blocks let an automation work with text: summarize a message, pull fields out of it, or decide which kind of request it is. To use a document, first turn it into text with Extract document text. This guide is for authors adding them to an automation.
Lainstack uses your own AI provider account. You choose the provider and the model, and usage runs on your account with that provider.
1. Connect an AI provider
Section titled “1. Connect an AI provider”- Open Connections and click New connection.
- Under AI, pick your provider:
- OpenAI-compatible AI model, Anthropic-compatible AI model, Gemini-compatible AI model, Azure OpenAI-compatible model or Bedrock-compatible AI model, with your API key or cloud credentials;
- AI gateway, for a gateway your company runs in front of its providers;
- ChatGPT subscription (Codex), which signs in with a ChatGPT account instead of an API key.
- Save it.
The “compatible” kinds also take a base URL, so they work with any service that speaks the same API.
2. Pick the right block
Section titled “2. Pick the right block”| Block | Use it to |
|---|---|
| AI Prompt | Make one call with your instructions and get text back: summarize, rewrite, draft a reply. |
| AI Classify | Put an input into exactly one of 2 to 8 classes you define, then branch on the answer. |
| AI Agent | Work through several steps, use tools, and return typed fields that later blocks can map. |
Every AI block needs a Connection and a Model from that connection.
3. Summarize or draft with AI Prompt
Section titled “3. Summarize or draft with AI Prompt”Write a System prompt with the role and the rules, and a User prompt with the request. Type @ to insert values from the run, such as an email’s text.
The reply comes back as text. Response format can ask for JSON instead, but its fields cannot be mapped directly; when later blocks need individual fields, use AI Agent with an answer shape, described below.
4. Route work with AI Classify
Section titled “4. Route work with AI Classify”- Set the Input, such as the text of a request.
- Add the Classes. Each has a Label and Criteria that say when it applies. Clear criteria that do not overlap matter more than the Instructions.
- Add a catch-all class, such as “Other”. The model must pick one class and cannot answer “none”.
- Add a Switch after the block and give each class its own path.
5. Extract fields with AI Agent
Section titled “5. Extract fields with AI Agent”Set Answer format to Fields and list the Output fields you want, such as a reference number and a date. Later blocks can then map each field with @, like any other block’s output.
To read a file, map it under Files. Read data from a document goes through the whole setup: which files work, how to test, and how to check the answer and send it to a person.
AI Agent can also use tools. Allowed tools, Workspace access and Write access control what it may touch. Maximum steps and the Expense guardrail (USD) stop a run that goes on too long. The guardrail is an estimate, so a single call can go over it.
Check the output before trusting it
Section titled “Check the output before trusting it”Model answers are not deterministic, and every draft run calls the model again.
- Test with real examples, including awkward ones, and read each answer in the run.
- When a wrong answer would be costly, put a person in the loop: send the extracted data to an Approval block with Correct the data.
Runs that used AI show AI usage in the run header, with the tokens used and an estimated cost.