Your AI agent should not have direct database access
Topic
Agentic Architecture
Kind
Perspective
Author
André Pedroso
Read time
3 min read
Natural-language access to enterprise data is one of the clearest applications of generative AI.
Ask:
Which customers have reduced their orders for three consecutive months?
The system translates the request into a database query and returns the answer.
Useful.
Also potentially dangerous.
The quickest implementation is to give an LLM the database schema, let it generate SQL and execute that SQL.
That is excellent for a demo.
Production requires more thought.
The problem with arbitrary SQL
A generated query can be wrong.
It can be inefficient.
It can expose information the user should not see.
It can misunderstand table relationships.
It can return far more data than intended.
If write access exists, the consequences become considerably worse.
This does not mean AI-generated SQL is inherently unusable.
It means execution needs boundaries.
Pattern 1: controlled business tools
The safest approach for predictable workloads is often to expose specific capabilities.
For example:
get_customer_revenue(customer_id, period)
find_declining_accounts(threshold, period)
get_overdue_invoices(region)
compare_product_margin(product_id, periods)
The model translates user intent into one of these operations.
The application controls the underlying query.
This limits flexibility but provides strong predictability.
Pattern 2: parameterised query templates
For more flexible analysis, define approved query structures with controlled parameters.
The AI can determine:
customer segment
geography
time period
threshold
grouping
But it cannot arbitrarily rewrite the complete query.
This creates a useful middle ground between fixed APIs and unrestricted SQL.
Pattern 3: generated SQL inside a sandbox
Some analytical use cases genuinely require open-ended queries.
Generated SQL can still be used.
But execute it in an environment designed for exploration.
That may include:
read-only replicas
restricted schemas
query timeouts
row limits
cost limits
blocked operations
query validation
audit logs
The agent gets flexibility without unrestricted access to the production database.
Identity still matters
A technically valid query is not automatically an authorised query.
Suppose a manager asks:
Compare salaries across my department.
Whether the request can be fulfilled depends on the person's permissions.
The AI layer therefore needs identity context.
The database operation should reflect what the user is authorised to access.
Natural language cannot become a shortcut around RBAC.
Minimise what reaches the model
Another useful principle is to retrieve only what is required.
If the user asks:
What was our total revenue in Germany last month?
the LLM does not need thousands of transaction records.
The database can calculate the total.
The model receives:
Germany revenue, August 2026: €X
This reduces token usage and limits unnecessary exposure of underlying information.
Use databases for database work.
Use models for interpretation.
Validate before execution
A query execution layer can inspect generated operations before they reach the database.
Checks can include:
allowed tables
allowed columns
query type
estimated complexity
user permissions
prohibited functions
maximum rows
sensitive fields
Suspicious requests can be rejected or escalated.
Separate read from write
Reading data and modifying data should have very different risk profiles.
An analytics agent may receive read-only access.
A workflow agent capable of updating records should use explicit operations.
Instead of letting an LLM generate:
UPDATE customers ...
provide:
update_customer_status(customer_id, status)
The operation can validate both the parameters and the user's authority before making the change.
Why this matters for enterprise AI
Natural-language interfaces will make databases accessible to many more employees.
That is a major opportunity.
It also means the database will receive requests from people who do not understand its structure and from models that can make mistakes.
The solution is not to block natural-language access.
It is to build a controlled execution layer between language and infrastructure.
The model interprets.
The database computes.
The infrastructure decides what is allowed.
That separation is one of the core principles behind how we design data access in SINAS and ONE.
Enterprise data should become easier to use.
It should not become easier to compromise.





Fresh insights, straight to your inbox.
Engineering breakdowns, sovereign-AI perspectives and practical guides from the people building enterprise AI. One email when there is something worth your time.