---
title: "AI in workflows: generate, extract, classify and decide"
description: "Use AI in a Softr workflow to write, summarize, categorize, run your own prompt or decide on a path, with Softr AI or with your own AI provider API key."
canonical: "https://docs.softr.io/workflows/ai"
updated: "2026-12-04"
---

# AI in workflows: generate, extract, classify and decide

AI steps read text and data in a workflow and write, summarize, categorize or decide. Use them to draft replies, sort incoming requests, enrich records or route a run.

## AI steps

| Step                | What it does                                                                                                                                                                    |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Write**           | Writes text from your instructions, such as a reply or a description                                                                                                            |
| **Summarize**       | Shortens a text to its key points                                                                                                                                               |
| **Categorize**      | Puts a text into one of the categories you list                                                                                                                                 |
| **Custom prompt**   | Runs your own prompt, with free text or a structured answer                                                                                                                     |
| **Make a decision** | Answers yes or no, picks one option from a list, or gives a score, to route the run. OpenAI step, from 2 to 255 options or 2 to 10 score levels                                 |
| Image steps         | Create an image from a prompt: **Generate image (Image 2)** in OpenAI, **Nano Banana 2 (image)** in Gemini, and **Flux via Replicate** and **Pruna via Replicate** in Replicate |

To read a PDF or a web page before an AI step, use **Extract PDF** or **Scrape webpage**. See [Steps](/workflows/steps).

![A Categorize step on Softr AI: the model Claude Haiku 5.5, the text to categorize from the request, and the Categories Billing, Technical and Sales, outlined](/workflows/ai/categorize.2x.webp)

## Softr AI or your own provider

Each AI step runs on **Softr AI** or on your own account with an AI provider:

- **Softr AI** runs models from OpenAI, Anthropic, Google and Mistral, and uses your workspace's AI credits.
- **Your own key** for OpenAI, Anthropic, Gemini, Mistral or DeepSeek bills your provider account directly. Connect the account as an integration first. AI steps on your own key need the Business plan or above.

## Choose a model

Pick the model by the task. The most capable model costs more credits and slows the workflow down, so avoid it on every step.

| Task                               | Model to start with    |
| ---------------------------------- | ---------------------- |
| Classify and route                 | A small, fast model    |
| Write, summarize, extract data     | A mid-size model       |
| Reason over many steps, write code | The most capable model |

> **Tip**
>
> Start with the smallest model that could handle the task. Run a few tests and compare outputs. Move to a more capable model only if the quality falls short.

![The model list of a Categorize step on Softr AI, with what each model is best for and its credit cost](/workflows/ai/model-list.2x.webp)

## Get a structured answer

By default, AI steps return free text. That works for writing content, but the format can vary, so it is hard to use in a **Branch** condition or a record update.

Turn on **Structured output** to get a JSON object with typed fields instead. You can then branch on it, store single fields, or pass specific values to later steps.

To turn it on:

1. In a **Custom prompt** step, with Softr AI or your own key, turn on **Structured output**.
2. Provide a JSON schema that describes the fields and types you expect.

Structured output needs Softr AI 1.3.0 or later, or OpenAI and Anthropic 1.2.0 or later. Every version of Gemini and Mistral has it.

![A Custom prompt step that checks a discount request, with Structured output on and a JSON schema with followsPolicy and reason, outlined](/workflows/ai/structured-output.2x.webp)

This schema categorizes customer feedback with a confidence score:

```json
{
  "type": "object",
  "properties": {
    "category": {
      "type": "string",
      "enum": ["bug", "feature_request", "billing"]
    },
    "confidence": {
      "type": "integer",
      "description": "Confidence score from 0 to 100"
    }
  },
  "required": ["category", "confidence"]
}
```

With this schema, the AI returns exactly two fields, `category` and `confidence`, that you can use in later steps.

![The Testing tab of the Custom prompt step, with the result of a test: followsPolicy true and the reason](/workflows/ai/test-result.2x.webp)

> **Tip**
>
> For a simple classification into set categories, **Categorize** needs no JSON schema. Use **Custom prompt** with **Structured output** when you need several fields, such as a category and a confidence score.

## How an AI step ends

**Custom prompt**, **Write**, **Summarize** and **Categorize** have two outputs:

- `result`: the answer of the model.
- `outcome`: how the model ended the answer. Use it in a **Branch** to handle an answer that is not complete.

| `outcome`   | The step                                       | What happened                                                                                |
| ----------- | ---------------------------------------------- | -------------------------------------------------------------------------------------------- |
| `COMPLETED` | Succeeds                                       | The model finished its answer.                                                               |
| `TRUNCATED` | Succeeds, with the answer so far               | The answer reached the output limit and stops in the middle.                                 |
| `FILTERED`  | Fails, and keeps the answer so far in `result` | The safety or content filter of the provider declined the prompt or stopped the answer.      |
| `NO_ANSWER` | Fails                                          | The provider sent no answer at all. Usually it declined the prompt before it wrote anything. |
| `OTHER`     | Fails, and keeps the answer so far in `result` | The answer stopped for another reason, such as a tool call that the model could not make.    |
| `UNKNOWN`   | Succeeds                                       | The provider gave no reason.                                                                 |

When the step fails, the run details show one of these messages:

- `FILTERED`: "The AI provider declined the prompt or stopped the answer with its safety or content filter. Change the prompt and try again."
- `NO_ANSWER`: "The AI model returned no answer. The provider may have declined the prompt. Change the prompt and try again."
- `OTHER`: "The AI model stopped before it finished the answer (finish reason: ...)." The reason of the provider replaces the dots.

A cut-off answer is a success, so the workflow continues. To catch it, add a **Branch** after the AI step that checks whether `outcome` is `TRUNCATED`. With **Structured output** on, a cut-off answer is not valid JSON, so the step fails instead. The message is "The AI response was cut off because it reached the maximum output length. Please ask for a shorter response or split the request into smaller steps."

Mistral gives no signal when it declines a prompt. A Mistral refusal is a normal answer with the outcome `COMPLETED`.

## Route a run with AI

Let an AI step classify or analyze data, then use a **Branch** to route the run on the result.

### Route on a category

```mermaid
flowchart LR
  A[Record added to Feedback] --> B[Categorize: Bug or Feature request]
  B --> C{Category is Bug?}
  C -->|Yes| D[Post in #bugs and update the record]
  C -->|No| E[Post in #feature-requests and update the record]
```

The **Categorize** step outputs a `category` value. The **Branch** checks it and sends the run down the matching path. Each path can notify a different team and update the record with the category.

### Route on confidence

For more control, use a **Custom prompt** with **Structured output** that returns a category and a confidence score. Then branch on the confidence:

```mermaid
flowchart LR
  A[New support ticket] --> B[Custom prompt: category and confidence]
  B --> C{Confidence 70 or more?}
  C -->|Yes| D[Assign to the team and update the record]
  C -->|No| E[Ask a reviewer in Slack]
  E -->|Approve| F[Update the record with the AI category]
  E -->|Override| G[Update the record with the reviewer's category]
```

The AI handles the clear cases, and a person reviews the unclear ones. See [Human in the loop](/workflows/human-in-the-loop) for the review step.

## Send only the records that matter

Sending all your records in one AI prompt is expensive and slow, and the answer is often worse because the AI has too much to sift through.

Instead, use two passes. A small AI model first picks the relevant records, and the workflow passes only those records to the main AI task.

```mermaid
flowchart TD
  A[New task arrives] --> B[Find multiple records: all items of the knowledge base]
  B --> C[Run custom code: keep the ID and title of each record]
  C --> D[Custom prompt, small model: pick the relevant IDs]
  D --> E[Loop: get the full content of each selected record]
  E --> F[Custom prompt, larger model: complete the task with these records]
  F --> G[Store the result]
```

The first pass is cheap, because a small model reads short titles and picks the relevant ones. The second pass is focused, because the larger model receives only the few records that matter. The total cost is lower than one large prompt.

For example, you keep 50 marketing insights in a database, and a user asks for a LinkedIn post about one product. The workflow sends the 50 titles to a small model, which picks "LinkedIn post framework", "Product X specs" and "Brand voice guidelines". The workflow then fetches those 3 records and passes them to a larger model to write the post.

## Credits

AI steps on Softr AI use AI credits, based on the size of the prompt and the answer. A step that fails still uses credits for the tokens that the provider reports. Each run shows the credits it used. See [AI credits](/admin/ai-credits).
