The 'No Handwritten SQL' Rule Behind 230,000 Trusted Data Retrievals
Data agents that produce numbers without evidence aren't useful for decisions. This system shows how to make an AI query pipeline accountable: enforce a strict path, treat failures as learning material, and move hard rules into code. The consequence is a data agent that improves by being audited, not by being cleverer.
Taotian's live-streaming team runs a data agent that has completed 230,000+ retrievals for 190+ users, and its defining constraint is a ban on handwritten SQL. Every request must go through a semantic layer that validates the metric and dimension, a DSL2SQL converter that produces auditable queries, and a read-only executor. The ban turns data retrieval from an unaccountable ad-hoc action into a fixed pipeline with a complete product trail, including the SQL's origin, the semantic assets used, the filter conditions, the data source, and execution status. The system's reliability comes from what it refuses to do, not from how clever the model is.
The design rests on three foundations: the semantic layer answers what the business question means, DSL2SQL answers how to turn that definition into an auditable query, and the cloud agent handles understanding, retrieval, orchestration, and explanation. Underneath, Paimon and StarRocks provide decoupled storage, processing, and querying. Correctness is enforced through semantic definitions, query constraints, permission and filter checks, and execution evidence. When the agent can't confirm a metric's semantics or lacks permission, it marks the request as pending or blocked rather than guessing.
The system institutionalizes failure. An eight-ring closed loop processes every issue, with three hard rules: gaps must be logged, not filled; hypotheses must come with predefined criteria for confirmation or rejection; and feedback flows upstream to the semantic layer. The team's stated goal is that the loop's output is an expanding set of answerable questions, not just conclusions. Rules that can be machine-enforced are moved out of prompts and into code, with a four-tier context layering that caps the must-load set at 20 entries. Validation uses fences to block any bypass attempt and gates to catch wrong values, where the engine gate treats zero rows and hit row limits as 'undetermined' rather than 'no data'. The system also acknowledges its limits: performance metrics exist per-tier, but no overall A/B proof, and the evaluation framework is still being built.
The ban on handwritten SQL reframes AI reliability: it comes from the constraints a system refuses to violate, not from how well the model generates code.
Turning failures into a learning loop means the system's growth depends on how well it records and converts errors into rules; that's a more sustainable improvement path than model upgrades.
Moving rules from prompts to code is a practical answer to the prompt-versus-code tradeoff: deterministic constraints belong in machine-validated layers, leaving prompts for the flexible parts.
Treating zero rows as 'undetermined' rather than 'no data' is a distributed-systems discipline that prevents false conclusions, and it's often missing in analytics tooling.