Skip to main content

How to build AI workflows in Retool

Overview

AI workflow automation uses large language models to handle tasks that traditionally require human judgment. Learn how to build your own AI-powered workflow in Retool in this step-by-step walkthrough.

AI workflow automation combines large language models with structured processes to handle complex tasks that traditionally require human judgment. Instead of manually categorizing data, routing requests, or analyzing content, you can build AI workflows that make intelligent decisions at scale.

In this tutorial, you'll learn how to build AI workflows in Retool by creating an AI-powered support ticket classifier. We'll connect AI models to your data, add intelligent decision-making, and deploy an end-to-end automation that routes tickets to the right teams automatically.

Understanding AI workflow automation in Retool

Before building AI workflows, it's important to understand how AI-powered automation differs from traditional automation tools.

Traditional workflows

Traditional workflows execute predefined steps automatically—querying databases, running code, and triggering actions based on fixed rules. Traditional workflows are perfect for handling ETL tasks and scheduled jobs where the logic never changes.

Generative AI workflows

GenAI workflows incorporate AI models at specific steps to analyze content, make decisions, or generate text. The AI generates intelligent outputs, but you control the overall automation workflow. AI workflows are ideal for handling tasks like content classification, sentiment analysis, or data enrichment where AI systems provide insights within a structured process.

Agentic workflows

Agentic workflows (what we'll build) use AI models to inform control flow decisions. Instead of just generating content, the AI decides which path the automation workflow should take. This is ideal for processes that require intelligent routing, conditional logic based on content analysis, or decision-making at specific points in a workflow.

How to build an AI workflow in Retool

We'll build an automation workflow that uses AI models to classify support tickets and route them to the appropriate teams. This demonstrates how to build AI into real-time processes with structured data flows.

What we're building: A webhook-triggered workflow that receives ticket data, uses AI to classify it (Billing, Technical, or General), sends notifications to the right team, and updates the database.

Pre-build step: Download the sample data

To follow along with this tutorial, you'll need sample support ticket data. Download the sample tickets CSV which contains 15 realistic support tickets with a mix of billing issues, technical problems, and general inquiries.

Once downloaded, you have two options for using this data:

Option 1: Use Retool DB (easiest)

    1.
  1. In Retool, navigate to Resources > Retool Database
  2. 2.
  3. On the left, click the plus button to add a new table called support_tickets
  4. 3.
  5. Click Import from CSV and upload the sample data file
  6. 4.
  7. Name the new table support_tickets—Retool will automatically detect the columns and data types

Option 2: Use your own database

    1.
  1. Create a table in your PostgreSQL, MySQL, or other database with columns: ticket_id, description, customer_email, status, created_at, category
  2. 2.
  3. Import the CSV data using your database's import tools
  4. 3.
  5. Ensure your database is connected as a resource in Retool

Step 1: Create your workflow and configure triggers

Navigate to the Workflows tab, and click Create new > Workflow. You'll see a canvas with a single startTrigger block—this is where every workflow begins.

Click the workflow name at the top (it defaults to "My First Workflow") and rename it to AI Support Ticket Classifier.

An "AI Support Ticket Classifier" workflow in Retool with JavaScript code and trigger settings, over a cartoon landscape background.

Now configure how this workflow will run. Click Edit triggers in the startTrigger block to open the Triggers tab.

Enable the Webhook trigger. Retool generates a unique webhook URL that looks like https://api.retool.com/v1/workflows/[workflow-id]/startTrigger. This endpoint can be called by your ticketing system, a form submission, or any service that needs to trigger the workflow.

In the "Test JSON Parameters" field, add sample data that mimics what your webhook will receive:

{ "ticket_id": "TICKET-001" }

This test data lets you run the workflow manually during development.

Step 2: Fetch ticket data from your database

Now we need to retrieve the ticket information from our database.

Remove the default code block from your workflow.

Click the + button in the toolbar or drag from the startTrigger block to create a new block, then select Resource query as the block type. Rename it to fetchTicket.

Change the resource type to match where you stored your sample data (Retool Database or your connected database), then write this SQL query:

SELECT * FROM support_tickets 
WHERE ticket_id = '{{ startTrigger.data.ticket_id }}'
AND status = 'unclassified'
An AI support ticket classifier workflow in Retool, showing a 'startTrigger' component with sample JSON ticket data and a 'ReturnTicket' component with a SQL database update query.

The {{ startTrigger.data.ticket_id }} syntax references data from the previous block. Any block can access data from earlier blocks using {{ blockName.data }}.

To test the query's output, use the play button located on the top right-hand corner of the block and you'll see the results underneath the query.

Step 3: Add AI classification

This is where AI powers the workflow. Drag from the green circle on the fetchTicket block to create a new block, select AI Action, and rename it to classifyTicket.

Retool provides several AI text actions (Generate text, Summarize text, Classify text, Extract entity). For our use case, select Classify text—it's designed to analyze text and assign it to predefined categories.

Input: {{ fetchTicket.data[0].description }} (The [0] accesses the first row since SQL queries return arrays)

Classification labels: Add three labels pressing enter after each entry:

  • Billing
  • Technical
  • General

Model: Select GPT-4 for highest accuracy, or GPT-3.5 for faster processing. For this tutorial, GPT-3.5 works well.

A Retool workflow titled "AI Support Ticket Classifier" showing a workflow with an event trigger, a database insert query, and an AI text classification module.

Retool provides native integrations with OpenAI, Anthropic, Azure, and Amazon Bedrock. Token costs are included with Retool's built-in models.

Click the play button to test. You'll see output like {"category": "Billing"}. Try changing the ticket_id in your test parameters (TICKET-002, TICKET-003, etc.) to see how AI classifies different ticket types.

Step 4: Route tickets with conditional logic

Now we'll route tickets to the appropriate teams based on the AI's classification. Drag from classifyTicket to create a Branch block and rename it routeByCategory.

Branch blocks let you build conditional logic visually without writing if/else code. The AI's output determines which path the workflow takes—this is what makes it an "agentic workflow."

Set up conditions:

If: classifyTicket.data.category === "Billing"

Else if: classifyTicket.data.category === "Technical"

Else: Handles "General" tickets

A routing step in Retool titled "routeByCategory" displays If/Else If conditions checking "classifyTicket.data.category" for "Billing" and "Technical" on a grid background.

For each path, add a Resource query block set to Retool Email:

Billing path:

  • Block name: notifyBillingTeam
  • To: billing-team@yourcompany.com
  • Subject: New Billing Ticket: {{ fetchTicket.data[0].ticket_id }}
  • Body (Markdown):
**Ticket ID:** {{ fetchTicket.data[0].ticket_id }}
**Customer:** {{ fetchTicket.data[0].customer_email }}

**Description:** {{ fetchTicket.data[0].description }}

Technical path:

  • Block name: notifyTechTeam
  • To: tech-support@yourcompany.com
  • Subject: New Technical Support Ticket: {{ fetchTicket.data[0].ticket_id }}
  • Body: Similar markdown with adjusted wording

General path:

  • Block name: notifyGeneralTeam
  • To: support@yourcompany.com
  • Subject: New General Inquiry: {{ fetchTicket.data[0].ticket_id }}
  • Body: Similar markdown with adjusted wording
Conditional routing in Retool: 'routeByCategory' sends tasks to 'notifyBillingTeam' if 'Billing', 'notifyTechTeam' if 'Technical', or 'notifyGeneralTeam' otherwise.

Step 5: Update the database and add error handling

After all three notification paths, add a Resource query block named updateTicketStatus. Connect all three notification blocks to this update block—it will wait for the notification to send before updating the database.

Set the resource type to your database and write this UPDATE query:

UPDATE support_tickets
SET status = 'classified',
    category = '{{ classifyTicket.data }}'
WHERE ticket_id = '{{ fetchTicket.data[0].ticket_id }}'

Adding error handling

Drag a Resource query block onto the canvas without connecting it to anything. Rename it errorHandler, click the ••• menu, and select Add global error handler.

A visual workflow builder for an AI Support Ticket Classifier, showing a 'Blocks' sidebar and a database update node with SQL code.

Change the resource type to Retool Email and configure it to send you an alert if the workflow fails:

  • To: Your email address
  • Subject: Workflow Failed: AI Ticket Classifier
  • Body: Include basic error details

This ensures you'll be notified immediately if something goes wrong.

Step 6: Test, deploy, and monitor

Once you’ve completed all these steps, it’s time to test, publish, and monitor your workflow.

Test your workflow

Click the ••• menu on your updateTicketStatus block, then select Run with previous blocks. Watch each block execute and verify the correct team receives a notification. Check your email to confirm.

To test different ticket types, edit the test parameters in your trigger and change the ticket_id to "TICKET-002" (technical) or "TICKET-003" (general), then run again.

Deploy

Click Publish release in the toolbar. Retool creates a versioned release and your workflow is now live. The webhook endpoint will automatically process any POST requests it receives.

Configure your ticketing system to send webhook POST requests to your Retool endpoint whenever new tickets are created.

For production workflows, consider enabling workflow protection. This adds a safety lock that prevents anyone—including admins—from accidentally editing or deleting the workflow. To enable it, click the ••• menu in the toolbar and select Protect workflow.

Monitor

View execution logs by clicking the Run history icon in the toolbar. Each log shows input data, output from every block, execution time, and any errors. This visibility is crucial for debugging misclassifications or failures.

What’s next?

You've built an AI-powered automation that classifies support tickets and routes them intelligently. This same pattern works for countless other use cases: sales lead qualification, content moderation, document processing, customer feedback analysis, and data enrichment.

The key is identifying processes where humans currently make decisions based on analyzing content—those are prime candidates for AI workflow automation.