Building a Data Agent Under Data Residency Constraints: Architecture and Selection Guide
As large language models (LLMs) reshape how enterprises consume data, Data Agents promise to let business users query data and generate reports through natural conversation. However, for organizations with strict data security requirements—such as financial institutions, energy companies, manufacturers, and state-owned enterprises—keeping data within the enterprise domain is a hard prerequisite, not an option. This article examines the core architecture of enterprise-grade Data Agents built under data residency constraints, including local/private deployment, the evolution from raw NL2SQL to NL2DSL, and permission inheritance. It also explains key technologies such as semantic layer alignment, multi-layer validation, and result traceability, and concludes with practical selection recommendations.
As large language models (LLMs) continue to advance rapidly, the deep integration of natural language processing and data analytics is reshaping how enterprises consume data. In the traditional model, business users depend heavily on technical staff to write SQL, build reports, and interpret results manually—a process plagued by long cycles, high barriers to entry, and slow response times. The emergence of the Data Agent changes this: business users can now query data, generate reports, and trigger alerts simply through conversation. Yet once LLMs actually touch an enterprise’s underlying data, the core question quickly shifts from “can it be done?” to “where is the data stored, who executes the query, and can the results be trusted?”
For organizations with strict data security requirements—such as financial institutions, energy companies, manufacturers, and state-owned enterprises—“data residency” (keeping data within the enterprise domain) is a hard prerequisite for AI adoption, not an optional feature. Uploading underlying table structures or business data to an external cloud LLM may violate security and compliance red lines. Moreover, allowing a model to directly access data tables risks semantic misunderstanding and hallucination. This article outlines the construction path for enterprise-grade Data Agents under the data residency constraint and analyzes the key technology choices behind them.
1. Core Architecture Characteristics of Enterprise-Grade Data Agents
Under the hard constraint of data residency, most enterprises currently implement Data Agents by performing an in-place AI upgrade on top of their existing BI systems. The core idea is to combine the LLM’s “understanding and planning capabilities” with the “deterministic computing capabilities” of the enterprise’s existing data assets. This architecture is characterized by three main aspects:
1.1 Local and Private Deployment with Physical Isolation
To meet compliance requirements, an enterprise-grade Data Agent must support fully intranet-based or private deployment. This means the LLM inference service, vector database, semantic layer middleware, and the business data itself all remain within the enterprise’s own data centers or private cloud environment, with no traffic passing through the public internet. Under this architecture, enterprises do not need to rebuild existing data pipelines or break their network boundaries to adopt AI—they simply add an AI capability layer on top of the existing IT infrastructure.
1.2 Evolving from “Raw NL2SQL” to “NL2DSL”
Many open-source frameworks and early-stage solutions rely on “raw NL2SQL,” where the LLM directly generates SQL statements from table schemas to query the database. This approach has fatal flaws: the probabilistic nature of LLM output means the generated SQL may contain syntax errors or logic bugs, and direct manipulation of underlying tables easily triggers hallucinations, returning incorrect or even destructive query results.
Mature Data Agent architectures generally adopt the NL2DSL (Natural Language to Domain Specific Language) approach. The workflow is as follows:
- Intent understanding: The LLM receives the user’s natural language question and parses out the metrics, dimensions, and filter conditions the user wants to query.
- DSL generation: The model converts the intent into a restricted, domain-specific language (DSL) or a standardized JSON query protocol—rather than generating SQL directly.
- Semantic layer alignment: The system passes the DSL into a pre-defined BI semantic layer, aligning it with the enterprise’s existing metric definitions and dimension models.
- Deterministic execution: A deterministic compute engine (such as a traditional BI engine) compiles the DSL into a physical query plan, executes it, and returns the results.
This mechanism establishes a clear division of responsibility: the model handles intent understanding and planning, while the semantic layer and deterministic engine handle accurate execution—completely eliminating the uncertainty caused by models generating SQL directly.
1.3 Permission Inheritance and Data Asset Reuse
In terms of implementation cost, a good Data Agent should seamlessly integrate with the enterprise’s existing permission system. Because queries are ultimately executed by the deterministic engine through the semantic layer, the system can directly inherit the data permissions of the existing BI platform (such as row-level and column-level access control), without building a separate permission module for AI. At the same time, enterprises can reuse their existing data warehouses, metric models, and analytical assets, avoiding a second data migration or a full system rebuild.
2. Key Technologies: Balancing Flexibility and Trustworthiness
Under this architecture, how do we ensure that the analytical results delivered to business users are accurate and trustworthy? This requires a rigorous mechanism for semantic alignment and validation.
2.1 Semantic Layer Alignment
The semantic layer is the bridge between business language and technical data. In a Data Agent, the semantic layer defines a unified data model, metric calculation logic, dimension hierarchies, and synonym mappings. Once the LLM converts a user’s question into a DSL, the semantic layer verifies whether the requested metrics fall within the authorized scope and performs calculations using pre-defined definitions. For example, different departments may define “active users” differently—the semantic layer ensures that all conversational queries use the unified, business-confirmed definition, eliminating ambiguity.
2.2 A Three-Layer Validation System
To further guarantee query accuracy, the system should incorporate three layers of validation into the execution pipeline:
- Terminology alignment validation: During intent parsing, the system checks whether the entity terms in the user’s question match the standard terms in the semantic layer. Unrecognized terms trigger a follow-up question or fuzzy matching.
- DSL validity validation: After the DSL is generated, a rule engine verifies its syntax structure and dimension combinations against the constraints of the data model (for example, certain metrics cannot be drilled down by specific dimensions).
- Result plausibility validation: After computation, the system performs anomaly detection on the result set. For example, if a year-over-year or month-over-month comparison shows an abnormal fluctuation of more than 100x, the system can trigger a secondary review or alert the user to the anomaly.
2.3 Result Traceability Design
For enterprise applications, every analytical conclusion must be traceable to its source. When a Data Agent returns charts and textual interpretations, it should attach clear data source annotations and metric definition explanations. The front-end interface should support drill-down capability—“from answer back to raw data”—so that clicking any metric reveals its calculation logic, data extraction scope, and the underlying detail records.
3. Selection Recommendations and Practical Takeaways
For enterprises building a Data Agent under the data residency constraint, the following principles are recommended during technology selection and architecture design:
- Prioritize private deployment capability: Evaluate whether candidate solutions support fully offline model inference and component deployment to ensure physical isolation of data flows.
- Avoid the aggressive approach of direct SQL generation: For core business systems, firmly reject raw NL2SQL in favor of an architecture based on the semantic layer and DSL, ensuring deterministic and secure data computation.
- Assess asset compatibility and permission integration: During selection, verify whether the target solution can seamlessly connect to existing data warehouses and BI assets, and whether it supports fine-grained row/column-level permission passthrough, reducing rebuilding costs.
- Build a complete validation and audit loop: The system must provide end-to-end logging and auditing, recording every natural language question, the generated DSL, the executed logic, and the returned results—enabling post-hoc traceability and tuning.
In summary, under the strict constraint of data residency, building an enterprise-grade Data Agent is not simply a matter of adopting an open-source LLM framework. It requires a composite architecture that combines natural language understanding, semantic layer governance, and deterministic computation. By clearly defining the boundary between the model and the compute engine, enterprises can safeguard absolute data security while truly unlocking the value of data-driven business.
