Skip to content
FJFiras JdayFull Stack Engineer · Tech Lead
AboutServicesProjectsExperienceBlogGet in touch
Back to projects
  1. Home
  2. Projects
  3. n8n SQL Orchestrator Agent: Event Audience Scoring
n8n SQL Orchestrator Agent: Event Audience Scoring
Automation & AI

n8n SQL Orchestrator Agent: Event Audience Scoring

n8n sub-workflow (34 nodes) where an LLM writes the scoring SQL but never touches the database: n8n executes it, returns counts only, and a human validates each audience in a Microsoft Teams Adaptive Card.

Dec 2025 · Automation Architect & Backend Developer

Project overview

The challenge

  • The client needed the right members for each event from about 150,000 users, without hard-coding one filter per use case.
  • Giving a language model database access, or sending it personal data, was not acceptable.

A French professional network needed to pick the right members to invite to each event, from a database of about 150,000 users, without exposing personal data to a language model.

I built the audience-selection sub-workflow in a self-hosted n8n: an orchestrator agent receives the schema, the event theme and the conversation, and generates the SQL; a keyword agent expands job titles; an n8n node holding the credentials executes the query and returns counts only, never personal data.

A Microsoft Teams Adaptive Card shows the targeted count; the user validates, widens the audience step by step (500 → 420 → 350 → 280 points on the client's 1,000-point scoring model) or gives a plain-language instruction.

Technical architecture

Click diagram to zoom

Orchestrator agent: receives the Prisma schema, the event theme, the history and the user's instruction, and writes the SQL.

Keyword agent (GPT-4o-mini): expands job titles into 150–300 variants.

An n8n PostgreSQL node holding the credentials executes the SQL and returns counts only.

A Microsoft Teams Adaptive Card shows the count; free-text instructions go through an n8n web page, because Teams Action.Submit would have required a registered bot.

Key challenges & solutions

1

Measure before you architect

A third "themes" agent was planned; the database held only 24 themes, which fit in the prompt, so two agents were enough.

2

Dynamic SQL instead of fixed tiers

Instead of hard-coding ten widening steps, the agent regenerates the SQL from the conversation, so a new instruction needs no new code.

3

Validation channel constraints

Teams Action.Submit would have needed a registered bot, so free-text input moved to an n8n web page while the counts stay in the Adaptive Card.

Impact & results

The language model never connects to the database: it writes SQL, n8n executes it

Counts only, no personal data sent to the model — GDPR-friendly by design

Human validation in Teams before any audience is used

Rated 5.0 by the client: "Excellent skills, he fixed my n8n workflow in no time"

Key features

  • SQL orchestrator agent: schema + event theme + history → SQL
  • Keyword agent: 150–300 job-title variants across three circles (French and English)
  • n8n node holds the credentials and executes the SQL
  • Counts only — no personal data sent to the model
  • Teams Adaptive Card for validation, with step-by-step widening (500 → 280 points)
  • Plain-language instruction translated into SQL (UNION)
  • Client's 1,000-point scoring model with non-negotiable compliance rules

Technologies used

n8nOpenAI (GPT-4o-mini)PostgreSQLMicrosoft Teams Adaptive CardsSQL

Project gallery

Multi-Agent Orchestration Logic
Multi-Agent Orchestration Logic
Audience Scoring Metrics
Audience Scoring Metrics
Teams Adaptive Card Interface
Teams Adaptive Card Interface

Project details

Client
French client via Upwork (subcontracting)
Timeline
Dec 2025
Role
Automation Architect & Backend Developer

© 2026 Firas Jday · Senior Full Stack Engineer & Tech Lead · Tunis, Tunisia

Available for CDI & senior freelance — French & international market · jdayfiras.com

0%