Custom LLM Function similar to Databricks built in AI functions

neha89
New Contributor II

Hi Team,

I am new to Databricks and working on Gen AI requirements.

Task - Build custom prompt with set of instructions to classify incident e.g. False Positive or True Positive. Input will be columns in Delta Table

Can I build custom LLM function with custom prompt and invoke it similar to built in AI function as SQL query. Or I should register function as model serving endpoint and then use this endpoint to apply on each record in Delta Table. Kindly provide suggestions

Alberto_Umana
Databricks Employee
Databricks Employee

Hi @neha89 -

You can use below approach:

Databricks provides AI Functions that allow invoking large language models directly within SQL queries. Here’s how this approach works:

  • Define a Custom AI Function: You can define a SQL function using ai_query or similar built-in AI capabilities, which directly interact with a generative AI model (e.g., Databricks Foundation Models or OpenAI models).
  • Prompt Engineering: Build your classification prompt that receives Delta Table columns as input and generates the required classification (False Positive/True Positive).
  • Integrating with Delta Table: Use this SQL function to compute the classification and update the Delta Table
    1. Create an AI Function using ai_query.
    2. Apply the function in an UPDATE or SELECT statement for your Delta Table.
    3. Execute through standard SQL pipelines.

View solution in original post

neha89
New Contributor II

Thank you @Alberto_Umana for explanation. This is really helpful!

Alberto_Umana
Databricks Employee
Databricks Employee

No problem, if you have any other question, let me know!