Wink Pings

The SQL Ran, but the Numbers Were Wrong: The Missing Layer for AI Agents

A finance question: an AI agent generated SQL that ran without error and returned $4.82 million; the actual figure was $4.31 million. The problem was not syntax but the mapping from business terms to data. Ontology is what handles that.

Ask a data question, and an AI agent generates a piece of SQL, it runs, and it returns a number. Finance looks at it and says it is wrong. This happens a lot now.

The problem is not SQL syntax. The database will immediately report a syntax error. The trouble is that the query can execute, the result looks plausible, but the number is wrong.

Prince Verma wrote a post about this on X. He gives the example of a fictional B2B company called Halvard. The finance manager asks: What was net revenue for EMEA enterprise customers in Q3 2026?

Without an ontology, the agent finds amount_cents and invoice_date, writes a query, and returns $4.82 million. Finance's actual number is $4.31 million. Five errors, none of them syntax errors:

  • Refund invoices were not excluded
  • Test accounts were included
  • The date used was invoice date, not service period
  • Different currencies were added together directly
  • DACH accounts were missed because the regional hierarchy was not applied

This SQL would pass any data catalog check because the tables and columns really exist. It was simply wrong.

The key concept here is ontology. In AI, an ontology is a machine-readable domain model: what entities exist, how they relate, and what rules always hold. It maps business terms such as 'net revenue' to specific tables and columns, plus calculation rules.

An ontology usually has five parts: classes, instances, properties, relations, and axioms. Teams actually building data agents also add metric definitions and physical table mappings. Those last three are exactly where agents most often go wrong. Give an agent only a list of classes and no metric definitions, and it has to guess what 'revenue' means, generating a new SQL query every time it guesses.

ComponentRole
ClassEntity type
InstanceSpecific object
PropertyCharacteristic
RelationAssociation between entities
AxiomRule that always holds
Metric definitionHow a business metric is calculated
Physical table mappingWhich table and column a term maps to

Ontology should be distinguished from several easily confused concepts. Taxonomy deals with hierarchies; a knowledge graph is a graph of facts; a semantic layer defines BI metrics; a database schema describes table structure. An ontology defines meaning and rules. Knowledge graphs are usually constrained by an ontology: the ontology is the blueprint, the graph is the building. A semantic layer can be seen as an ontology over metrics, but an ontology also has to govern cross-system entity relationships and rules.

Ontologies let AI reason. For example, make partOf a transitive relation: Germany is part of DACH, DACH is part of EMEA, and a reasoner can infer that Germany is part of EMEA. Without this rule, filtering by region='EMEA' would silently exclude German customers in DACH. A pure text-to-SQL agent lacks this reasoning ability.

NVIDIA open-sourced an Auto Ontology project under the Apache-2.0 license, with 17.1k stars as of November 29, 2026. It is a Python framework that provides business definitions to agents through MCP, with a CLI and REST API. The README lists 11 engines: PostgreSQL, MySQL, Databricks, Snowflake, ClickHouse, Trino, BigQuery, Apache Kyuubi, HeavyDB, DuckDB, and SQLite. Tools include check_readiness, search_terms, get_term, describe_table, check_answerable, and ask_question. ask_question returns the answer, SQL, and data rows. The README also claims leadership on BIRD-Interact and BEAVER benchmarks, but the page only shows a #1 badge and does not publish scores, so this ranking can currently only be considered NVIDIA's own claim.

The original article's advice on how to build an ontology is very pragmatic: start with the questions the agent actually receives. Go through Slack, BI requests, and support tickets, and collect 50 to 200 real questions. Pick the 20 to 40 metrics and entities used in those questions. For each definition, clearly write down the owner: finance owns net revenue, sales owns pipeline. If there is disagreement, record it as two separate terms. Then map terms to physical columns, and manually review every mapping. Add exclusion rules, cardinality rules, hierarchies, units, and calendars. In terms of format, teams that need formal logic can use W3C standards: RDF 1.1, OWL 2, and SHACL. Many data teams simply write YAML in semantic layer tools. Version it like code, and rerun the question set on every merge. For permissions, use the user's own identity; don't let the agent run with superuser privileges.

One point the original article puts bluntly: these built-in checks are all run against the ontology's own views. Certification happens only once, when definitions are approved. After that, data, mappings, and definitions all change, so independent tests need to run against trusted systems at every release to catch drift that certification cannot see.

The original author is from TestMu AI, and the article is clearly promotional. The Agent Testing approach he mentions is still worth considering: ask the agent questions with known answers, then cross-check its responses against trusted sources it did not generate. Upload metric definitions and a data dictionary as the baseline, use Data Validation to check facts mentioned in the conversation, use Hallucination Detection to score each run, and rerun the same set of scenarios when definitions change. These practices are tool-agnostic and can be built in-house.

Back to the opening example. If the ontology has two definitions of the term net revenue, a well-designed agent will ask which one you want, or at least state which one it used. Test cases should check this behavior. The worst case is an agent confidently choosing one, and you only discovering the number is wrong on the board deck.

发布时间: 2026-11-30 23:27