Intro
Two services in my lab keep a history that I keep asking about. LiteLLM logs every model request with its key, tokens and cost (Part 29). n8n logs every workflow run (Part 41). The questions are always small: which service spent the most this week, which workflow fails. The answer is always a SQL query that I write again from memory.
NVIDIA Auto Ontology is a text-to-SQL app. It reads a database and builds a catalog of tables and columns with model-written descriptions (the ontology). Then it answers a question in plain English. It answers with SQL, runs it, and shows the rows. I wanted it on those two databases, and I wanted to ask it from Claude Code, not from a browser tab.
TL;DR: Auto Ontology 1.3.0 runs in namespace
auto-ontology, installed by Flux from a vendored copy of its Helm chart. Its state lives on my CloudNativePG cluster. It readslitellmandn8nas a read-only role that sees only views in a schemaao, never prompts, payloads or credentials. Chat models go through LiteLLM to Workers AI, embeddings go straight to NVIDIA, because the vector store only takes 2048 dimensions. Only the frontend is exposed, on the tailnet. A Claude Code skill calls its API with a viewer token. Six problems on the way. The last one: every question ended with no answer, and the model was not the cause. With two databases connected, the agent had no database to run its SQL on until the request named one.
The Figure
I drew Auto Ontology as a library card catalog. The two drawer banks at the
back are the source databases, litellm and n8n. Each drawer holds the card
for one view in schema ao. The tray of new cards in front stands for
ingestion and compilation. The clerk on the carriage is the agent. It pulls
cards for the question slip on the desk and runs the SQL at the terminal. Each
tool call uses one of the 24 pegs on the budget board. The dial on the desk is
target_db. Press 1 to leave it unset. Both banks light up, and the clerk
pulls cards from both. The terminal raises a red “no database to run on” flag
until every peg is used, and a red slip comes out with no query. Press 2 or 3
to set the dial to litellm or n8n. Only that bank opens, the SQL runs, and
a green slip comes out with the answer. The readout in the corner shows the
dial, the cards pulled, the tool calls and the result. I built it with the
anatomy skill.
The Situation
- k0s on three Proxmox hosts, Flux owns every app (Part 16). Kyverno enforces image registries, resource limits and Service types.
- CloudNativePG cluster
pg, two instances, TLS only (Part 8). - LiteLLM v1.106.7 in front of Cloudflare Workers AI, one virtual key per service (Part 29).
- n8n 2.45.7, with about 10 000 workflow runs in its database (Part 41).
- Secrets in OpenBao through External Secrets (Part 5), private apps on the tailnet (Part 4).
- NVIDIA Auto Ontology 1.3.0: a Next.js frontend (port 3000), a FastAPI backend (3001) and an ingestion service (3002).
Setup
The flow
flowchart LR CC["Claude Code<br/>skill ask.sh"] -->|"x-api-key<br/>tailnet"| FE["frontend<br/>Next.js"] FE --> BE["backend<br/>ReAct agent"] BE --> ING["ingestion"] BE -->|chat| LL["LiteLLM"] --> WAI["Workers AI"] BE -->|embeddings| NV["build.nvidia.com"] BE -->|"SQL as ao_reader"| RO["pg-ro<br/>litellm, n8n<br/>schema ao"] ING --> RO BE --> RW["pg-rw<br/>auto_ontology"]
The chart, fixed from outside
The chart is not in NVIDIA’s Helm repository index, so the app folder holds a
copy of helm/auto-ontology from the project at tag v1.3.0. I do not edit
the copy. A Flux post-renderer fixes what does not fit the cluster:
| Chart behavior | Fix |
|---|---|
frontend Service is a hardcoded NodePort, which Kyverno denies | JSON patch to ClusterIP |
| a bundled Postgres StatefulSet, Service and PVC with no toggle | $patch: delete, plus an ExternalName Service postgres to pg-rw, because the init containers wait on nc -z postgres 5432 |
pgAdmin on :latest and NodePort | pgadmin.enabled: false |
| migration Jobs without memory limits or a security context | patched |
| images run as named users | explicit runAsUser (1000 backend, 1001 frontend), so runAsNonRoot passes |
The images come from nvcr.io, which pulls without a login. I pinned them by
index digest and added nvcr.io to the Kyverno registry allowlist.
pg refuses plain connections, and the apps build their database URLs with no
sslmode. Both clients read TLS settings from the environment instead:
libpq takes PGSSLMODE=verify-full and PGSSLROOTCERT, and node-postgres
takes PGSSLMODE and NODE_EXTRA_CA_CERTS. Every pod mounts the lab root CA.
Only the frontend is reachable
The backend trusts an x-auto-ontology-user-id header that it does not check.
Anyone who can reach port 3001 can act as any user. So a NetworkPolicy admits
the backend only from the frontend pods, and the ingestion service only from
the backend. The frontend has a Tailscale Ingress and nothing else: no LAN
route, no public route. Sign-up is off, and the bootstrap admin never leaves
the UI.
A read-only role that sees views
Auto Ontology takes plain connection strings with no table filter. Whatever
the role can read, it ingests, and parts of it go to the models as samples.
So the scope lives in Postgres. The CNPG managed role ao_reader has
default_transaction_read_only, a 60 s statement timeout, and access to one
schema per database, ao, which holds views:
| Database | Views | Left out |
|---|---|---|
litellm | spend_logs, keys, daily_spend_by_key, daily_model_usage | prompts, responses, the hashed key (api_key) |
n8n | executions, workflows, workflow_statistics, tags, workflow_tags | workflow nodes, pinned data, execution data, credentials |
LiteLLM needs views for a second reason. Its spend tables identify a
key only by api_key, the hash of the key. LiteLLM treats a value without the
sk- prefix as an already hashed key, so the hash can work as a credential. A
view joins the readable alias in and leaves the hash out:
CREATE VIEW ao.spend_logs AS
SELECT s.request_id,
COALESCE(k.key_alias, s.metadata ->> 'user_api_key_alias') AS key_alias,
s.model, s.status, s.spend,
s.prompt_tokens, s.completion_tokens,
s."startTime" AS start_time
-- and a few more timing columns
FROM public."LiteLLM_SpendLogs" s
LEFT JOIN public."LiteLLM_VerificationToken" k ON k.token = s.api_key;
A view runs with its owner’s rights, so ao_reader holds nothing on the real
tables. The grants file runs by hand on the primary, because CNPG does not
manage grants. It is idempotent (safe to run again). One cost: an upgrade that
changes a column under a view fails until I drop the schema and run the file
again.
Models: chat through LiteLLM, embeddings direct
Auto Ontology picks its chat client from the model name. A name that starts
with openai/ uses LangChain’s ChatOpenAI, which supports the JSON schema
output that every step of the agent uses. Any other name uses ChatNVIDIA. So
LiteLLM serves two aliases with that prefix, and the app has one virtual key
with a budget:
| Role | Model |
|---|---|
| reasoning | openai/glm-5.3 (Workers AI @cf/zai-org/glm-5.3) |
| non-reasoning and default | openai/deepseek-v4.1-flash (@cf/deepseek-ai/deepseek-v4.1-flash-1017) |
| embeddings | nvidia/nemotron-3.5-embed-1b on build.nvidia.com |
| rerank | none |
Embeddings skip LiteLLM. The vector store creates its column as
halfvec(2048) (vdb/postgres.py, vector_size 2048) and does not size it
from the embedder. The only embedder I have on Workers AI is bge-large with
1024 dimensions. Nemotron embed returns 2048 natively. LiteLLM has no rerank
model. If the call fails, the only caller (semantic/bridge_tables.py)
falls back. So rerank points at LiteLLM with a model name that does not exist,
and it fails at once.
The skill
The Claude Code skill is a 50-line script, ask.sh. It posts the question to
/api/chat/completions on the frontend, reads the server-sent events and
prints the answer, the SQL and the rows. It authenticates with an API token
that belongs to a viewer user, created through the app’s invitation API, so
the token cannot change settings. The token lives in OpenBao and reaches my
shell as an environment variable. The first argument names the database
(Issue 6 explains why):
.claude/skills/lab-ontology/ask.sh n8n "How many n8n executions failed in the last 30 days?"
# ANSWER
# 31 executions failed in the last 30 days, counted from ao.executions where
# status is not 'success' (30 with status 'error' and 1 with status 'crashed') ...
#
# SQL
# SELECT COUNT(*) AS failed_last_30_days
# FROM ao.executions
# WHERE status <> 'success'
# AND "startedAt" >= NOW() - INTERVAL '30 days'
#
# ROWS
# [{"failed_last_30_days":31}]
Issue 1: Ingestion Found No Tables, Then Too Many Connections
Symptom
The first ingestion finished with 0 tables. After I applied the grants and restarted it, ingestion failed:
FATAL: too many connections for role "ao_reader"
Cause
Ingestion runs once at startup and then every 24 hours. The pod started before the grants existed, so it found nothing, and it had no reason to look again. The second error is arithmetic. Each process opens a psycopg pool of up to 4 connections per source database. The backend and ingestion each have one, for two databases, and a rollout runs old and new pods side by side. The role limit was 10.
Fix
kubectl rollout restart deploy/ingestion after any grant change, and a
connectionLimit of 40 on the role. Then litellm ingested 4 views with 55
columns, and the embeddings came back with 2048 dimensions.
Issue 2: n8n Had Zero Tables
Symptom
litellm ingested, n8n still showed 0 tables. The role was able to read the
columns: a manual SELECT as ao_reader worked.
Cause
My first n8n grants were column grants on the real tables, which looked like
the tidy way to hide workflow definitions. Auto Ontology’s catalog query lists
only relations where has_table_privilege(c.oid, 'SELECT') is true. For a
role that holds column grants only, that check is false. So the catalog
skipped every table it was allowed to read.
Fix
Views in schema ao for n8n too, the same pattern as LiteLLM. Then n8n
ingested 5 views with 35 columns.
Issue 3: HTTP 410 from Both Models
Symptom
Every chat call failed through LiteLLM with HTTP 410 and code 5028.
Cause
I chose kimi-k2.6 and glm-5.3-flash while I planned this, and Cloudflare
deprecated both on 2026-11-20. Three other models in my LiteLLM catalog were
gone from the Workers AI model list too.
Fix
I probed the live models with what the agent needs, a strict json_schema
response_format:
| Model | Result |
|---|---|
@cf/zai-org/glm-5.3 | valid JSON, 6 s |
@cf/deepseek-ai/deepseek-v4.1-flash-1017 | valid JSON, 3 s |
@cf/openai/gpt-oss-120b | valid JSON, 4 s |
@cf/meta/llama-4-scout-17b-16e-instruct | valid JSON, 3 s |
@cf/google/gemma-4-26b-a4b-it | valid JSON, 13 s |
@cf/zai-org/glm-4.7-flash | valid JSON, 75 s |
@cf/qwen/qwen3.8-27b | hit the token limit |
The probe needs max_tokens (I used 4096). Without it, the reasoning models
spend their default budget on thinking and return content: null. I picked
glm-5.3 for reasoning and deepseek-v4.1-flash for the rest, and changed the
models allowed on the virtual key.
Issue 4: Compilation Crashed on Empty Columns
Symptom
Semantic compilation writes the descriptions and terms. It is off by default,
so I switched it on through the admin API
(PUT /api/configurations/semantic-compilation). Three n8n tables failed:
IndexError: single positional indexer is out-of-bounds
Cause
The error comes from probe_ascending_distinct_values. When a key column has
no non-NULL values, the probe gets a DataFrame with no columns and indexes into
it anyway. retryOf and retrySuccessId were NULL in all 10 092 runs,
because my workflows do not retry. tags and workflow_tags have no rows at
all.
Fix
I dropped the two retry columns from the ao.executions view. Nothing can ask
about a value that never occurs. The two tag tables still fail and will
compile once I create a tag.
Issue 5: LiteLLM Compiled Zero Tables
Symptom
After the model change, a new compile pass reported 0 tables for litellm.
Cause
A compile pass skips tables that already have terms. The pass with the dead models had already written them, so the new pass saw nothing to do.
Fix
POST /semantic/reset on the ingestion service, then a fresh compile. It
compiled 7 tables in 220 s. One call ran into the 4096-token output limit and
was retried.
Issue 6: Every Answer Said No Query
Symptom
Every question through the skill ended after 100 to 150 s with the same answer:
I couldn't write a query that answers this question from the data I could
find. Try rephrasing it, or name the table or measure you mean.
The backend logged:
ReAct episode ended without an answer: budget_exhausted
LiteLLM showed 142 successful glm-5.3 calls in 15 minutes. Postgres showed no
failed query from ao_reader.
Dead end: blame the model
The agent is a ReAct loop (the model reasons, calls a tool, reads the result,
and repeats). Its tools are retrieve (search the catalog), run_sql and
submit. The loop ends when the model submits a query or after 24 tool calls. Many calls and no answer looked like a model that cannot finish
a tool loop. I almost switched the reasoning model to gpt-oss-120b and doubled
the budget.
First I ran a toy version: two tools, one table, the same Workers AI models.
glm-5.3 called run_sql, then submit, in 6.7 s. gpt-oss-120b called
run_sql three times and stopped without submitting, in 48.6 s. The model was
fine, and the switch can make it worse.
Finding it
The API returns only a summary of the agent’s thoughts, and the logs do not
show tool results. So I ran one episode inside the backend pod with a small
wrapper around the loop’s dispatch function that printed each tool result.
Every run_sql and the final submit got the same answer:
=== CALL run_sql {'sql': "SELECT COUNT(*) FROM ao.executions WHERE status <> 'success' ..."}
--- OBS Error: no database to run on. Retrieve the tables you need first.
The SQL never reached Postgres, which is why Postgres had no errors to show.
Cause
With more than one source database, the agent must choose which one runs the
SQL. When the request does not name one, resolve_connector_from_tables
takes the database of every table that retrieve showed in the episode. If
those span more than one database, it refuses:
Relevant tables span multiple databases (...); a single statement cannot be
routed across them.
The refusal is right, a statement cannot run across two databases. But
retrieval is a semantic search over both catalogs, and it returns near
matches. An n8n question about “execution status” also returned LiteLLM’s
ao.spend_logs, which has a status column. Both views also live in a schema
named ao. After the first mixed search, every query in the episode had no
database. The model kept searching and retrying, which is what a careful agent
does, until the budget ran out.
Fix
The chat API accepts target_db. With it set, the agent uses that connector
and ignores what retrieval mixed in. The skill now requires the database as
its first argument and sends it with every question. The model and the tool
budget stay as they were.
Results
Three questions through the skill, each checked against a direct query on the primary:
| Question | Time | Answer | Direct query |
|---|---|---|---|
| n8n executions that failed in the last 30 days | 16 s | 31 | 30 error + 1 crashed |
| failed executions per n8n workflow, last 30 days | 40 s | 27, 3, 1 | 27, 3, 1 |
| requests and spend per LiteLLM key alias, last 7 days | 18 s | 4 aliases | not checked |
The per-workflow answer joined ao.executions to ao.workflows on its own
and returned workflow names. The LiteLLM answer also showed a trap with live
data. The answer text said auto-ontology made 268 requests, and the rows
under it said 272. The agent ran a check query, then the final one, and its own
model calls landed in between. The rows are the answer, the text is a summary
of an earlier look.
Auto Ontology is now the biggest user of my LiteLLM budget: 272 requests and about 1 USD in 7 days, most of it from ingestion and compilation.
Lessons
- Scope a text-to-SQL app with database grants. Auto Ontology reads whatever its role can read and sends samples to a model. Views in a separate schema decide what exists for it.
- Column grants can hide a table from a catalog. A tool that lists
relations with
has_table_privilegesees none of them. Views give a role full privileges on exactly the columns you choose. - Probe models with the request shape the app sends. A model that chats
can still fail strict JSON output, and a reasoning model returns nothing
without enough
max_tokens. - Test the premise before you swap the model. A toy loop took two minutes and showed that my planned fix was worse than the current model.
- Print what the tools return. The model did the right thing for 24 calls in a row. The answer was in what the tools told it.
- Give an agent with several databases the one to use. Semantic search crosses database lines easily. Routing by what search returned breaks on the first near match.
- Trust the rows over the answer text. On data that changes while the agent works, the text and the result can disagree.
References
- NVIDIA: Auto Ontology on GitHub
- NVIDIA: build.nvidia.com, Nemotron embed models
- Cloudflare: Workers AI models
- Cloudflare: Workers AI JSON mode
- LiteLLM: Proxy virtual keys
- PostgreSQL: has_table_privilege and access privilege functions
- PostgreSQL: CREATE VIEW
- CloudNativePG: Managed roles
- Flux: Helm post renderers
- GitHub: wheresryan22/anatomy
