Skip to main content

Overview

Custom Metrics and Segments are defined using the Fiddler Query Language (FQL), a flexible set of constants, operators, and functions which can accommodate a large variety of metrics.

Definitions

TermDefinition
Row-level functionA function which executes row-wise for a set of data. Returns a value for each row.
Aggregate functionA function which executes across rows. Returns a single value for a given set of rows.

FQL Rules

  • Column names can be referenced by name either with double quotes (“my_column”) or with no quotes (my_column).
  • Single quotes (’) are used to represent string values.

Data Types

FQL distinguishes between three data types:
Data typeSupported valuesExamplesSupported Model Schema Data Types
NumberAny numeric value (integers and floats are both included)<p><code>10</code><br><code>2.34</code></p><p><code>DataType.INTEGER</code><br><code>DataType.FLOAT</code></p>
BooleanOnly true and false<p><code>true</code><br><code>false</code></p>DataType.BOOLEAN
StringAny value wrapped in single quotes (')<p><code>‘This is a string.’</code><br><code>‘200.0’</code></p><p><code>DataType.CATEGORY</code><br><code>DataType.STRING</code></p>

Constants

SymbolDescription
trueBoolean constant for true expressions
falseBoolean constant for false expressions
nullRepresents an absent or missing value. Use as a return value in conditional expressions — for example: if(is_null(x), null, x * 2). To test whether a value is null, use is_null() or is_not_null().

Operators

SymbolDescriptionSyntaxReturnsExamples
^ExponentiationNumber ^ NumberNumber<p><code>2.5 ^ 4</code><br><code>(column1 - column2)^2</code></p>
-Unary negation-NumberNumber-column1
*MultiplicationNumber * NumberNumber<p><code>2 * 10</code><br><code>2 * column1</code><br><code>column1 * column2</code><br><code>sum(column1) * 10</code></p>
/DivisionNumber / NumberNumber<p><code>2 / 10</code><br><code>2 / column1</code><br><code>column1 / column2</code><br><code>sum(column1) / 10</code></p>
%ModuloNumber % NumberNumber<p><code>2 % 10</code><br><code>2 % column1</code><br><code>column1 % column2</code><br><code>sum(column1) % 10</code></p>
+AdditionNumber + NumberNumber<p><code>2 + 2</code><br><code>2 + column1</code><br><code>column1 + column2</code><br><code>average(column1) + 2</code></p>
-SubtractionNumber - NumberNumber<p><code>2 - 2</code><br><code>2 - column1</code><br><code>column1 - column2</code><br><code>average(column1) - 2</code></p>
&lt;Less thanNumber &lt; NumberBoolean<p><code>10 < 20</code><br><code>column1 < 10</code><br><code>column1 < column2</code><br><code>average(column2) < 5</code></p>
&lt;=Less than or equal toNumber &lt;= NumberBoolean<p><code>10 <= 20</code><br><code>column1 <= 10</code><br><code>column1 <= column2</code><br><code>average(column2) <= 5</code></p>
>Greater thanNumber > NumberBoolean<p><code>10 > 20</code><br><code>column1 > 10</code><br><code>column1 > column2</code><br><code>average(column2) > 5</code></p>
>=Greater than or equal toNumber >= NumberBoolean<p><code>10 >= 20</code><br><code>column1 >= 10</code><br><code>column1 >= column2</code><br><code>average(column2) >= 5</code></p>
==EqualsNumber == NumberBoolean<p><code>10 == 20</code><br><code>column1 == 10</code><br><code>column1 == column2</code><br><code>average(column2) == 5</code></p>
!=Does not equalNumber != NumberBoolean<p><code>10 != 20</code><br><code>column1 != 10</code><br><code>column1 != column2</code><br><code>average(column2) != 5</code></p>
notLogical NOTnot BooleanBoolean<p><code>not true</code><br><code>not column1</code></p>
andLogical ANDBoolean and BooleanBoolean<p><code>true and false</code><br><code>column1 and column2</code></p>
orLogical ORBoolean or BooleanBoolean<p><code>true or false</code><br><code>column1 or column2</code></p>

Constant functions

SymbolDescriptionSyntaxReturnsExamples
e()Base of the natural logarithme()Numbere() == 2.718281828459045
pi()The ratio of a circle’s circumference to its diameterpi()Numberpi() == 3.141592653589793

Row-level functions

Row-level functions can be applied either to a single value or to a column/row expression (in which case they are mapped element-wise to each value in the column/row expression).
SymbolDescriptionSyntaxReturnsExamples
if(condition, value1, value2)<p>Evaluates <code>condition</code> and returns <code>value1</code> if true, otherwise returns <code>value2</code>.<br><code>value1</code> and <code>value2</code> must have the same type.</p>if(Boolean, Any, Any)Any<p><code>if(false, ‘yes’, ‘no’) == ‘no’</code><br><code>if(column1 == 1, ‘yes’, ‘no’)</code></p>
length(x)Returns the length of string x.length(String)Numberlength('Hello world') == 11
to_string(x)Converts a value x to a string.to_string(Any)String<p><code>to_string(42) == ‘42’</code><br><code>to_string(true) == ‘true’</code></p>
startswith(str, prefix)Returns true if str starts with prefix.startswith(String, String)Booleanstartswith('abcde', 'abc')
substring(str, offset, length)Returns a substring of str of length length from offset offset. The first character has an offset of 1.substring(String, Number, Number)Stringsubstring('abcde', 2, 3) == 'bcd'
match(str, regex)Returns true if str matches the pattern regex in re2 regular syntax.match(String, String)Booleanmatch('abcde', 'a.c.*e')
is_null(x)Returns true if x is null, otherwise returns false.is_null(Any)Boolean<p><code>is_null(”) == true</code><br><code>is_null(“column1”)</code></p>
is_not_null(x)Returns true if x is not null, otherwise returns false.is_null(Any)Boolean<p><code>is_not_null(”) == false</code><br><code>`is_not_null(“column1”)</code></p>
abs(x)Returns the absolute value of number x.abs(Number)Numberabs(-3) == 3
exp(x)Returns e^x, where e is the base of the natural logarithm.exp(Number)Numberexp(1) == 2.718281828459045
log(x)Returns the natural logarithm (base e) of number x.log(Number)Numberlog(e) == 1
log2(x)Returns the binary logarithm (base 2) of number x.log2(Number)Numberlog2(16) == 4
log10(x)Returns the binary logarithm (base 10) of number x.log10(Number)Numberlog10(1000) == 3
sqrt(x)Returns the positive square root of number x.sqrt(Number)Numbersqrt(144) == 12

Aggregate functions

Every Custom Metric must be wrapped in an aggregate function or be a combination of aggregate functions.
SymbolDescriptionSyntaxReturnsExamples
sum(x)Returns the sum of a numeric column or row expression x.sum(Number)Numbersum(column1 + column2)
average(x)Returns the arithmetic mean/average value of a numeric column or row expression x.average(Number)Numberaverage(2 * column1)
count(x)Returns the number of non-null rows of a column or row expression x.count(Any)Numbercount(column1)
min(x)Returns the minimum value of a numeric column or row expression x.min(Number)Numbermin(column1)
max(x)Returns the maximum value of a numeric column or row expression x.max(Number)Numbermax(column1)
quantile(x, level)Returns the quantile (percentile) of a numeric column or row expression x at the specified level. The level must be a constant between 0.0 and 1.0 (defaults to 0.5 if not specified).quantile(Number, level=Number)Number<p><code>quantile(Output, level=0.5)</code><br><code>quantile(latency_ms, level=0.95)</code><br><code>quantile(response_time, level=0.99)</code></p>
greatest(agg1, agg2, ...)Returns the maximum value between multiple numerical aggregatesgreatest(Number, Number, ...)Numbergreatest(sum(col1), sum(col2), sum(col3))
least(agg1, agg2, ...)Returns the minimum value between multiple numerical aggregatesleast(Number, Number, ...)Numberleast(sum(col1), sum(col2), sum(col3))
min(x) / max(x) vs least(...) / greatest(...): min(x) and max(x) aggregate a single row-level expression across rows (e.g., min(column1) returns the smallest value of column1 across all rows in the time window). least(...) and greatest(...) compare multiple aggregate results and return the smallest or largest among them (e.g., least(sum(col1), sum(col2)) compares two already-computed sums).
Built-in metric functions are available for ML models only (classification, regression, and ranking tasks). They are not supported in custom metrics for agentic or GenAI applications. For agentic applications, use the attribute() function with aggregate functions instead — see Custom Metrics for Agentic Applications.

Built-in metric functions

SymbolDescriptionSyntaxReturnsExamples
jsd(column, baseline)The Jensen-Shannon distance of column column with respect to baseline baseline.jsd(Any, String)Numberjsd(column1, 'my_baseline')
psi(column, baseline)The population stability index of column column with respect to baseline baseline.psi(Any, String)Numberpsi(column1, 'my_baseline')
null_violation_count(column)Number of rows with null values in column column.null_violation_count(Any)Numbernull_violation_count(column1)
range_violation_count(column)Number of rows with out-of-range values in column column.range_violation_count(Any)Numberrange_violation_count(column1)
type_violation_count(column)Number of rows with invalid data types in column column.type_violation_count(Any)Numbertype_violation_count(column1)
any_violation_count(column)Number of rows with at least one Data Integrity violation in column.any_violation_count(Any)Numberany_violation_count(column1)
traffic()Total row count. Includes null rows.traffic()Numbertraffic()
tp(class)True positive boolean state. Available for binary classification and multiclass classification models. For multiclass, class is used to specify the positive class.tp(class=Optional[String])Boolean<p><code>tp()</code><br><code>tp(class=‘class1’)</code></p>
tn(class)True negative boolean state. Available for binary classification and multiclass classification models. For multiclass, class is used to specify the positive class.tn(class=Optional[String])Boolean<p><code>tn()</code><br><code>tn(class=‘class1’)</code></p>
fp(class)False positive boolean state. Available for binary classification and multiclass classification models. For multiclass, class is used to specify the positive class.fp(class=Optional[String])Boolean<p><code>fp()</code><br><code>fp(class=‘class1’)</code></p>
fn(class)False negative boolean state. Available for binary classification and multiclass classification models. For multiclass, class is used to specify the positive class.fn(class=Optional[String])Boolean<p><code>fn()</code><br><code>fn(class=‘class1’)</code></p>
precision(target, threshold)<p>Precision between target and output. Available for binary classification model tasks.<br>If <code>target</code> is specified, it will be used in place of the default target column.</p>precision(target=Optional[Any], threshold=Optional[Number])Number<p><code>precision()</code><br><code>precision(target=column1)</code><br><code>precision(threshold=0.5)</code><br><code>precision(target=column1, threshold=0.5)</code></p>
recall(target, threshold)<p>Recall between target and output. Available for binary classification model tasks.<br>If <code>target</code> is specified, it will be used in place of the default target column.</p>recall(target=Optional[Any], threshold=Optional[Number])Number<p><code>recall()</code><br><code>recall(target=column1)</code><br><code>recall(threshold=0.5)</code><br><code>recall(target=column1, threshold=0.5)</code></p>
f1_score(target, threshold)<p>F1 score between target and output. Available for binary classification model tasks.<br>If <code>target</code> is specified, it will be used in place of the default target column.</p>f1_score(target=Optional[Any], threshold=Optional[Number])Number<p><code>f1_score()</code><br><code>f1_score(target=column1)</code><br><code>f1_score(threshold=0.5)</code><br><code>f1_score(target=column1, threshold=0.5)</code></p>
fpr(target, threshold)<p>False positive rate between target and output. Available for binary classification model tasks.<br>If <code>target</code> is specified, it will be used in place of the default target column.</p>fpr(target=Optional[Any], threshold=Optional[Number])Number<p><code>fpr()</code><br><code>fpr(target=column1)</code><br><code>fpr(threshold=0.5)</code><br><code>fpr(target=column1, threshold=0.5)</code></p>
auroc(target)<p>Area under the ROC curve between target and output. Available for binary classification model tasks.<br>If <code>target</code> is specified, it will be used in place of the default target column.</p>auroc(target=Optional[Any])Number<p><code>auroc()</code><br><code>auroc(target=column1)</code></p>
geometric_mean(target, threshold)<p>Geometric mean score between target and output. Available for binary classification model tasks.<br>If <code>target</code> is specified, it will be used in place of the default target column.</p>geometric_mean(target=Optional[Any], threshold=Optional[Number])Number<p><code>geometric_mean()</code><br><code>geometric_mean(target=column1)</code><br><code>geometric_mean(threshold=0.5)</code><br><code>geometric_mean(target=column1, threshold=0.5)</code></p>
expected_calibration_error(target)<p>Expected calibration error between target and output. Available for binary classification model tasks.<br>If <code>target</code> is specified, it will be used in place of the default target column.</p>expected_calibration_error(target=Optional[Any])Number<p><code>expected_calibration_error()</code><br><code>expected_calibration_error(target=column1)</code></p>
log_loss(target)<p>Log loss (binary cross entropy) between target and output. Available for binary classification model tasks.<br>If <code>target</code> is specified, it will be used in place of the default target column.</p>log_loss(target=Optional[Any])Number<p><code>log_loss()</code><br><code>log_loss(target=column1)</code></p>
calibrated_threshold(target)<p>Optimal threshold value for a high TPR and a low FPR. Available for binary classification model tasks.<br>If <code>target</code> is specified, it will be used in place of the default target column.</p>calibrated_threshold(target=Optional[Any])Number<p><code>calibrated_threshold()</code><br><code>calibrated_threshold(target=column1)</code></p>
accuracy(target, threshold)<p>Accuracy score between target and outputs. Available for multiclass classification model tasks.<br>If <code>target</code> is specified, it will be used in place of the default target column.</p>accuracy(target=Optional[Any], threshold=Optional[Number])Number<p><code>accuracy()</code><br><code>accuracy(target=column1)</code><br><code>accuracy(threshold=0.5)</code><br><code>accuracy(target=column1, threshold=0.5)</code></p>
log_loss(target)<p>Log loss score between target and outputs. Available for multiclass classification model tasks.<br>If <code>target</code> is specified, it will be used in place of the default target column.</p>log_loss(target=Optional[Any])Number<p><code>log_loss()</code><br><code>log_loss(target=column1)</code></p>
r2(target)<p>R-squared score between target and output. Available for regression model tasks.<br>If <code>target</code> is specified, it will be used in place of the default target column.</p>r2(target=Optional[Any])Number<p><code>r2()</code><br><code>r2(target=column1)</code></p>
mse(target)<p>Mean squared error between target and output. Available for regression model tasks.<br>If <code>target</code> is specified, it will be used in place of the default target column.</p>mse(target=Optional[Any])Number<p><code>mse()</code><br><code>mse(target=column1)</code></p>
mae(target)<p>Mean absolute error between target and output. Available for regression model tasks.<br>If <code>target</code> is specified, it will be used in place of the default target column.</p>mae(target=Optional[Any])Number<p><code>mae()</code><br><code>mae(target=column1)</code></p>
mape(target)<p>Mean absolute percentage error between target and output. Available for regression model tasks.<br>If <code>target</code> is specified, it will be used in place of the default target column.</p>mape(target=Optional[Any])Number<p><code>mape()</code><br><code>mape(target=column1)</code></p>
wmape(target)<p>Weighted mean absolute percentage error between target and output. Available for regression model tasks.<br>If <code>target</code> is specified, it will be used in place of the default target column.</p>wmape(target=Optional[Any])Number<p><code>wmape()</code><br><code>wmape(target=column1)</code></p>
map(target)<p>Mean average precision score. Available for ranking model tasks.<br>If <code>target</code> is specified, it will be used in place of the default target column.</p>map(target=Optional[Any])Number<p><code>map()</code><br><code>map(target=column1)</code></p>
ndcg_mean(target)<p>Mean normalized discounted cumulative gain score. Available for ranking model tasks.<br>If <code>target</code> is specified, it will be used in place of the default target column.</p>ndcg_mean(target=Optional[Any])Number<p><code>ndcg_mean()</code><br><code>ndcg_mean(target=column1)</code></p>
query_count(target)<p>Count of ranking queries. Available for ranking model tasks.<br>If <code>target</code> is specified, it will be used in place of the default target column.</p>query_count(target=Optional[Any])Number<p><code>query_count()</code><br><code>query_count(target=column1)</code></p>
gini(actual, predicted)Gini coefficient derived from the Lorenz curve. Measures how well a model’s predicted scores rank actual values. Available for ML custom metrics (all model task types, including regression). Both actual and predicted are required keyword arguments of type Number. To compute the normalized Gini coefficient, divide by the ideal Gini: gini(actual=Target, predicted=Score) / gini(actual=Target, predicted=Target). For binary classification, the normalized Gini can also be derived from AUC: 2 * auroc() - 1.gini(actual=Number, predicted=Number)Numbergini(actual=Target, predicted=Score)