Guides5 min read· 23 Nov 2026

Safely Connecting an AI Assistant to PostgreSQL and MongoDB with Table Allowlists and Email OTP

Learn how to connect PostgreSQL and MongoDB to an AI assistant without exposing full schemas—using read-only roles, explicit allowlists, 6-digit Email OTP gating, and HMAC-SHA256 webhooks.

Written by Servunio Team· Platform Engineering

Why direct database access fails without strict boundaries

Teams building customer-facing assistants often want answers backed by live operational data: real-time stock levels, project milestone statuses, or open service ticket updates. Giving a language model raw SQL or unrestricted query generation against a production database creates unacceptable risk. Even a read-only database user can leak internal notes, employee records, or billing tables if schema visibility is left wide open.

Servunio AI (servunio.com), operated by BigBurry Hypersystems LLP, approaches database connectivity through four layered controls:

  • Dedicated read-only credentials: Encrypted connection strings bound to least-privilege PostgreSQL roles or MongoDB users with read-only permissions.
  • Explicit allowlists (allowedTables): Only tables or collections you explicitly approve can be inspected or queried—everything else stays invisible to the connector.
  • Automated schema sync to the Knowledge Base: Sanitized metadata from allowlisted tables syncs into your assistant's grounding context so it knows exact field names rather than guessing.
  • 6-digit Email OTP verification: Customer-specific lookups—such as booking.update, ticket.read, quote.status, or project.status.read—stay gated behind a verified 6-digit Email OTP session (configurable from 5 to 120 minutes).

You can review the full connector workflow in the databases and webhooks guide and inspect the endpoint schemas in the API reference.

Designing read-only PostgreSQL and MongoDB allowlists

Before pasting a connection string into the Dashboard, create a dedicated database principal scoped strictly to the tables or collections your assistant needs. Never reuse an application admin user, reporting superuser, or migration role.

For PostgreSQL, grant USAGE on the target schema and SELECT only on the specific views or tables that belong in allowedTables. Using a curated SQL view is even cleaner when a base table mixes public catalog fields with internal margin columns, supplier cost notes, or raw PII. For MongoDB, create a custom role restricted to find actions on named collections rather than granting readAnyDatabase or broad metadata privileges across administrative collections.

When preparing those views or collections, verify that timestamp fields, status enums, and primary identifier columns use predictable names so both the Knowledge Base schema sync and your prompt instructions stay unambiguous. Avoid exposing free-text internal operator comment fields unless they are sanitized for customer display.

Control LayerExposed to AssistantBlocked by DefaultOperational Purpose
Database RoleRead-only SELECT / findINSERT, UPDATE, DELETE, DDLPrevents any state mutation through the connector
allowedTables ListExplicitly approved tables or collectionsUnlisted tables, system catalogs, audit logsEliminates accidental schema discovery across internal tables
Public Catalog LookupsProduct specs, stock counts, pricing tiersCustomer emails, phone numbers, account notesSupports catalog.search, catalog.compare, and inventory.read safely
Account-Scoped RecordsStatus rows matching verified emailUnverified cross-customer rows or bulk exportsEnforces customer.verify 6-digit Email OTP before disclosure

When you add or update an allowlisted table, Servunio runs an automated schema sync that maps permitted field names and types into the assistant's Knowledge Base. That keeps capabilities such as inventory.read and project.milestones.read grounded in real column names while keeping unapproved tables completely off-limits. See Servunio Security for details on credential encryption, TLS transport, and tenant isolation.

Gating customer lookups with 6-digit Email OTP

Catalog, pricing, and availability questions rarely need authentication, but account-level lookups always do. Asking a visitor to type an email address into chat is not verification—anyone can type a colleague's or competitor's email address to fish for order or project updates.

Servunio's customer.verify capability enforces cryptographic identity checks inside the conversation flow:

  • The assistant prompts for the visitor's email address whenever an action requires account verification—such as checking quote.status, reading ticket.read, inspecting project.status.read, or modifying a booking with booking.update or booking.cancel.
  • Servunio dispatches a 6-digit Email OTP with a 10-minute code expiry and bounded attempt lockouts.
  • Once the visitor confirms the 6-digit code, the connector authorizes scoped lookups tied to that verified email across a configurable window between 5 and 120 minutes.
  • Queries outside that verified identity remain blocked, eliminating cross-customer enumeration across shared tables.

To see how capability gating fits alongside bookings, tickets, and catalog comparison, explore Servunio Features.

Forwarding mutations through HMAC-SHA256 webhooks

Because database connectors are strictly read-only, writes stay cleanly separated in your own backend, CRM, n8n workflow, or Zapier integration. Whenever an assistant triggers a structured event—such as lead.capture, booking.create, quote.request, ticket.create, or complaint.capture—Servunio dispatches a signed JSON webhook payload.

Every outbound webhook includes four standard verification headers:

  • X-Servunio-Signature: The HMAC-SHA256 hex digest computed over the timestamp and raw JSON request body.
  • X-Servunio-Timestamp: Unix timestamp used to reject stale replay requests outside your tolerance window.
  • X-Servunio-Delivery: Unique delivery identifier for idempotent event handling in your worker queue.
  • X-Servunio-Event: Event name matching the triggered capability workflow.

Servunio also supports dual-secret rotation so your receiver can verify signatures against both the active primary secret and a retiring secondary secret during key rollovers with zero dropped deliveries. Below is a concise TypeScript verification handler for Node.js receivers:

ts
import { createHmac, timingSafeEqual } from "node:crypto";

export function verifyServunioWebhook(
  rawBody: string,
  signatureHeader: string,
  timestampHeader: string,
  secrets: string[],
): boolean {
  const ageSeconds = Math.abs(Math.floor(Date.now() / 1000) - Number(timestampHeader));
  if (!Number.isFinite(ageSeconds) || ageSeconds > 300) {
    return false;
  }

  const providedHex = signatureHeader.replace(/^sha256=/, "");
  const providedBuf = Buffer.from(providedHex, "hex");

  return secrets.some((secret) => {
    const expectedHex = createHmac("sha256", secret)
      .update(`${timestampHeader}.${rawBody}`)
      .digest("hex");
    const expectedBuf = Buffer.from(expectedHex, "hex");
    return providedBuf.length === expectedBuf.length && timingSafeEqual(providedBuf, expectedBuf);
  });
}

Rollout checklist for production teams

Start with the smallest viable allowedTables set—typically one public catalog view and one customer status view—and verify every field returned during sandbox testing. For programmatic automation or CI verification, pair webhooks with scoped API keys (sv_live_...) or OAuth2 tokens following the OpenAPI 3.1 contract in /docs/api. Before connecting production databases, test an assistant live on servunio.com/demo and read verified customer reviews on Trustpilot.

Ready to deploy your grounded AI receptionist?

Start a cardless 14-day free trial with your documents, booking forms, and live team inbox in minutes.