All Products
Search
Document Center

ApsaraDB for SelectDB:AI_MASK

Last Updated:Mar 28, 2026

Masks sensitive information in text that matches specified labels.

Syntax

AI_MASK([<resource_name>], <text>, <labels>)

Parameters

ParameterRequiredDescription
<resource_name>NoThe name of the AI resource to use. If omitted, the session variable default_ai_resource is used.
<text>YesThe input text that may contain sensitive information.
<labels>YesAn array of label strings specifying the types of information to mask, such as ARRAY('name', 'phone', 'email').

Return value

  • Returns the input text with sensitive values replaced by [MASKED].

  • Returns NULL if any input parameter is NULL.

  • Because the result is generated by a Large Language Model (LLM), the output may vary between calls.

Examples

Example 1: Use the default AI resource

Set the default AI resource for the session, then call AI_MASK to redact a name and age.

SET default_ai_resource = 'resource_name';
SELECT AI_MASK('Wccccat is a 20-year-old SelectDB community contributor.', ['name', 'age']) AS Result;

Result:

+--------------------------------------------------------+
| Result                                                 |
+--------------------------------------------------------+
| [MASKED] is a [MASKED] SelectDB community contributor. |
+--------------------------------------------------------+

Example 2: Specify the AI resource inline

Pass the resource name directly as the first argument to mask an email address and phone number.

SELECT AI_MASK(
  'resource_name',
  'My email is rarity@example.com and my phone is 123-456-7890',
  ['email', 'phone_num']
) AS RESULT;

Result:

+-----------------------------------------------+
| RESULT                                        |
+-----------------------------------------------+
| My email is [MASKED] and my phone is [MASKED] |
+-----------------------------------------------+