Skip to content
View original post on X: meng shao
Published

Independent review layer keeps LLM data agent from judging its own SQL

AIA data analysis agent built by @Sumanth_077 separates generation, deterministic guardrails, and review: Qwen writes read-only SELECT queries, code enforces hard rules such as a single SELECT, SQLite read-only mode, and a 200-line limit, and a separate TypeSafe AI Jev model checks question clarity, SQL relevance, and whether answers are grounded in returned rows. Answers that fail grounding are marked as unverified drafts while the SQL and data are kept for human inspection.
@shao__meng
View on X

不要让 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
https://x.com/i/article/2107467472760897536
View quoted post on X
Source details

meng shao · x.comPublished · added here

Original title: 不要让 LLM 既当运动员,又当裁判员!