Skip to main content

Your database

"Where is my shipment?", "What's my balance?", "When does my plan renew?" are questions only your database can answer. Sarthi can read it, read-only, and answer each signed-in customer from their own rows only.

Supported: PostgreSQL (9.6+), MySQL (5.7+) and MariaDB (10.4+), SQL Server, and MongoDB (5.0+, including Atlas; see MongoDB).

The promises​

  1. Read-only, proven. Before connecting, Sarthi asks the database what the user may do and refuses one that can insert, update, delete, create or drop anything. It checks again every night, and suspends the connection the moment the user gains a write permission.
  2. Only what you map. Sarthi can only read the tables and columns you tick in the data map, even if the database user could read more.
  3. Each customer, their own rows. Every per-customer table carries a row filter (customer_id = {token.user_id}). Sarthi adds it to every query itself; the AI never writes it and can't leave it out.
  4. Nothing runs without a check. Every query passes a parser and an allow-list (one SELECT, your tables, no writes, no file access, no sub-queries in odd places, nothing your database could read differently from the check), then runs as one statement in a read-only transaction with a time limit. See what the check refuses.
  5. Masks before anything sees a value. Columns marked private are masked (last 4, hidden, hashed) or never read, before the AI, the log or the cache sees them.

1. Create a read-only user​

Ask your developer to create a user that can only read the tables Sarthi may use. The console shows this for your engine (and shows it again if a connection is refused):

CREATE ROLE saarthi_ro LOGIN PASSWORD 'choose-a-long-password' NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT;
GRANT CONNECT ON DATABASE "acme_ops" TO saarthi_ro;
GRANT USAGE ON SCHEMA "public" TO saarthi_ro;
GRANT SELECT ON "public"."shipments" TO saarthi_ro;
-- Repeat the GRANT for each table Sarthi may read.
-- Postgres 14 and older let every user create tables in "public":
-- REVOKE CREATE ON SCHEMA "public" FROM PUBLIC;

Then let Sarthi reach the database: allow Sarthi's addresses (shown on the connection page) in your firewall or Atlas Network Access, and use TLS. "Encryption off" is only for testing on your own network and can't be used in production.

2. Connect​

Knowledge → Databases → Connect a database. Engine, host, port, database, schema (Postgres and SQL Server), the read-only user and its password; for MongoDB, the connection link. Give it a description the AI reads to know when this database can answer ("Shipments of our customers and the routes we run").

Sarthi connects, proves the user is read-only, reads the list of tables and columns, and stores the password in your workspace vault (encrypted, never shown again). A user that can write is refused with the list of what it can do.

3. The data map​

What Sarthi may read, and how customers are kept apart:

SettingMeaning
Tables and columnsTick what the AI may see. Untick anything else. Up to 30 tables, 60 columns each.
Row filterThe column that names the customer, and the matching detail from the token: customer_id = {token.user_id}. Also {token.email}, {token.plan}, {token.attrs.<name>}. One default for all tables, and a different column per table where needed (invoices: client_ref = {token.user_id}).
Shared tablesTables everyone may read, like routes or a price list. Every other table needs a row filter.
MasksPer column: Last 4 (••••1Z5), Hide all, Hash (a stable code), Never read (left out entirely).
Notes and typical valuesA sentence about a table or column ("eta is the promised date, not the actual one"), and sample values ("status: booked, in_transit, delivered"), so the AI writes correct queries. Fill from data fills the typical values for you (below).
FreshnessLive (every question reads the database) or cached for a few minutes (faster, and cached answers cost no credits).
"How I found this"Show visitors the query under the answer, values hidden.
Typical values give the AI your exact spelling

When a column has typical values ("Bank transfer, UPI, Card"), the AI writes your exact spelling in its query. For other text it ignores capital letters, so "orders paid by bank transfer" still finds "Bank transfer". Order numbers, codes and emails are always matched exactly as typed.

Fill from data. Instead of typing typical values, press Fill from data on a table (or Fill all from data for every table). Sarthi reads each ticked text column over your whole table, so even a value only a few rows have is found, and fills its empty Typical values box when the column's values repeat, like a status, a city or a payment method: at most 15 different values, and most of them in more than one row. Most common first, spelled exactly as in your data. Empty values don't count.

  • Nothing you typed is replaced, and nothing is saved until you check the values and save the data map. Filled boxes say "From your data: check, then save".
  • Some columns stay empty, on purpose, with the reason under them: columns where each row has its own value, like names, order numbers or ids ("each value is different, like names or ids", even on a small table with only a few rows), more than 15 different values, values that look like emails or phone numbers, masked and Never read columns, the column that ties rows to a customer, ids and keys, and columns that aren't text. Sarthi never reads the masked or customer columns. Typical values you save go to the AI in every chat, so this errs on the side of leaving a box empty: you can always type values in yourself.
  • Owners, admins and editors can use it, up to 20 times an hour per database, and it costs no credits. A column that takes more than a few seconds is skipped; if time runs out before every column was read, press Fill from data again for the rest.

Per-customer tables are only read for signed-in visitors; anonymous visitors can only get answers from shared tables. On WhatsApp, where nobody is signed in, only shared tables apply.

4. Choose a mode​

ModeWho writes the queryWhen to use it
FixedYou, as templates. Values come from the token only.The safest: "my latest invoice", "my open shipments".
GuidedYou, as templates with blanks the visitor fills: "where is shipment {ref}?".Most businesses. Predictable answers, no surprises.
FullThe AI writes the query from the question; Sarthi checks and rewrites it, and asks the visitor to confirm before running it. Signed-in visitors only.Open-ended questions ("how much did I spend on exports last quarter?"). Needs a query-writing model, set up by Sarthi.

Templates​

A template is one SELECT on your mapped tables with named blanks:

SELECT ref, status, eta FROM shipments WHERE ref = {ref}

For each blank you say what it is (text, number, date, one of a list), where it comes from (the visitor, or the token), and how the assistant should ask for it ("the shipment number"). Add the columns the answer must have and example questions, so the AI picks the right template.

Test it as a pretend customer: the console shows the rows and the exact query that ran, with your row filter added. A template only goes live after a passing test of its current version, and goes back to draft when you change it.

Don't filter by customer in a template; Sarthi adds that itself.

What the check refuses​

The same check covers your templates, Full mode, Ask your data and the Staff assistant. Besides writes, tables and columns outside your data map and unknown functions, it refuses anything your database could read differently from the check:

  • comments, ; and backslashes;
  • text with a letter right before its quote, like E'…' or X'…': write plain '…';
  • names quoted the way another database quotes them: quote names with "…" on PostgreSQL, backticks on MySQL and […] on SQL Server ("…" is refused on MySQL and SQL Server);
  • $ and @ outside text, and ? on MySQL: a template's blanks are written like {ref};
  • numbers run into letters, like 0x1F, and names in other scripts or with accents unless they're quoted.

It also refuses query shapes that could reach a hidden or masked value:

  • LIMIT or OFFSET with anything but a plain number or a template's blank, and TOP with anything but a plain number;
  • TABLESAMPLE, table hints like WITH (NOLOCK), FOR JSON, NATURAL JOIN and window functions;
  • a whole row, like concat(s.*) or a table's alias on its own;
  • column names after a table's alias, like shipments s(a, b);
  • a name given with AS anywhere but ORDER BY or GROUP BY (in HAVING, for example);
  • in Full mode, a masked column inside a function, a calculation, CASE or an aggregate (like count(phone)): it can only be shown as it is;
  • any part of a query the check doesn't know yet.

The console names the problem in plain words when you save or test. A template that uses one of these is refused when it runs, and goes back to draft the next time the data map is saved, so test your templates if you're unsure.

What a visitor sees​

The assistant answers in plain words from the rows ("AC 20931 is in transit, arriving 12 October"). If nothing matches on their account, it says so instead of guessing. In Full mode it first asks "Shall I look up: shipments on your account from the last 30 days?" with Yes / No buttons; a correction ("no, only Surat") gets one redraft.

Safety nets​

  • A connection whose queries fail 5 times in a row is marked failing and you are emailed; it keeps answering for a day, then stops until a test passes. Sarthi tests it again by itself, about 20 minutes after it started failing, then 40 and 80 minutes after that, then every 2 hours, so a database that was down for a while (a server asleep at night) is back in use as soon as it answers.
  • Each query has a time limit (3 seconds by default), a row cap (100), a join cap (2) and a per-chat cap (20 look-ups); you can lower them per connection.
  • The query log shows every query proposed, run or refused, for which chat and why, with customer ids masked. It never keeps the rows.
  • The test console asks "what would Sarthi do with this question, for this customer?" and shows all three modes side by side before you go live.

Costs​

One credit per database look-up; cached answers are free. Writing the query in Full mode uses a model call like any reply.