跪拜 Guibai
← All articles
Agent · LLM · AI

The 'No Handwritten SQL' Rule Behind 230,000 Trusted Data Retrievals

By Cosolar ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

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.

Summary

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.

Takeaways
— The system has handled 230,000+ calls and served 190+ users.
— Handwritten SQL is completely forbidden; all queries go through the semantic layer, DSL2SQL, and a read-only executor.
— Correctness relies on semantic definitions, query constraints, permission and filter checks, and execution evidence, not on model intelligence.
— An eight-ring closed loop institutionalizes failure: gaps are logged, hypotheses need predefined criteria, and feedback flows to the semantic layer.
— Rules that can be machine-enforced are moved out of prompts into code; the must-load prompt layer has a 20-item cap.
— Fences block any bypass attempt (e.g., SQL patterns or physical table names), while gates have three levels: generation, assembly, and engine.
— The engine gate treats zero rows and row-limit hits as 'undetermined', not 'no data', and switches engines to re-run.
— Two gate failure modes are constant false negatives and false positives; tightening rules must include legitimate-path test cases.
— Knowledge retrieval (Wiki-KBase) uses only/all/off modes, with a fallback when confidence is below 0.6.
— One badcase round found 466 retrieval records, 282 no-hit/low-score, and 237 independent issues; triage had 122 open, 20 closed, 102 pending.
— The system does not yet have an overall accuracy A/B proof; the evaluation framework is still under construction.
Conclusions

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.

Concepts & terms
Semantic Layer
A metadata layer that maps business terms (e.g., 'paid conversion rate') to physical tables and metrics, ensuring consistent definitions and preventing ambiguity in queries.
DSL2SQL
A controlled transformation that converts a domain-specific language representation of a user request into an auditable SQL query, preserving the semantic and audit trail.
Fence vs. Gate
Two validation approaches: fences block any attempt to bypass the query pipeline, while gates perform internal checks on generated queries and results to catch errors.
Closed Loop
In this context, a feedback cycle where every failed or blocked retrieval is logged, analyzed, and used to refine the semantic layer and agent rules, turning errors into learning material.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗