Review Layer Keeps LLM Data Agents From Grading Themselves
The pattern solves a real failure mode: a model that writes and evaluates its own SQL will confidently rationalize its own mistakes. Builders of text-to-SQL or analytics agents can copy the three-layer split directly, especially the model-free guard rules that cost nothing to run. No regional angle applies here; the closest comparison is self-critique prompting, which this architecture outperforms by using a separate model for judgment.
A data analysis agent architecture separates the LLM that writes SQL from a second model that audits it.
The generation layer uses Qwen via the Vercel AI Gateway to translate natural-language questions into read-only SELECT statements against a local SQLite database.
A deterministic guard layer, implemented purely in code, enforces single SELECT only, read-only mode, a 200-row limit, and manual approval for queries without a WHERE clause.
An independent review model, TypeSafe AI Jev, checks question clarity and SQL relevance before execution and verifies answer groundedness afterward, flagging unverified answers at up to 93% confidence.
不要让 LLM 既当运动员,又当裁判员! 应该引入一个独立的“审查层”来做判断。 @Sumanth_077 构建一个数据分析 Agent,用户用自然语言提问,Agent 生成 SQL 查询本地数据库并回答。 核心架构:三层职责分离 1. 生成层:主模型 Qwen( @vercel AI Gateway),负责理解问题、编写只读 SELECT、解释查询结果。模型从不直接接触数据库。 2. 确定性守卫层:完全用代码实现、不依赖任何模型的硬性规则,只允许单条 SELECT、SQLite 只读模式、超 200 行的查询拒绝、无 WHERE 子句需人工批准。 3. 审查层:TypeSafe AI Jev,一个独立模型,在三个关键点介入: · 问题清晰度(执行前),如 "Who is our best customer?" 因“最好”定义含糊,被以 93% 置信度要求澄清; · SQL 相关性(执行前),比对问题、schema 与 SQL 是否匹配,不匹配给主模型一次修改机会; · 答案接地性(执行后),检查最终解释是否真的基于返回的数据行,不达标则降级标记为“未验证草稿”,同时保留 SQL 和数据供人工检查。 Sumanth @Sumanth_077 x.com/i/article/2107… 🔗 View Quoted Tweet📊 3 ⚡
This report is categorized under AITOP's "How-to" desk, focusing on China's AI industry and domestic foundation model ecosystem. Within our cross-regional analytical framework, it directly maps to AI developer toolchains, coding agents, and engineering workflows. Key entities and technical topics under continuous tracking include Qwen, Vercel AI Gateway, agents, SQL.
Source attribution: curated from shao__meng (@shao__meng). Cross-source corroboration: 2 independent sources have covered this development (including arXiv cs.AI), confirming industry-wide signal strength.
- arXiv cs.AI10-05 17:48Source