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
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
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.
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.
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



