m4Mindset docs

Docs / AMS / Connect / Connect a database or sheet

View as Markdown

Connect a database or sheet

Connect a Postgres database or a Google Sheet, enable the queries or ranges your agent needs, and see real rows before anything calls them.

After this page a Postgres database or a Google Sheet is connected, the queries your agent needs are enabled, and you've seen real rows come back.

What this is

TypeUse it forThe invoice workflow
Postgres databaseLookups and joins over more data than a sheet holdsSupplier payment terms and two years of invoice history
Google SheetA small table a person also maintains by handHow much price variance each supplier is allowed

Neither type is on the + New connection shortlist. Choose Describe it to the builder and tell the Connection Builder what you're connecting, for example "a Postgres database with our supplier payment terms".

Connect a Postgres database

How to connect it

  1. Connections → + New connection → Describe it to the builder. Say it's a Postgres database and what the agent needs from it.
  2. When the builder asks, enter the Connection string (DSN) in the Enter a secret value form. The builder never sees it.
  3. The builder reads the tables and checks what your database login is allowed to do.
  4. Agree the queries with the builder. Each one is a fixed, parameterized SQL statement, enabled one at a time.

Enabling a query

Two checks run before a query is enabled:

  • Your login's privileges are checked first. If it can't read the suppliers table, enabling stops and gives you the exact GRANT statement to send to whoever owns the database.
  • Then the query runs on the live database inside a transaction that is rolled back. You see real rows, and the database is left as it was. That's true for a query that writes, too.

How queries are classified

Each query is marked read or write when it's enabled. Mindset doesn't parse the SQL to decide. The boundary is the database login's own privileges, so give a connection that must never write a login that can't write.

Make it available

An enabled query is available to functions to start with. To let an agent call it directly, tick Available to agents on the connection. That needs a description for the query and for each of its parameters.

Try it

The Query console tab runs a query and shows the result. Use it to check a value you can verify elsewhere.

Connect a Google Sheet

How to connect it

  1. Connections → + New connection → Describe it to the builder. Say it's a Google Sheet and which spreadsheet.
  2. When the builder asks, enter the Service-account key (JSON) for a Google Cloud service account.
  3. Share the spreadsheet with that service account's email address in Google Sheets, so it can read it.

Its two operations

A Google Sheet connection has two fixed operations. There's nothing to discover.

OperationWhat it doesKind
get_rangeReads a rectangle of cellsRead
append_rowAdds rows to the end of a rangeWrite

So it's also a place to drop the month's exceptions for finance to look at. For how a write is approved, see Approve what an agent can do.

Try it

The Data preview tab reads the sheet. Check that the column headers are the ones the workflow expects.

Response samples and tested status

Each operation shows Tested or Untested. A query passes its rolled-back test run when it's enabled. On the Operations tab, Show recent responses shows what recent real calls returned. See Test before it goes live.

Change it later

On the Settings tab you can change the name and description. The credential is replaced from its field there: Replace credential swaps in a new value without interrupting the connection, and Remove credential stops it working at once.

What can go wrong

Enabling fails on a database query. Read the error. It names the privilege your login is missing and gives you the GRANT statement for the database owner.

The sheet reads as empty or refuses access. The spreadsheet isn't shared with the service account's email address.

A query works in the console and an agent still can't call it. It's available to functions only. Tick Available to agents, or call it from a function.

The numbers are right but from the wrong database. Check the connection string points at the database you meant, not a copy. See Check you reached the right account.

You're done when

  • Each query or range the workflow needs is enabled, and you saw its real rows.
  • You checked one value against what the person who owns the data sees.
  • The database login can do only what the queries need.