Cert EspressoLearn. Practise. Find your flow.

A LITTLE FOCUS.
A BIG NEXT STEP.

Your pace. Your space.
Databricks · Databricks Context Engineer Associate

Genie Agents: SQL Expressions and Trusted Assets

Databricks Context Engineer Associate · Lesson 5 of 18 · 25:55

YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗

Learning with these videos? Subscribe for new courses and exam-style questions.

In this lesson

Prepare for the Databricks Certified Context Engineer Associate exam. In this lesson: building a focused Genie Agent, SQL expressions versus text instructions, example queries, trusted assets, sample questions, and benchmarks, and comparing prompt configurations in MLflow to find the element that drives the cost and quality trade-off. Includes three original practice questions.

Study notes

The text of this lesson, to read at your own pace. Information as of November 2026.

Two questions from the team

Thistledown's leasing analysts want to ask questions about occupancy and rents in plain English, so the data team builds them a Genie Agent. At the same time, the support team tests a longer system prompt that costs twice as much per request, and wonders whether it is worth it. This lesson covers how to configure and validate a Genie Agent, and how to compare two prompt configurations with MLflow.

Building a Genie Agent

A Genie Agent, formerly called a Genie space, answers business questions in natural language by writing SQL over the data you give it. Start small: one audience, one purpose, and ideally five tables or fewer, prejoined into views or metric views when needed. Genie relies on the names and descriptions of tables and columns in Unity Catalog, so well documented tables come first. In the agent itself, you can add local descriptions and synonyms, without overwriting Unity Catalog. And prompt matching gives Genie representative values, so it can map a word like Northside to the exact value stored in a column.

Instructions and SQL expressions

Business terms belong in SQL expressions: measures like occupancy rate, filters like active lease, and dimensions like portfolio. Genie applies them exactly as written, which is more reliable than explaining the logic in prose. Text instructions are the last resort, for global guidance that SQL cannot express, like formatting rules or a fiscal calendar. Keep them few and well organized, since too many instructions make it harder for Genie to prioritize, and only text instructions shape its summaries. To make Genie ask for clarification, state the trigger, the missing details, the required action, and an example question.

Examples and trusted assets

Example SQL queries teach Genie how to answer complex or multi part questions, and each one should be titled with the most typical phrasing of the question. Parameterized example queries and SQL functions are trusted assets: when Genie uses one, the answer is marked as verified, and users need the execute privilege on the functions. Sample questions show users what they can ask, while benchmark questions let you score the agent's accuracy again and again. Before going to production, run the benchmarks, read the generated SQL, and let a business user test the agent. Then keep improving it from the questions real users ask.

Comparing prompt configurations

To compare two system prompt configurations, run both in MLflow on the same evaluation dataset, with the same judges. Log the quality metrics, and also the tokens and latency per request, so that each run shows its cost next to its quality. A higher token configuration is justified only when its quality gain matters for the task, and is larger than the noise between repeated runs. To find the element that drives the trade off, remove one element at a time, like the examples, a policy section, or extra retrieved context, and rerun. At equal quality, keep the cheaper configuration.

Recap

Let's recap. A Genie Agent starts small, focused on one audience, with well documented tables. Business terms go in SQL expressions, and text instructions are the last resort. Example queries, trusted assets, sample questions, and benchmarks make it reliable and measurable. Compare prompt configurations in MLflow on the same data, with quality and cost side by side. And remove one element at a time to find what drives the trade off.

Quick checks for this lesson

The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.

  1. The data team wants to add all 80 tables of the property catalog to the analysts’ Genie Agent, to be safe. What should it do instead?

    • Add all 80 tables, and let Genie choose
    • Prejoin a few views or metric views for leasing questions
    • Create one Genie Agent per table
    • Describe every table in the text instructions
    Show the answer

    Prejoin a few views or metric views for leasing questions

    Keep the agent focused, with a few views or metric views prejoined for the leasing questions. “Add all 80 tables, and let Genie choose” is wrong, since eighty tables exceed the limit, and unfocused data lowers accuracy. “Create one Genie Agent per table” is wrong, since one agent per table would split questions that need several tables. And “Describe every table in the text instructions” is wrong, since describing tables in text instructions is a last resort, and adds noise to every prompt.

  2. Analysts ask for the occupancy rate of the north portfolio, and Genie computes it differently almost every time. What is the most reliable fix?

    • Define occupancy rate as a SQL expression measure
    • Explain occupancy rate in a text instruction
    • Add a sample question with this phrasing
    • Add a benchmark question for it
    Show the answer

    Define occupancy rate as a SQL expression measure

    Define occupancy rate once as a SQL expression, a measure that Genie applies exactly as written. “Explain occupancy rate in a text instruction” is wrong, since a definition in prose is less reliable than the logic in SQL. “Add a sample question with this phrasing” is wrong, since a sample question guides users, but does not define how to compute the rate. And “Add a benchmark question for it” is wrong, since a benchmark measures the problem without fixing it.

  3. Configuration B uses 2.5 times the tokens of A. Its only gain is on maintenance requests, and it comes from six examples it adds. What should the team do?

    • Adopt configuration B as it is
    • Keep A, since any token increase is too costly
    • Pick the run with the single highest metric
    • Add only those six examples to A, then rerun
    Show the answer

    Add only those six examples to A, then rerun

    Add only those six examples to configuration A, then rerun the evaluation to confirm the gain at a lower cost. “Adopt configuration B as it is” is wrong, since the rest of configuration B costs tokens and adds nothing. “Keep A, since any token increase is too costly” is wrong, since it throws away a real gain on maintenance requests. And “Pick the run with the single highest metric” is wrong, since a single highest metric hides the cost, and the other metrics.