Use certified answers in Genie spaces

Preview

This feature is in Public Preview.

This article defines certified answers and explains how to use them to increase trust and confidence in responses provided in a Genie space.

What are certified answers?

Certified answers allow you to explicitly define validated, parameterized SQL queries as recipes for answering common questions. They can reduce the likelihood of non-technical users receiving responses that are misleading, incorrect, or hard to interpret. Certified answers help the Genie space provide accurate answers to common questions and let users know when the response they receive has been verified.

Certified answer response

Note

Certified answers are not a substitute for all other instructions. Databricks recommends using certified answers only for recurring, well-established questions. They provide exact answers to specific questions and are not reused by the Assistant to address adjacent questions.

Why create certified answers?

Genie spaces return the result of a generated SQL query to answer user questions. Business users can potentially include jargon that is hard to parse for the large language model (LLM) that generates queries. Suppose a business user provides a prompt like, “Show me the open pipeline in our APAC region.” If open pipeline does not correspond directly to a field in one of the tables in your Genie space, the user might get an empty result set accompanied by a generated SQL query, as in the following response:

Empty result response

For most business users, it is difficult to interpret or troubleshoot this response. Genie space authors can define certified answers to provide trusted responses for questions like this.

Define a certified answer

To define a certified answer, identify the question you expect users to ask. Then do the following:

  1. Define and test a SQL query that answers the question.

    The following is an example query designed to answer the question in the previous example. The table this query returns includes results from all regions in the data.

    SELECT
    o.id AS `OppId`,
    a.region__c AS `Region`,
    o.name AS `Opportunity Name`,
    o.forecastcategory AS `Forecast Category`,
    o.stagename,
    o.closedate AS `Close Date`,
    o.amount AS `Opp Amount`
    FROM
    users.user_name.opportunity o
    JOIN catalog.schema.accounts a ON o.accountid = a.id
    
    WHERE
    o.forecastcategory = 'Pipeline' AND
    o.stagename NOT LIKE '%closed%';
    
  2. Define a Unity Catalog function.

    Your Unity Catalog function should parameterize the query and produce results matching the specific conditions a user might inquire about.

    See Create a SQL table function to learn how to define a Unity Catalog function.

    The following function takes a list of regions and returns a table. The comments provided in the function definitions are critical for instructing the Genie space on when and how to invoke this function. This example includes comments in the function’s parameter definition and comments defined in the SQL table function that explain what the function does.

    • Parameter comments: The open_opps_in_region function expects an array of strings as a parameter. The comment includes an example of the expected input. If no parameter is supplied, the default value is NULL.

    • Function comments: The comment in the SQL table function explains what the function does.

    The associated SQL query has been adjusted to include the Unity Catalog function in the WHERE clause.

    CREATE OR REPLACE FUNCTION users.user_name.open_opps_in_region (
    regions ARRAY<STRING> COMMENT 'List of regions.  Example: ["APAC", "EMEA"]' DEFAULT NULL
    ) RETURNS TABLE
    COMMENT 'Addresses questions about the pipeline in a region by returning a list of all the open opportunities.'
    RETURN
    
    SELECT
        o.id AS `OppId`,
        a.region__c AS `Region`,
        o.name AS `Opportunity Name`,
        o.forecastcategory AS `Forecast Category`,
        o.stagename,
        o.closedate AS `Close Date`,
        o.amount AS `Opp Amount`
    FROM
        catalog.schema.accounts.opportunity o
        JOIN catalog.schema.accounts a ON o.accountid = a.id
    WHERE
        o.forecastcategory = 'Pipeline' AND
        o.stagename NOT LIKE '%closed%' AND
        isnull(open_opps_in_region.regions) OR array_contains(open_opps_in_region.regions, region__c);
    

    When you run the code to create a function, it’s registered to the currently active schema by default. See Custom SQL functions in Unity Catalog.

  3. Add certified answer.

    After being published as a Unity Catalog function, a user with at least CAN EDIT permission on the Genie space can add it in the Instructions tab of the Genie space.

    Add certified answer button

Required permissions

Genie space authors with at least CAN EDIT permission on a Genie space can add or remove certified answers.

Genie space users must have CAN USE permission on the catalog and schema that contains the function. To invoke a certified answer, they must have EXECUTE permission on the function in Unity Catalog. Unity Catalog securable objects inherit permissions from their parent containers. See Securable objects in Unity Catalog.

To simplify sharing in a Genie space, Databricks recommends creating a dedicated schema to contain all of the functions that you want to use in your Genie space.