← All case studies

Same question, same SQL, same answer

Deterministic Natural-Language Search for a Private-Markets Data Platform

Deal teams ask “industrials in the southwest received this year with LTV under 70%” and get an exact, explainable table — the model plans the query, but never writes free-form SQL.

The problem

A data platform for real estate and private-credit investors held deal metrics in a wide table — over a hundred columns — that only an analyst could query. Deal teams speak in vernacular (“LTV”, “multifamily”, “southwest”), the columns do not, and a text-to-SQL model that guesses a column or invents one returns a confident, wrong table.

What we built

A chat interface over the metrics database in which the language model never writes SQL directly. It interprets the question into a structured filter, deterministic code turns that filter into a validated, read-only query, and the answer comes back as a table with the filters it applied spelled out.

Before: 100+ columns only an analyst can query; Vernacular terms are not column names; Text-to-SQL invents columns. After: Same question, same SQL, same answer.

Before

  • 100+ columns only an analyst can query
  • Vernacular terms are not column names
  • Text-to-SQL invents columns

How it works

  1. Profile the database first. Every table and column is profiled automatically: type, null rate, cardinality, value ranges for numbers, top values for categories. The profile is checked against direct SQL so the agent reasons over facts, not guesses.

  2. Teach it the vocabulary. A model writes a one-line description and a handful of synonyms for every column at temperature zero, so “loan amount” and “LTV” land on the right fields.

  3. Retrieve before generating. A retrieval agent combines an entity index, vector search over the domain knowledge and fuzzy column and value matching (“york” → New York) into a summary of the tables, columns and intent the question needs.

  4. Plan as JSON, not SQL. The model outputs a filter plan — fields, operators, values — validated against a schema. Unknown fields are rejected; an ambiguous term such as “price” triggers a clarifying question instead of a guess.

  5. Build and check the SQL in code. A deterministic generator turns the plan into SQL, validates it against the schema, blocks anything that writes, and retries a failed validation at most twice.

  6. Pick the model per job. Each component was benchmarked side by side on real columns: the larger model kept the description writing, where quality drives matching, and a model about 90% cheaper took over entity grouping, where it did as well or better.

After

Same question, same SQL, same answer

Stack

NL2SQLAI AgentReal EstatePrivate Credit

Why it holds up

Determinism is the product. The same question produces the same plan, the same SQL and the same rows, every query is logged with its parameters, and a column the model invents simply cannot reach the database. That is the bar a credit committee needs before it trusts a chat window over its own deal book.

Related service: Hire vetted AI engineers

Get started

Talk to the engineer who will build it.

You will speak with me directly. Bring the use case, the data and the constraints, and I will give you a straight view on feasibility, effort and the first thing to ship.

Cat YungBook a call

Hong Kong & London time zones