Trusted Gateway

Run named read-only PostgreSQL queries.

SQL is saved in the dashboard. The agent selects a query ID and supplies positional parameters; it cannot send arbitrary SQL.

Dashboard fields

  • Named query ID: for example customer_by_id.
  • Query: one SELECT or WITH statement, such as SELECT id, status FROM customers WHERE id = $1.
  • DSN: a PostgreSQL connection string that requires TLS using sslmode=require or ssl=true.

Create the secured tool

from uuid import uuid4

def customer_read(customer_id: str) -> dict:
    """Read one customer through a named read-only query."""
    result = security.execute(
        agent_id="support-agent",
        session_id="support-session",
        action="customer.read",
        arguments={
            "query": "customer_by_id",
            "parameters": [customer_id],
        },
        idempotency_key=f"customer-read-{uuid4()}",
    )
    return result["output"]

Returned data

Output contains rows and a truncated flag. At most 1,000 rows are returned. Parameters are passed separately from SQL.

Backend enforcement

The connector permits saved SELECT/WITH statements only, opens a read-only transaction, applies a statement timeout and closes the connection.

Defense in depth

Give the database account read-only grants too. Validate does not connect to PostgreSQL; run a staging call to prove DNS, TLS, login and grants.