ai_classify function

Applies to: check marked yes Databricks SQL


This feature is in Public Preview.

In the preview:

  • The underlying language model can handle several languages, however these functions are tuned for English.

  • There is rate limiting for the underlying Foundation Model APIs. See Foundation Model APIs limits to update these limits.

The ai_classify() function allows you to invoke a state-of-the-art generative AI model to classify input text according to labels you provide using SQL. This function uses a chat model serving endpoint made available by Databricks Foundation Model APIs.



The underlying models that might be used at this time are licensed under the Apache 2.0 license or Llama 2 community license. Databricks recommends reviewing these licenses to ensure compliance with any applicable terms. If models emerge in the future that perform better according to Databricks’s internal benchmarks, Databricks may change the model (and the list of applicable licenses provided on this page).

Currently, Mixtral-8x7B Instruct is the underlying model that powers these AI functions.


ai_classify(content, labels)


  • content: A STRING expression, the text to be classified.

  • labels: An ARRAY<STRING> literal, the expected output classification labels. Must contain at least 2 elements, and no more than 20 elements.


A STRING. The value matches one of the strings provided in the labels argument. Returns null if the content cannot be classified.


> SELECT ai_classify("My password is leaked.", ARRAY("urgent", "not urgent"));

    ai_classify(description, ARRAY('clothing', 'shoes', 'accessories', 'furniture')) AS category