AI Filter Function
The AI_FILTER function evaluates a natural-language
predicate or yes or no question and returns a boolean result.
Note:
For information about limitations with using AI Functions, see Known Issues with AI Functions.
The function returns TRUE only when the model responds with a “yes”. Any
other response is treated as FALSE. There is no need to specify the model to answer
yes or no. The function handles the output format and you only needs to specify the
predicate or question. Because it returns a boolean value, you can use the
AI_FILTER function anywhere a boolean expression is valid, such
as:
- WHERE clause
- JOIN conditions
- CASE expressions
Use this function for:
- Sentiment-based filtering
- Intent or urgency detection
- Semantic matching
- Relevance evaluation
Where You Can Use the
AI_FILTER Function
You can use this function in filter expression editors, for example:
- Workbook's filter expression editor
- Data Flow's filter step editor
- Data Preparation's filter expression editor
- Semantic Modeler's Data Filters editors
You can also use this function in join conditions, for example a semantic model's physical join expression.
You can only use the function as a CASE condition when you add new columns, transform existing columns, or edit column expressions. You can't use it as a column value by itself.
You can use this function in various editors, for example:
- Workbook's Create Calculation editor
- Data Preparation's Create Column editor
- Data Flow's Add Columns editor
- Data Flow's Transform Column editor
- Semantic Modeler's Create New Column editor
You can't use this function as a column value by itself when adding new
columns, transforming existing columns, or editing column expressions. Some editors
may allow you to save the AI_FILTER by itself, but results will
encounter errors.
Syntax
AI_FILTER(<predicate>, <input>, <model_id>)
Parameters
| Parameter | Description |
|---|---|
predicate |
String
|
input |
String
|
model_id |
String literal
|
Examples
This example filters rows that contain only negative reviews.
SELECT *
FROM REVIEWS
WHERE AI_FILTER(
'Is the review negative?',
'Review: ' || REVIEW_TEXT,
'model'.'id'
);
This example matches reviews with the products reviewed.
SELECT *
FROM REVIEWS R
INNER JOIN PRODUCTS P
ON AI_FILTER(
'Does the review describe the same product as the description?',
'Review: ' || R.REVIEW_TEXT || '; Description: ' || P.DESCRIPTION,
'model'.'id'
);
Best Practices
Keep these best practices in mind when you use the
AI_FILTER function:
- Keep predicates and questions short, clear, and unambiguous.
- Phrase predicates as explicit yes or no questions.
- Avoid compound or multi-part questions that require nuanced answers.
- Provide descriptive labels for each input value to help the model understand what each piece of data represents.
- Ensure the prompt references the same labels used in the input.
- Use punctuation and separators to clearly distinguish between multiple input values.
- Cast non-string expressions / columns to string.
- Use consistent and predictable labels across queries to improve reliability.
- Keep input text focused because long inputs reduce classification accuracy.
- Remember that only "yes" evaluates to TRUE.