{"author":"tejusarora","children":[{"author":"tejusarora","children":[],"created_at":"2026-07-11T20:03:59.000Z","created_at_i":1783800239,"id":48875345,"options":[],"parent_id":48875342,"points":null,"story_id":48875342,"text":"Author here. sqlsure is a semantic inspector for SQL: it checks queries \u2014 human- or AI-written \u2014 against declared facts about your schema (grain, join cardinality, measure additivity) before execution. It never generates SQL, never reads your data, and runs in ~0.1 ms per check, fully offline. Apache-2.0.<p>The bug it targets: fan-out double-counting. Join orders to order_items and SUM(order_total), and every dollar is counted once per line item. The query runs fine, the dashboard renders, the number is silently wrong.<p>To test it, we ran it over the gold (expert-written) answer keys of the Spider and BIRD text-to-SQL benchmarks \u2014 2,568 queries, using only the benchmarks&#x27; own PK&#x2F;FK declarations as the rulebook. It raised 45 flags and zero spurious ones. For one BIRD query we executed the benchmark&#x27;s own database and proved the official gold answer wrong by 8\u00d7 (the fan-out factor). Filed upstream: <a href=\"https:&#x2F;&#x2F;github.com&#x2F;bird-bench&#x2F;mini_dev&#x2F;issues&#x2F;37\" rel=\"nofollow\">https:&#x2F;&#x2F;github.com&#x2F;bird-bench&#x2F;mini_dev&#x2F;issues&#x2F;37</a><p>Three ways to use it: CLI (CI gate), MCP server (agents call check_sql before executing; rejections carry machine-actionable fix hints \u2014 in our benchmark, applying the hint verbatim fixed the query 10&#x2F;10 times in one round), or as a Python library wrapping an existing text-to-SQL generator.<p>Rulebooks come from what you already have: dbt tests (unique &#x2F; relationships), PK&#x2F;FK declarations, or OSI semantic model YAML. Happy to answer anything about the method or the benchmark findings.","title":null,"type":"comment","url":null},{"author":"tuckwat","children":[{"author":"tejusarora","children":[],"created_at":"2026-07-12T04:17:50.000Z","created_at_i":1783829870,"id":48878211,"options":[],"parent_id":48878006,"points":null,"story_id":48875342,"text":"Fair point, I legit have a policy not to read anyone&#x27;s &quot;Thoughts&quot; if they were AI -- hypocritical of me I went on with AI assisted documentation. I wanted a quick POC repo and I went the lazy way -- would love to redo any sections that didn&#x27;t make sense.","title":null,"type":"comment","url":null}],"created_at":"2026-07-12T03:27:09.000Z","created_at_i":1783826829,"id":48878006,"options":[],"parent_id":48875342,"points":null,"story_id":48875342,"text":"I don&#x27;t know why but I really struggle comprehending AI written READMEs and comments. I understand the words but the way it&#x27;s written is just distracting and unintelligible.","title":null,"type":"comment","url":null},{"author":"onlyrealcuzzo","children":[],"created_at":"2026-07-12T03:29:31.000Z","created_at_i":1783826971,"id":48878019,"options":[],"parent_id":48875342,"points":null,"story_id":48875342,"text":"From what I gather, the most valuable feature is this: &quot;2. Why does SQL double-count? (the &quot;fan-out&quot;)&quot;<p>But your example is not convincing this is a common enough problem to merit a library.<p>You have a table with cost that sums to 400.  If you summed that table you&#x27;d get the same error.  You don&#x27;t need a fan-out JOIN to get the error...<p>That seems like bad database design, and creating a separate config file to mask the bad database design, rather than fixing the actual problem.<p>I think this <i>could</i> actually be useful, but I&#x27;d recommend a better example.<p>An OLAP table should be designed so that values can be summed if that&#x27;s the purpose of the table.  A relational table should be designed so that you don&#x27;t have replicated bad data.<p>An OLAP table could have unintended many-to-ones, but it still <i>shouldn&#x27;t</i> have this problem.  Maybe I&#x27;m being naive, but I think the better solution is to fix the problem, not the queries.<p>You <i>could</i> get this problem, with a different example, but I&#x27;m not convinced this library is the best solution to that problem.  Looker and DBT already mostly or completely solve it.","title":null,"type":"comment","url":null},{"author":"d-yoda","children":[],"created_at":"2026-07-12T05:53:45.000Z","created_at_i":1783835625,"id":48878699,"options":[],"parent_id":48875342,"points":null,"story_id":48875342,"text":"I think it would be better to have support for Skills.","title":null,"type":"comment","url":null},{"author":"nf-x","children":[],"created_at":"2026-07-12T07:33:37.000Z","created_at_i":1783841617,"id":48879149,"options":[],"parent_id":48875342,"points":null,"story_id":48875342,"text":"How much of it is written by AI?","title":null,"type":"comment","url":null}],"created_at":"2026-07-11T20:03:42.000Z","created_at_i":1783800222,"id":48875342,"options":[],"parent_id":null,"points":35,"story_id":48875342,"text":null,"title":"Show HN: Sqlsure \u2013 deterministic semantic checks for AI-generated SQL","type":"story","url":"https://github.com/sqlsure/sqlsure"}
