Key takeaway
Start read-only: a dedicated account, limited schemas and columns, parameterized queries, timeouts, and row caps. AI generates queries; template checks or approval execute them. Results state the data cutoff and definitions, and sensitive fields are masked. Writes stay out of phase one; no permission workaround.

Take this illustrative scenario. Sales asks AI: "Find last week's customers, sorted by amount." AI generates SQL, connects to the database, executes, and returns results. Everything is smooth. A later security review discovers the account connects to production and holds write permission. If someone had asked AI to "also mark this customer as closed," it might have done that too.
Letting AI query a business database has direct value: no waiting for a report queue, and business users get data in natural language. The risk is equally direct: a vague sentence can become a full table scan, or even an update. The right starting point is read-only, and not merely a label on the account.
Read-only is a set of boundaries, not one button
Read-only has at least four layers: account privileges, database session mode, network and connection scope, and application-level query limits.
Account privileges decide which databases, tables, and views are reachable. Session mode adds another limit. In PostgreSQL, for example, SET TRANSACTION READ ONLY restricts INSERT, UPDATE, DELETE, MERGE, and COPY FROM against non-temporary tables, along with several DDL operations. Check temporary-object details in the documentation for the deployed version. The documentation also notes this is a high-level notion of read-only that does not prevent all writes to disk.
Read-only mode is therefore one layer of defense, not the only one. The account itself must lack write privileges, the network must allow connections only from a designated service, and the application must restrict query types.
Accounts and data scope
Create a dedicated account for AI queries; never reuse an administrator, reporting, or personal account. Grant only necessary read privileges, and expose data through views rather than entire tables.
Views can pre-limit columns and rows: hide phone numbers, identity numbers, bank accounts, and cost prices; keep only the columns business queries need. Even necessary sensitive fields should be masked at the result layer or shown by role.
Permissions follow people. When a business user changes role, the AI query account's scope should not persist unchanged; review regularly who uses it and what they query.
Query generation and execution
Do not execute AI-generated SQL directly in production. A safer pattern: AI generates a parameterized query, a template check or a person reviews it, and only then does it run.
Parameterization prevents user input from being concatenated into SQL and keeps the query scope controlled. Template checks limit allowed tables, columns, aggregations, and sort fields. Queries outside the template go to human review instead of unrestricted execution.
If the system supports natural-language querying, record generation and execution separately: who asked, what was generated, who approved, and what result came back.
Cost: timeouts, row caps, frequency
An unbounded query can scan the entire order table and slow production during peak hours. Set:
- Timeout: terminate after an agreed number of seconds.
- Row cap: return the first N rows by default and indicate more exist.
- Concurrency and frequency: limit queries per account or user.
- Read replica: query a replica where possible to reduce load on the primary.
The specific values depend on database capacity and peak load; do not copy another system's numbers. Test with production-scale data before launch.
Result checks and definitions
Results state the data cutoff and statistical definition. A dashboard's "yesterday's sales" and a live database number can differ because of sync delay, status changes, or deduplication.
State which table or view, the time range, included statuses, and whether deduplication applied. AI should not wrap a query result as "this month's revenue" unless the definition is confirmed.
Keep an execution record for reconciliation queries: question, query, time, and result summary. When a dispute arises, it is possible to return to what was queried.
Why writes stay out of phase one
The risk of a write is not merely changing one record. It may trigger a state machine, notifications, stock deduction, and financial entries. AI's grasp of business context is insufficient for those consequences.
Phase one is read-only. When writes are genuinely needed, they go through an approved business interface or a person, not AI-executed SQL. No temporary "open write access and deal with problems later" shortcut should be adopted.
A hypothetical flow
- Define the business question
- Generate and check the query
- Execute with least privilege
- Check definitions and cutoff time
A read-only transaction does not replace account and data permissions, query limits or result checks.
Step | Action | Owner | Gate |
|---|---|---|---|
1 | A business user asks in natural language | Business user | Question includes time range and object |
2 | AI generates a parameterized query | System | Only tables and fields in the template |
3 | Template check or human review | Data or IT | Outside template is refused or escalated |
4 | Read-only account executes | System | Timeout, row cap, frequency limit |
5 | Result returned with definitions | System | Sensitive fields masked; cutoff shown |
The goal is not to replace analysts but to make common queries faster and traceable. Complex analysis remains human work.
Keep the query log for the same period as the business records it supports, and review who ran which query during access reviews.
Retention should match the business record.
Confirm Read-Only Boundaries Before Enabling Queries
[AI read-only query checklist]
1. Account and scope
- Is a dedicated read-only account used instead of admin or reporting accounts:
- Are tables and columns limited through views:
- Are sensitive fields hidden or masked:
2. Query and execution
- Are parameterized queries used:
- Are AI-generated queries checked by template or a person:
- Are DDL, writes, and cross-database access blocked:
3. Cost
- Are timeout, row cap, and frequency limits set:
- Are queries run on a read replica:
- Was a production-scale load test performed:
4. Results and records
- Do results state the data cutoff and definition:
- Are queries and executions logged:
- Are writes explicitly excluded from phase one:Start with one read-only view and one bounded question, such as "the order status of this customer for the last three months." After it works, add views and query templates gradually. Interface-level integration levels are covered in how AI connects to ERP and OA; action permissions and approval are in AI agent permissions, approval, and human takeover. The scope of business data queries and AI workflows can be discussed within AI applications and workflows.
Use entity confirmation when names are ambiguous, and show the source and time with the live-data answer.