Article

Auto Ontology in Practice: One Wrong Status Code

How a coding agent built text-to-SQL context for a real customer database over the QueryPanel MCP, and the wrong status code a person caught.

QueryPanel Team
9 min read
NL-to-SQLontologyAI agentsMCPsemantic layerembedded analytics
Auto Ontology in Practice: One Wrong Status Code

Last week we compared NVIDIA Auto Ontology and QueryPanel. Both rest on the same idea: text-to-SQL gets better from better context, more than from a better model. This post shows what building that context looked like for one real customer database, including the part where the agent got it wrong.

Short answer: A coding agent built the text-to-SQL context for a customer's production database in about 40 minutes of work spread over one day. It found what the data meant by querying it, wrote 5 glossary terms and 9 example queries, and was wrong once about what a status code meant. A person caught that by pasting the customer's three status codes. The agent wrote everything through the QueryPanel MCP server; the 14 entries took 45 seconds. Auto Ontology does the drafting in a pipeline and the certifying in a review screen. Here, the agent did the drafting and the review happened in the conversation.

Key takeaways

  • Most of what the AI needed was not in the schema. It was in the values: a placeholder that broke counts, a device clock set to 2096, two firmware versions writing to different columns.
  • The customer's agent already had their codebase and database. Adding the QueryPanel MCP let it turn what it found into context. The traps showed up when the app's queries were checked against real values. It could not know what a status code meant. Only the customer knew that.
  • A wrong context entry is worse than none. After the first round of training, the AI answered with a confident, wrong number.
  • The customer added the QueryPanel MCP to the agent they already used. It wrote 14 entries in 45 seconds and hid 3 tables from the AI.
  • QueryPanel has no certification state or "can this be answered?" check today. The review step is a person approving each write.

The question that failed

The customer runs a fleet of connected devices, about two dozen of them, and wanted a dashboard showing which devices are working right now. We asked QueryPanel the obvious question:

How many devices are active versus idle?

The devices table has no status column. With nothing else to go on, the AI did what a careful analyst would: it said so, and offered a guess. Should "has a commissioning date" count as active?

That guess would have been wrong. Every device has a commissioning date.

The agent goes digging

The customer didn't start from zero. Their team already worked with a coding agent that had their app's codebase and their database connected. They added the QueryPanel MCP server to that same agent. Nothing new to deploy, no extra service: the agent that already knew the app could now write QueryPanel's context too.

That combination is the point. The codebase and the database answer different questions. The code shows how the app uses the data: which tables it joins, which status values it writes, what a field is called on screen. The database shows what is actually stored, including what the code never mentions. Context built from the schema alone has neither.

The person gave one hint: a device is active when it has a serial number reserved to it. The agent worked out the rest by checking the app's queries against the stored values:

  • Status lives in another table. Serial numbers sit in serials, each with a numeric status and the id of the device that reserved it.
  • A placeholder breaks counts. About 1,500 serial rows have the reserving device set to '0', which isn't a device. Counting distinct reserving devices counts that placeholder as one. The rule became: never count distinct reserving ids, join to devices instead.
  • One clock lies. A few readings have timestamps in 2096. The rule: use the row's insert time, not the device-reported date.
  • Two firmware generations. Newer devices write consumption to one column, older ones to another, and an older device writes 0 when it couldn't measure. The rule: use the new column when it's set, else the old one, and treat 0 as missing.
  • Small things that cost a retry each: a plural table name, a column with a capital letter that needs quoting, and Postgres reading \b in a regex as a backspace (\y is the word boundary).

None of these are visible in a schema dump. They are the difference between SQL that runs and SQL that is right.

First training, confident and wrong

The agent wrote what it had learned as QueryPanel knowledge: 2 glossary terms ("device status", "device location") and 3 example queries ("How many devices are active versus idle?", "Which devices are idle?", "List devices with status and location"). Then it asked the original question again in a fresh conversation.

Three minutes after the failing question, the AI answered with a bar chart and a clear split: most devices active, a handful idle.

It was wrong. The agent had assumed status 0 meant "reserved", because status 0 was by far the most common value on rows that pointed at a device. That looked like the active state. It wasn't.

This is the failure mode to worry about. Before training, the AI said it didn't know. After training on one wrong assumption, it gave a confident number and explained it with a definition that sounded right.

A person corrects it

The person pasted the status table from the customer's own app:

StatusMeaning
1available
2reserved
0used (consumed on a run)

0 was the most common value because it means "already used". Reserved is 2, and almost nothing is reserved at any moment.

The agent edited 4 of the 5 entries in place, read them back, and asked again. The new answer: one device active, the rest idle. A direct count in the database agreed. The whole correction took about 7 minutes.

This is the step Auto Ontology calls certification. In their product, a person reviews drafted terms in a UI and marks them certified. Here it happened in conversation: the agent proposed, the person approved each write, and the person supplied the one fact the data could not.

The second domain: consumption

The same pattern repeated for consumption. The agent wrote 3 glossary terms and 6 example queries: total per device, per day, over time for one device, average per run, and a weekly version.

Two details are worth copying:

  • Unconfirmed meanings are marked as such. The meaning of the new-firmware fields came from comments in the customer's app code, not from the firmware itself, so the person said to confirm it with the firmware owner. The glossary entry says "unconfirmed" in its text, so anyone reading it later knows.
  • Example queries follow the chart limits. The daily query for every device returned more rows than a chart draws, so the agent added a weekly version. Context should produce answers people can see, not only SQL that runs.

What the MCP calls looked like

Every write went through the QueryPanel MCP server, one tool call per entry:

StepMCP toolCalls
Write glossary termstrain_glossary5
Write example queriestrain_gold_sql9
Check what was writtenlist_glossary, list_gold_sql4
Hide system and user tables from the AIannotate_schema3

The 14 writes took 45 seconds. The agent then listed what it had written and checked it against what it meant to write before moving on.

What a dedicated ontology service does better

Auto Ontology has things this workflow doesn't:

  • A certification state. QueryPanel's knowledge entries are live as soon as they're written. The only review is the person approving each call.
  • An "is this answerable?" check, so an agent can ask for clarification instead of guessing.
  • Automatic drafting at ingest. Here the agent did the drafting, prompted by a person.

A prompt you can reuse

You are building text-to-SQL context for the datasource <name> in QueryPanel.

  1. List the tables and read the columns of the ones the question touches. You have the app's codebase too: find the queries it runs against those tables and what its code says each column means.
  2. Before writing anything, query the real values: distinct values of status and type columns, null rates, placeholders, out-of-range dates, and whether joins match.
  3. Propose glossary terms and example queries. For each, say which query result it rests on and what you're assuming. Mark anything you couldn't verify from the data as unconfirmed.
  4. Ask me before every write.
  5. After writing, ask the original question in a fresh conversation and compare the answer with a direct count.

FAQ

Does the agent see customer data?

Yes. It runs read-only queries against the datasource to learn real values, and you approve them. It doesn't need to export data. What it writes back is definitions and example SQL, not rows.

Which MCP clients work with the QueryPanel MCP server?

Any client that supports remote MCP servers. The setup guide covers Claude Desktop, Claude Code, Cursor and ChatGPT. See What MCP Analytics Means for SaaS Teams.

How do I undo a bad entry?

List entries with list_glossary or list_gold_sql, then delete or edit them with delete_knowledge_chunk or update_knowledge_chunk. Re-ask the question afterwards. As the wrong status code showed, a bad entry is worse than a missing one.

Do I need NVIDIA NIM or a GPU?

No. The agent runs on whichever model your MCP client uses, and QueryPanel is hosted.

Further reading