Skip to main content

A/B test AI prompts with Supabase, Langchain Agent & OpenAI GPT-4o

Workflow preview

Workflow preview
100%
A/B test AI prompts with Supabase, Langchain Agent & OpenAI GPT-4o preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

Split Test AI Prompts Using Supabase & Langchain Agent This workflow allows you to A/B test different prompts for an AI chatbot powered by Langchain and OpenAI. It uses Supa...

Best for

  • Engineering automation workflows
  • AI Chatbot automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

@n8n/n8n-nodes-langchain.chattrigger, @n8n/n8n-nodes-langchain.agent, n8n-nodes-base.supabase, n8n-nodes-base.if, n8n-nodes-base.set, @n8n/n8n-nodes-langchain.lmchatopenai, @n8n/n8n-nodes-langchain.memorypostgreschat, n8n-nodes-base.stickynote

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by vanhon.

Original n8n.io source

1.1 Workflow description

Title
A/B test AI prompts with Supabase, Langchain Agent & OpenAI GPT-4o
Workflow name
A/B test AI prompts with Supabase, Langchain Agent & OpenAI GPT-4o

Split Test AI Prompts Using Supabase & Langchain Agent

This workflow allows you to A/B test different prompts for an AI chatbot powered by Langchain and OpenAI. It uses Supabase to persist session state and randomly assigns users to either a baseline or alternative prompt, ensuring consistent prompt usage across the conversation.

๐Ÿง  Use Case

Prompt optimization is crucial for maximizing the performance of AI assistants. This workflow helps you run controlled experiments on different prompt versions, giving you a reliable way to compare performance over time.

โš™๏ธ How It Works

  1. When a message is received, the system checks whether the session already exists in the Supabase table.
  2. If not, it randomly assigns the session to either the baseline or alternative prompt.
  3. The selected prompt is passed into a Langchain Agent using the OpenAI Chat Model.
  4. Postgres is used as chat memory for multi-turn conversation support.

๐Ÿงช Features

  • Randomized A/B split test per session
  • Supabase database for session persistence
  • Langchain Agent + OpenAI GPT-4o integration
  • PostgreSQL memory for maintaining chat context
  • Fully documented with sticky notes

๐Ÿ› ๏ธ Setup Instructions

  1. Create a Supabase table named split_test_sessions with the following columns:
    • session_id (text)
    • show_alternative (boolean)
  2. Add credentials for:
    • Supabase
    • OpenAI
    • PostgreSQL (for chat memory)
  3. Modify the "Define Path Values" node to set your baseline and alternative prompts.
  4. Activate the workflow.
  5. Send messages to test both prompt paths in action.

๐Ÿ”„ Next Steps

  • Add tracking for conversions or feedback scores to compare outcomes.
  • Modify the prompt content or model settings (e.g. temperature, model version).
  • Expand to multi-variant tests beyond A/B.

๐Ÿ“š Learn More

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - When chat message received

Type / Role
@n8n/n8n-nodes-langchain.chatTrigger - chatTrigger
Config choices
Version 1.1

Block 2 - AI Agent

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 1.7

Block 3 - Check If Session Exists

Type / Role
n8n-nodes-base.supabase - supabase
Config choices
Version 1

Block 4 - If Session Does Exist

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 5 - Assign Path To Session

Type / Role
n8n-nodes-base.supabase - supabase
Config choices
Version 1

Block 6 - Define Path Values

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 7 - OpenAI Chat Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1.2

Block 8 - Postgres Chat Memory

Type / Role
@n8n/n8n-nodes-langchain.memoryPostgresChat - memoryPostgresChat
Config choices
Version 1.3

Block 9 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 10 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 11 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 12 - Get Correct Prompt

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 13 - Sticky Note6

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 14 - Sticky Note8

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 15 - Sticky Note5

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 16 - Sticky Note3

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

3. Summary Table

Workflow A/B test AI prompts with Supabase, Langchain Agent & OpenAI GPT-4o
Complexity advanced
Nodes 16
Categories Engineering, AI Chatbot
Author vanhon
Published 21 Sept 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/8790/8790.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does A/B test AI prompts with Supabase, Langchain Agent & OpenAI GPT-4o do?

Split Test AI Prompts Using Supabase & Langchain Agent This workflow allows you to A/B test different prompts for an AI chatbot powered by Langchain and OpenAI. It uses Supa...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Engineering, AI Chatbot use case.