Skip to main content

Why Your Text-to-SQL Agent Needs a Business Glossary

Updated 2 min readMarkdown

Give an LLM a clean database schema and it can write impressive SQL. Then a real user asks "which products are below their reorder level in the Leeds depot?" and things fall apart. There is no column called reorder_level, and "depot" is a warehouse in one table and a location code in another.

This is the gap between how the business talks and how the database is named. A business glossary closes it.

What a Business Glossary Is

A glossary is a set of short definitions for the terms people actually use: what "active customer" means, which column holds the reorder threshold, how a "depot" maps to the warehouse table, and which status codes count as "shipped". Each entry says what the term means and where it lives in the schema.

Why Not Put It All in the Prompt?

For a small database you could. For a real one, the glossary quickly gets too big, and stuffing everything into every prompt wastes tokens and confuses the model. Instead, store the entries in a vector database such as Qdrant and retrieve only the terms that match the question. That's RAG, applied to business vocabulary.

How It Fits the Pipeline

1. The user asks a question.
2. The agent searches the glossary for matching terms.
3. The relevant definitions are added to the prompt along with the schema.
4. The model writes SQL that uses the right columns and filters.
5. The query is validated and executed as usual.

What Changes

Questions that used to produce plausible but wrong SQL now map to the correct tables and conditions. Just as important, the glossary becomes shared documentation: the same definitions help new developers and analysts understand the data.

Practical Tips

Keep entries short and specific. Include synonyms users actually type. Version the glossary alongside your schema, and test it with a benchmark of real questions so you can see when an entry is missing or wrong.

For the full implementation in ASP.NET Core with Qdrant and SQL Server, read AI Database Agent, Part 4: Adding Business Knowledge on AI Engineering Foundry.

About the author

  • AI Engineering Foundry provides practical technical content and resources for developers building production-ready AI applications with .NET, C#, large language models (LLMs), retrieval-augmented generation (RAG), AI agents, Model Context Protocol (MCP), and SQL Server. The platform focuses on real-world AI engineering, including application architecture, database integration, secure AI workflows, tool calling, vector search, deployment strategies, and production infrastructure. Through technical tutorials, implementation guides, and developer-focused resources, AI Engineering Foundry helps software developers understand how to build, integrate, and improve AI-powered systems using modern .NET technologies. Website: https://aiengfoundry.com/

No comments yet. Be the first to comment.

More from this blog