Data Agent Architecture for Data Residency: A Practical Build and Selection Guide

    Data Agents allow business users to query data, generate reports, and configure alerts through natural language, but security-sensitive organizations must keep data storage, computation, sensitive context, and tool execution within a controlled boundary. This article explains why keeping data within the domain is an architectural constraint rather than a deployment option. It presents a reference architecture covering intent understanding, the semantic layer, query compilation, policy enforcement, execution, and audit; compares three implementation paths—upgrading an existing BI stack, using a private orchestration platform with a query gateway, and building a custom agent framework integrated with a semantic execution engine; and examines controlled intermediate query representations such as NL2DSL. It also provides a trusted and secure capability checklist, selection criteria, and a seven-step rollout plan for organizations building Data Agents in data-residency-constrained environments.

    As large language models enter data analytics, enterprises are beginning to query data, generate reports, and drive alerts through natural language. These capabilities are commonly called Data Agents. Enterprise attention has shifted from whether such systems can be built to where the data resides, who executes the query, and whether the result can be trusted. For organizations with high data security requirements, keeping data within the domain is not an optional feature; it is a precondition for architecture design.

    Traditional data analysis depends on professionals writing SQL, building reports, and interpreting results manually. This is slow and requires specialized expertise. Large language models make it possible for business users to retrieve data through conversation, but they also introduce new risks. When a model accesses underlying data tables directly, it can misunderstand metric definitions, hallucinate fields, or create incorrect joins. If data is uploaded to an external cloud, the organization may cross security and compliance boundaries. The focus of Data Agent development is therefore not simply adding a conversational entry point. It is building an engineering system that performs intent understanding, semantic alignment, deterministic execution, and result traceability within a secure boundary.

    1. Why Keeping Data Within the Domain Is an Architectural Constraint, Not a Deployment Option

    Keeping data within the domain has three meanings: data storage remains inside the enterprise boundary; query computation takes place in a controlled environment; and model services and tool calls do not transmit sensitive detail to external networks. Deploying an application on the internal network while allowing a model to read data tables through a public API—or uploading complete detail records as prompt context—does not satisfy the requirement.

    The architecture should follow these principles:

    1. Deploy the model in the same or a nearby network domain as the data. Model inference services should run in the enterprise intranet, a private cloud, or a private environment. At a minimum, query results, metric details, and business fields should not traverse an external network.
    2. Do not let the model access underlying tables directly. The model should understand intent and plan queries; it should not generate executable SQL that directly accesses physical tables. A semantic layer, query gateway, and deterministic execution engine should sit between the model and the data.
    3. Push computation down and minimize returned results. Queries should execute in the environment where the data resides. Only aggregated results, necessary samples, and explanation information should be returned to the conversation layer. Sensitive details should not enter the model context by default.
    4. Inherit permissions and enforce mandatory filtering. The query plan must inject row-level and column-level permission predicates and reuse the existing BI or data warehouse permission system. An AI entry point must not bypass existing access controls.
    5. Provide full-chain auditing and traceability. Record the user question, intent parsing, intermediate query representation, execution plan, data source, metric definition, and result hash. The system should support tracing an answer back to the original data.

    2. Reference Architecture for a Data Agent

    A practical Data Agent typically includes the following modules:

    • Interaction layer: natural-language conversation, report generation, and alert configuration.
    • Intent understanding layer: entity recognition, metric recognition, time-range parsing, and comparison-mode recognition.
    • Semantic layer: metrics, dimensions, business terms, data domains, metric definitions, synonyms, and hierarchical relationships.
    • Query compilation layer: compiles the intermediate representation produced by the model into a deterministic execution plan instead of executing model-generated SQL directly.
    • Permission and policy layer: row-level and column-level permissions, data masking, tool allowlists, and query-scope restrictions.
    • Execution engine: executes queries in the environment where the data resides and returns aggregated results.
    • Audit and explanation layer: records lineage, metric definitions, execution logs, and result sanity checks.

    The semantic layer is a critical bridge between keeping data within the domain and producing trustworthy results. Without a semantic layer, the model can only work with physical tables and field names, making it easy to interpret the same term, such as “sales revenue,” according to different definitions. With a semantic layer, the model can operate on business terms, and the system maps those terms to governed metrics and dimensions for execution by a deterministic engine.

    3. Comparison of Three Implementation Paths

    Path 1: Upgrade the Existing Enterprise BI Stack in Place

    This path builds on the enterprise’s existing BI semantic layer, metric system, and permission system by adding natural-language interaction and agent orchestration. It supports intranet and private deployment. After a user asks a question, the system converts natural language into a domain-specific language or structured query representation, aligns metrics and dimensions through the semantic layer, and executes the query through a deterministic computation engine.

    The advantages are reuse of existing data assets, metric definitions, analytics assets, and permission systems; relatively strong query accuracy and explainability; and comparatively controllable implementation cost. The limitations are dependence on the maturity of the existing semantic layer, limited coverage of ungoverned data domains, and flexibility constrained by governance requirements. This path suits enterprises with a relatively mature BI system, strong compliance requirements, and a focus on consistent metric definitions.

    Path 2: Private Agent Orchestration Platform + Query Gateway

    This path uses a general agent orchestration platform as its foundation and connects to data services through workflows, tool calls, knowledge bases, and plugins. To keep data within the domain, the platform must be deployed privately, and data access must go through a query gateway or data service API. Agents must not connect directly to databases.

    The advantages are flexibility and extensibility. The platform can orchestrate multiple data sources, tools, and multi-step tasks. The limitations are that the semantic layer, permission gateway, and audit trail must be built separately. If tool calls lack allowlists and policy constraints, unauthorized queries or inconsistent metric definitions can occur. This path suits organizations with platform engineering teams, multiple heterogeneous data sources, and a need to orchestrate business scenarios quickly.

    Path 3: Custom Agent Framework Integrated with a Semantic Execution Engine

    This path is a custom integration built on general Agent frameworks, function calling, policy engines, and query compilers. It gives the organization full control over model services, tool calls, permission filtering, and the audit chain. The advantage is a high degree of control and the ability to customize deeply for industry compliance requirements. The limitation is high development cost: the organization must build the semantic layer, DSL, execution engine, permission system, and model evaluation capabilities at the same time. This path suits organizations with strong development capabilities, clear long-term governance requirements, and highly diverse scenarios.

    Dimension In-place BI upgrade Private orchestration platform Custom framework integration
    Data boundary Intranet/private deployment with a clear boundary Depends on private transformation and a gateway Fully controllable
    Query mechanism Semantic layer + deterministic engine Tool calls + query gateway Self-built DSL/compiler
    Trusted sources Reuses metric definitions and permissions Requires added semantics and audit Requires full-stack development
    Implementation cost Relatively low Medium Relatively high
    Best fit Strong compliance, unified metric definitions Multiple heterogeneous sources, rapid orchestration Deep customization, long-term governance

    4. Query Mechanism: Prefer a Controlled Intermediate Representation

    The risk of direct NL2SQL is that the model may generate incorrect joins, hallucinate fields, omit permission conditions, or misunderstand metric definitions. A more reliable approach is NL2DSL: the model outputs a constrained structured query representation; the semantic layer validates whether metrics, dimensions, and filter conditions are legal; and the representation is then compiled into an execution plan.

    Example pseudo-DSL:

    1. {
    2. "intent": "aggregate",
    3. "metric": "sales_revenue",
    4. "dimensions": ["region"],
    5. "filters": [
    6. {"field": "date", "op": "between", "value": ["2024-01-01", "2024-03-31"]}
    7. ],
    8. "compare": {"type": "yoy"},
    9. "limit": 100
    10. }

    Pseudo-code for permission injection and execution:

    1. effective_filter = merge(user_scope(data_domain), row_level_policy(user, metric))
    2. plan = semantic_layer.compile(dsl, effective_filter)
    3. result = deterministic_engine.execute(plan)
    4. return explain(result, lineage, metric_definition)

    The division of responsibilities is as follows: the model understands intent and plans the query; the semantic layer aligns metric definitions; and the deterministic engine executes accurately. Each result should include the data source, metric definition, and filter conditions so that users can trace the answer back to the original data.

    5. Trusted and Secure Capability Checklist

    A Data Agent implementation should cover at least the following capabilities:

    1. Term and metric governance: Maintain a metric registry, synonyms, business terms, and metric definitions to avoid the same name meaning different things.
    2. Intermediate representation validation: Validate DSL structure, field existence, operation legality, and query scope.
    3. Result sanity checks: Check for empty results, abnormal fluctuations, magnitude deviations, and consistency of comparison definitions.
    4. Permission inheritance: Reuse existing BI or data warehouse permissions and enforce row-level and column-level filters in query plans.
    5. Data masking: For sensitive fields, return masked values or aggregates by role, or deny access.
    6. Audit traceability: Record the question, parsing result, execution plan, data source, result hash, and user identity.
    7. Tool allowlists and network isolation: Agents can call only controlled data services and cannot access external networks or physical tables arbitrarily.
    8. Controllable model services: Deploy model inference services on the internal network and avoid including unnecessary sensitive details in prompts.

    6. Selection Recommendations and Rollout Steps

    When selecting an approach, evaluate whether the data boundary is clear; whether private or intranet deployment is supported; whether a semantic layer and metric governance are available; whether queries use a controlled intermediate representation; whether permissions can be inherited; whether auditing is complete; and whether scalability and cost match requirements. If the enterprise already has a mature BI semantic layer, the in-place upgrade path should be preferred. If data sources are heterogeneous and the platform team is strong, a private orchestration platform with a query gateway may be appropriate. If scenarios vary widely and development capabilities are strong, a custom framework integrated with a semantic execution engine may be suitable.

    Implementation can be divided into seven steps: inventory data assets and metric definitions; define the security boundary and deployment topology; build the query gateway and semantic layer; integrate intranet model services; connect permissions and auditing; run a POC to validate network isolation, unauthorized access prevention, metric consistency, and traceability; and gradually expand to report generation, alerts, and self-service analytics.

    Building a Data Agent under data-residency constraints is fundamentally about using a semantic layer, deterministic execution, permission inheritance, and audit traceability to constrain the uncertainty of large language models within a governable engineering boundary. Only after addressing data boundaries and result trustworthiness can natural-language analytics enter core enterprise business processes.