A regional sales manager asks an AI assistant which customers reduced their orders last month. The assistant generates SQL, runs it against PostgreSQL, and summarizes the result. In this hypothetical application, the manager should see only customers in their region.

The team has tested row-level security using the manager’s database role. The assistant, however, connects through a shared service account that owns the customer table. Its answer includes customers from other regions.

I would check the identity used by the query tool before spending time refining instructions about regional access. The database needs an execution identity whose permissions match the caller’s authorized scope.

PostgreSQL’s row-security documentation explains the relevant exception: table owners normally bypass row-level security. Superusers and roles with BYPASSRLS bypass it too. A policy that works for a restricted analyst role can therefore behave differently when the application runs the same SQL.

FORCE ROW LEVEL SECURITY can subject a table owner to row policies. It does not remove the superuser or BYPASSRLS exceptions. For this assistant, I would use a restricted execution role that does not own the tables, and keep ownership with a separate administrative role.

Start the investigation inside the actual query tool, using its connection pool and credentials. This diagnostic SQL is illustrative and has not been run against a deployment:

SELECT session_user, current_user;

Record the result beside the application’s authenticated user and request ID. The two database identities may differ after a role change. Inspect the effective role’s grants, memberships, and applicable policies; the identity query alone does not establish that access is correct.

There is a subtle trap in using one powerful login and switching down to a restricted role. PostgreSQL’s SET ROLE documentation says subsequent role changes are still checked against the session user. Switching roles does not remove the session’s ability to select other roles it is allowed to assume.

That matters when the assistant can submit arbitrary SQL. A privileged connection followed by SET ROLE is insufficient as the containment mechanism. The execution service must control what can run, and its credentials should have no unnecessary route to broader access.

For a pilot with two regional access groups, I would consider separate restricted logins and connection pools. The application would select the pool from authenticated authorization data, before executing any generated SQL. A region mentioned in the conversation would be a query preference, never the authority for choosing credentials.

This costs more connections and more credential administration. It may be unsuitable when access varies across thousands of customers or individual users. In that case, design and review how the application carries authorization into the database explicitly; do not let a convenient shared login become the default access policy.

For the regional pilot, use test customers with recognizable names in both regions. Run the same request through each manager’s application session, including a request for all regions, and inspect the raw tool result. Repeat after connection reuse and a failed query. The pilot is ready for broader use only when the permitted customers remain visible and the other region’s customers never enter the model’s context.