BMEL Function Reference¶
BMEL (BizMetry Expression Language) version 1.7.0 · 117 functions across 8 categories.
Every function lives in the bmel: namespace and takes its arguments by position. For the syntax of field references, operators and types, see the BMEL Language.
Categories¶
| Category | Functions | What it covers |
|---|---|---|
| LLM | 7 | Tokens, cost, embeddings and safety scores of LLM prompts and responses. |
| String | 14 | Text manipulation, text metrics and text similarity. |
| Math | 18 | Arithmetic, rounding, scaling and scoring of single values. |
| Array & Statistics | 24 | Iteration, aggregation and statistics over arrays and the invocations of MANY operations. |
| Logic & Control Flow | 8 | Conditions, branching, fallbacks and loops. |
| JSON | 12 | JSON objects, imported resources and client identification. |
| Date & Time | 30 | Current time, date parts, date arithmetic and formatting. |
| Type Conversion | 4 | Explicit conversion between types. |
Reading a Function Page¶
Each function has its own page with:
- Category and Returns — where the function belongs and the type of its result.
- Signature — the argument names and types, in order. Optional arguments are in brackets, and
...marks a variable number of arguments. The names document each position; you don't write them in the call. - Description and Arguments — what the function does and what each argument means.
- Examples — expressions ready to paste into the BMEL editor, each with a title that says what it computes.
Signature as shown on a function page
bmel:round(expr: bmel:number, decimals: bmel:integer)
The same function, as you write it
bmel:round({getOrder:Response Payload}.$.amount, 2)
LLM¶
Tokens, cost, embeddings and safety scores of LLM prompts and responses.
| Function | Returns | Description |
|---|---|---|
bmel:chunk-count | integer | Returns the number of chunks that a text would be split into given a fixed chunk size in tokens. |
bmel:compression-ratio | number | Returns the token compression ratio between an original text and a compressed/summarized version: token-count(original) / token-count(compressed). |
bmel:estimate-cost | number | Returns the estimated cost in USD for a given number of tokens and a named model. |
bmel:llm-inference-bias | number | Measures semantic bias between a prompt and an LLM response by computing their cosine similarity at the embedding level. |
bmel:prompt-toxicity-score | number | Computes a toxicity score for the given prompt text in the range [0.0, 1.0]. |
bmel:token-count | integer | Calculates the number of tokens required to represent the given content using the specified tokenizer. |
bmel:truncate-to-tokens | string | Truncates a string to at most maxTokens tokens using the specified tokenizer, cutting at a word boundary where possible. |
String¶
Text manipulation, text metrics and text similarity.
| Function | Returns | Description |
|---|---|---|
bmel:concat | string | Concatenates two or more values into a single string. |
bmel:contains | boolean | Returns true if the expression contains the specified substring. |
bmel:contains-any | boolean | Returns true if the text contains at least one string from the provided array. |
bmel:jaccard-similarity | number | Returns the Jaccard similarity between two strings, computed as |intersection(tokens(a), tokens(b))| / |union(tokens(a), tokens(b))|. |
bmel:length | integer | Returns the number of characters in a string, or the number of elements in an array. |
bmel:levenshtein-distance | integer | Returns the Levenshtein edit distance between two strings: the minimum number of single-character insertions, deletions, or substitutions required to transform a into b. |
bmel:lower | string | Converts all characters of the string to lowercase. |
bmel:matches-pattern | boolean | Returns true if the text matches the given regular expression pattern. |
bmel:replace | string | Replaces all occurrences of a substring within the expression with a new value. |
bmel:sentence-count | integer | Returns the number of sentences in a string, detected by terminal punctuation (. ! ?). |
bmel:substring | string | Extracts characters from a string between start index (inclusive) and end index (exclusive). |
bmel:trim | string | Removes leading and trailing whitespace from a string. |
bmel:upper | string | Converts all characters of the string to uppercase. |
bmel:word-count | integer | Returns the number of whitespace-delimited words in a string. |
Math¶
Arithmetic, rounding, scaling and scoring of single values.
| Function | Returns | Description |
|---|---|---|
bmel:abs | number | Returns the absolute value of a number. |
bmel:avg-inline-of | number | Returns the arithmetic mean of two or more inline numeric arguments. |
bmel:ceil | integer | Rounds a number up to the nearest integer. |
bmel:clamp | number | Constrains a value to be within the inclusive range [min, max]. |
bmel:floor | integer | Rounds a number down to the nearest integer. |
bmel:max-inline-of | number | Returns the maximum value from two or more inline numeric arguments. |
bmel:min-inline-of | number | Returns the minimum value from two or more inline numeric arguments. |
bmel:mod | number | Returns the remainder of dividing a by b. |
bmel:normalize | number | Applies min-max normalization to a scalar value, rescaling it to the [0, 1] range: (value - min) / (max - min). |
bmel:pow | number | Raises a base number to the power of an exponent. |
bmel:round | number | Rounds a number to a specified number of decimal places. |
bmel:sigmoid | number | Applies the sigmoid activation function to a scalar: 1 / (1 + exp(-x)). |
bmel:sign | integer | Returns -1 if the number is negative, 0 if zero, or 1 if positive. |
bmel:sla-breached | boolean | Returns true if the actual value exceeds the defined limit. |
bmel:sqrt | number | Returns the square root of a number. |
bmel:stddev-inline-of | number | Returns the population standard deviation of two or more inline numeric arguments. |
bmel:threshold | boolean | Returns true if the value falls within the inclusive range [min, max]. |
bmel:z-score | number | Returns the z-score (standard score) of a value: (value - mean) / stddev. |
Array & Statistics¶
Iteration, aggregation and statistics over arrays and the invocations of MANY operations.
| Function | Returns | Description |
|---|---|---|
bmel:avg | number | Returns the arithmetic mean of all numeric values in an array. |
bmel:count | integer | Returns the number of elements in an array. |
bmel:count-if | integer | Returns the count of elements in an array that satisfy the given boolean condition. |
bmel:cv-of | number | Returns the coefficient of variation (CV = stddev / mean) of an array, expressed as a ratio (not a percentage). |
bmel:distinct | array | Returns a new array with all duplicate values removed. |
bmel:filter | array | Returns the elements of bmel:array for which bmel:predicate is true, in their original order. |
bmel:first | any | Returns the first element of an array. |
bmel:flatten | array | Flattens one level of nested arrays into a single flat array. |
bmel:iqr-of | number | Returns the interquartile range (IQR = Q3 - Q1) of an array. |
bmel:last | any | Returns the last element of an array. |
bmel:map | array | Evaluates bmel:body once per element of bmel:array and returns the results as a new array of the same length and order. |
bmel:max-of | number | Returns the maximum numeric value in an array. |
bmel:median-of | number | Returns the median (50th percentile) of all numeric values in an array. |
bmel:min-of | number | Returns the minimum numeric value in an array. |
bmel:mode-of | any | Returns the most frequently occurring value in an array. |
bmel:outlier-count-of | integer | Returns the number of elements in an array that deviate from the mean by more than (threshold x stddev). |
bmel:percentile-latency | number | Returns the p-th percentile latency from an array of latency measurements (in milliseconds). |
bmel:percentile-of | number | Returns the p-th percentile of all numeric values in an array using linear interpolation (equivalent to NumPy percentile / Excel PERCENTILE.INC). |
bmel:range-of | number | Returns the statistical range of an array (max - min). |
bmel:softmax | array<number> | Applies the softmax function to an array of numeric logits, returning a probability distribution where all values are in (0, 1) and sum to exactly 1.0. |
bmel:stddev-of | number | Returns the population standard deviation of all numeric values in an array column. |
bmel:sum | number | Returns the sum of all numeric values in an array. |
bmel:sum-if | number | Returns the sum of numeric values in an array that satisfy the given boolean condition. |
bmel:variance-of | number | Returns the population variance of all numeric values in an array. |
Logic & Control Flow¶
Conditions, branching, fallbacks and loops.
| Function | Returns | Description |
|---|---|---|
bmel:coalesce | any | Returns the first non-null / non-empty value from the provided arguments, evaluated left to right. |
bmel:for-range | array | Iterates from bmel:from to bmel:to (both inclusive, step +1) and evaluates bmel:body at each step, collecting results into an array. |
bmel:if | any | Inline conditional (ternary): returns a if cond is true, otherwise returns b. |
bmel:not | boolean | Returns the boolean negation of the expression. |
bmel:nvl | any | Returns the expression value, or the fallback value if the expression is null or empty. |
bmel:self | any | Identity function. |
bmel:switch | any | Evaluates bmel:subject against one or more case/result pairs (left to right) and returns the result of the first matching case. |
bmel:to-enum-value | enum | Converts a bmel:string to its matching bmel:enum constant by exact case-sensitive match. |
JSON¶
JSON objects, imported resources and client identification.
| Function | Returns | Description |
|---|---|---|
bmel:get-client-by-criteria | client | Identifies the client that generated the call from one or more filters, and returns the JSON of that client. |
bmel:get-json-field | any | Returns the value of one top-level field of a JSON object. |
bmel:get-resource-by-id | json | Looks up an imported resource of the given resource type by its identifier and returns the complete resource instance as a JSON object — the record stored in Resources when it was imported from its DataSource. |
bmel:json-depth | integer | Returns the maximum nesting depth of a JSON object or array. |
bmel:json-flatten | string | Serializes a nested JSON object into a compact, single-level JSON string using dot-notation keys. |
bmel:json-keys | array | Returns an array of the top-level key names of a JSON object. |
bmel:json-merge | string | Performs a shallow merge of two JSON objects and returns the result as a JSON string. |
bmel:json-omit | string | Returns a new JSON string with the specified top-level keys removed from the input object. |
bmel:json-path | any | Extracts a value from a JSON string or object using a JSONPath expression. |
bmel:json-pick | string | Returns a new JSON string containing only the specified top-level keys from the input object. |
bmel:json-valid | boolean | Returns true if the input string is valid, parseable JSON; false otherwise. |
bmel:sizeof | integer | Calculates the byte size of the serialized representation of the given content. |
Date & Time¶
Current time, date parts, date arithmetic and formatting.
| Function | Returns | Description |
|---|---|---|
bmel:add-days | date or datetime | Adds N days to a date or datetime value. |
bmel:add-hours | datetime | Adds N hours to a datetime value. |
bmel:add-months | date or datetime | Adds N months to a date or datetime value. |
bmel:add-years | date or datetime | Adds N years to a date or datetime value. |
bmel:date-of | date | Extracts the date part from a datetime value, discarding the time component. |
bmel:day | integer | Extracts the day of the month (1-31) from a date or datetime value. |
bmel:day-of-week | integer | Returns the day of the week as an integer (1=Monday, 7=Sunday). |
bmel:day-of-year | integer | Returns the day of the year (1-366) from a date or datetime value. |
bmel:diff-days | integer | Returns the number of days between two dates (a - b). |
bmel:diff-months | integer | Returns the number of complete months between two dates (a - b). |
bmel:end-of-day | datetime | Returns the datetime at 23:59:59.999 on the same day. |
bmel:end-of-month | datetime | Returns the datetime at 23:59:59.999 on the last day of the month. |
bmel:format-date | string | Formats a date or datetime value into a string using the specified pattern. |
bmel:from-epoch | datetime | Converts Unix epoch milliseconds to a datetime value. |
bmel:hour | integer | Extracts the hour (0-23) from a datetime value. |
bmel:is-after | boolean | Returns true if date/datetime a is strictly after b. |
bmel:is-before | boolean | Returns true if date/datetime a is strictly before b. |
bmel:minute | integer | Extracts the minute (0-59) from a datetime value. |
bmel:month | integer | Extracts the month number (1-12) from a date or datetime value. |
bmel:now | datetime | Returns the current date and time with timezone information. |
bmel:parse-date | date | Parses a string into a date value using the specified format pattern. |
bmel:second | integer | Extracts the second (0-59) from a datetime value. |
bmel:start-of-day | datetime | Returns the datetime at 00:00:00.000 on the same day. |
bmel:start-of-month | datetime | Returns the datetime at 00:00:00.000 on the first day of the month. |
bmel:time-diff | integer | Returns the number of milliseconds between two datetimes (end - start). |
bmel:time-of | time | Extracts the time part from a datetime value, discarding the date component. |
bmel:to-epoch | number | Converts a date or datetime to Unix epoch milliseconds. |
bmel:today | date | Returns the current date at midnight (no time component). |
bmel:week-of-year | integer | Returns the ISO week number (1-53) from a date or datetime value. |
bmel:year | integer | Extracts the year from a date or datetime value. |
Type Conversion¶
Explicit conversion between types.
| Function | Returns | Description |
|---|---|---|
bmel:to-boolean | boolean | Converts the expression to a boolean value. |
bmel:to-number | number | Converts the expression to a numeric value. |
bmel:to-string | string | Converts the expression to its string representation. |
bmel:to-timestamp | datetime | Converts the expression to a datetime value. |