BMEL — BizMetry Expression Language¶
BMEL (BizMetry Expression Language) is a typed expression language used inside the Business Event mapper to define computed or multi-source field mappings. It allows you to write expressions that combine, transform, or conditionally select values from one or more API payload fields and assign the result to a target Frame component.
BMEL expressions are authored in the Monaco-based BMEL Editor, which provides syntax highlighting, inline validation, type inference, and source field auto-completion.
Functions and operators
Every function lives in the bmel: namespace and takes its arguments by position, in the order shown in its signature: bmel:round(value, 2), not bmel:round(value, decimals: 2). Arithmetic, comparison and logic can also be written with operators, such as +, == and &&.
When to Use BMEL¶
Use BMEL when a simple 1-to-1 field mapping is not sufficient.
bmel:concat({getCustomer:Response Payload}.$.firstName, ' ', {getCustomer:Response Payload}.$.lastName)
bmel:round({getOrder:Response Payload}.$.totalCents / 100, 2)
bmel:if({placeOrder:Response Payload}.$.status == 'SUCCESS', 1, 0)
bmel:json-path({getOrder:Response Payload}.$.payload, '$.items[0].price')
bmel:to-string({placeOrder:Request Payload}.$.orderId)
bmel:coalesce({getOrder:Response Payload}.$.region, 'UNKNOWN')
Source Field Syntax¶
All source field references in BMEL use the canonical format:
{operationName:Section}.$.fieldPath
The section says which part of the call the value comes from:
| Section | Reads | Example |
|---|---|---|
Request Payload | A field of the request body | {placeOrder:Request Payload}.$.customer.address.city |
Response Payload | A field of the response body | {getOrder:Response Payload}.$.total_amount |
HTTP Headers | A request header, by name | {createAccount:HTTP Headers}.$.X-Tenant-Id |
URI Parameters | A path parameter, by name | {getProduct:URI Parameters}.$.productId |
Query Parameters | A query string parameter, by name | {searchOrders:Query Parameters}.$.status |
Request Context | A platform variable of the request | {getOrder:Request Context}.$.bm.request.client_ip |
Response Context | A platform variable of the response | {getOrder:Response Context}.$.bm.response.timestamp |
{placeOrder:Request Payload}.$.customer.address.city
{getOrder:Response Payload}.$.total_amount
{createAccount:HTTP Headers}.$.X-Tenant-Id
{getProduct:URI Parameters}.$.productId
{getOrder:Request Context}.$.bm.request.client_ip
When the operation has cardinality MANY (it can run several times in the same transaction), the section ends with [] and the reference returns one value per invocation, ready for an aggregation function:
bmel:sum({createChatCompletion:Response Payload[]}.$.usage.total_tokens)
The BMEL editor shows only the fields you connected in the mapper — not the full schema. Unconnected fields are not available as expression inputs.
Operators¶
Operators combine values without a function call. From lowest to highest precedence:
| Operators | Meaning |
|---|---|
cond ? a : b | Conditional: a when cond is true, otherwise b |
value default fallback | fallback when value is null or empty |
|| | Logical OR |
&& | Logical AND |
==, != | Equal, not equal |
<, <=, >, >= | Comparisons |
+, - | Addition, subtraction |
*, / | Multiplication, division |
!, - (prefix) | Logical NOT, negation |
Parentheses group sub-expressions. Literals are numbers (42, 3.14), strings in single or double quotes ('USD', "USD"), true, false and null.
{getOrder:Response Payload}.$.amount * 1.21
{getOrder:Response Payload}.$.status == 'PAID' && {getOrder:Response Payload}.$.amount > 100
{getOrder:Response Payload}.$.amount > 1000 ? 'LARGE' : 'STANDARD'
{getOrder:Response Payload}.$.region default 'GLOBAL'
({getOrder:Response Payload}.$.min_price + {getOrder:Response Payload}.$.max_price) / 2
Resource and field references operators¶
BMEL has two reference operators, both written #{Name}. They don't produce a value: they name a resource type or an attribute (a field of a resource), and they can be used only as arguments of functions that declare a parameter of that kind — today bmel:get-resource-by-id and bmel:get-json-field.
| Operator | Parameter type | Names | Used in |
|---|---|---|---|
| Resource type reference | bmel:resource-type | A resource type of the template the target Frame Type belongs to | bmel:get-resource-by-id(#{aimodel}, …) |
| Attribute reference | bmel:json-field | A field of a JSON object; for a resource, one of its resource type's attributes | bmel:get-json-field(…, #{input_cost_per_token}) |
The same #{…} notation serves both: what it names depends on the parameter it is written in. Together they read an attribute of a business object identified by a source value — here, the input price of the model sent in the request:
bmel:get-json-field(
bmel:get-resource-by-id(#{aimodel}, {invokeAgent:Request Payload}.$.model),
#{input_cost_per_token})
Because the attribute keeps its type, it can be used directly in arithmetic:
{invokeAgent:Response Payload}.$.usage.prompt_tokens *
bmel:get-json-field(bmel:get-resource-by-id(#{aimodel}, {invokeAgent:Request Payload}.$.model),
#{input_cost_per_token})
+ {invokeAgent:Response Payload}.$.usage.completion_tokens *
bmel:get-json-field(bmel:get-resource-by-id(#{aimodel}, {invokeAgent:Request Payload}.$.model),
#{output_cost_per_token})
Resource type reference¶
Typing #{ in a resource type parameter opens an inline list with the resource types of the template; keep typing to filter it, and pick one to insert #{name}.
Attribute reference¶
Typing #{ in an attribute parameter lists the attributes of the resource type passed to bmel:get-resource-by-id (each one shows the resource type it belongs to). The result of bmel:get-json-field takes the attribute's type, so a numeric attribute can be used directly in arithmetic.
Validation¶
The editor reports:
- a resource type that is not in the template, or an attribute that does not belong to the referenced resource type (with a hint when only the letter case differs);
- a
#{…}reference used where a value is expected — on its own, as an operand, or in a parameter that doesn't take references; - a plain value (e.g. a string) passed to a parameter that requires a
#{…}reference; - an unclosed
#{or an empty#{}.
Iterating over arrays¶
bmel:map, bmel:filter, bmel:count-if, bmel:sum-if and bmel:for-range evaluate an expression once per element. Inside it, bmel:item is the current element and bmel:i its zero-based position; bmel:item.field reads a field of the element.
bmel:map({getOrder:Response Payload}.$.items, bmel:item.price * bmel:item.quantity)
bmel:filter({getOrder:Response Payload}.$.items, bmel:item.category == 'electronics')
bmel:sum(bmel:map({getOrder:Response Payload}.$.items, bmel:item.price * bmel:item.quantity))
Type System¶
BMEL is statically typed with type inference. The editor validates types at authoring time and reports errors inline.
| BMEL Type | Description | Example values |
|---|---|---|
bmel:string | Text values | "hello", 'USD' |
bmel:integer | Whole numbers | 42, -7 |
bmel:number | Decimal or whole numbers | 3.14, 99.99 |
bmel:boolean | True/false | true, false |
bmel:array<T> | Ordered list of items of type T | bmel:array<number> |
bmel:date | Calendar date, no time component | 2026-07-16 |
bmel:datetime | Date and time with timezone | 2026-07-16T14:30:00Z |
bmel:time | Time of day, no date component | 14:30:00 |
bmel:enum | A value from a predefined, ordered set of constants declared on a Frame component's attribute (e.g. an order status enum), written #enum.VALUE | #enum.SHIPPED |
bmel:expression | A sub-expression evaluated lazily or repeatedly rather than once up front — used for arguments like a switch branch's result or a for-range loop body | any expression |
bmel:json | A JSON object, e.g. a resource instance returned by bmel:get-resource-by-id | {"model_name": "gpt-4o", …} |
bmel:resource-type | A resource type of the template, written #{ResourceType} — only as a function argument (see reference operators) | #{aimodel} |
bmel:json-field | The name of a field of a JSON object, written #{FIELD_NAME} — only as a function argument (see reference operators) | #{input_cost_per_token} |
bmel:any | Untyped value (used for JSON payloads and generic arguments) | any value |
Type mismatches produce warnings (not hard errors) in most cases — BizMetry attempts best-effort coercion at runtime, but explicit conversion functions (bmel:to-string, bmel:to-number, bmel:to-boolean, bmel:to-timestamp) are recommended.
bmel:to-string({invokeAgent:Request Payload}.$.seed)
Function Reference¶
BMEL ships with 117 functions across 8 categories — LLM, string, math, array & statistics, logic & control flow, JSON, date & time, and type conversion. The full list, with signatures and examples, lives in the Function Reference.
Function names are kebab-case — lowercase words joined by hyphens: bmel:to-number, bmel:time-diff, bmel:prompt-toxicity-score. Earlier versions used camelCase (bmel:toNumber); the editor still accepts a former name, marks it with a warning and names the current one.
A representative sample:
| Function | Signature | Description |
|---|---|---|
bmel:concat | bmel:concat(values: bmel:any...) → bmel:string | Concatenates two or more values into a string. |
bmel:upper / bmel:lower | bmel:upper(expr: bmel:string) → bmel:string | Converts a string to uppercase or lowercase. |
bmel:if | bmel:if(cond: bmel:boolean, a: bmel:any, b: bmel:any) → bmel:any | Returns a if cond is true, otherwise b. |
bmel:coalesce | bmel:coalesce(values: bmel:any...) → bmel:any | Returns the first non-null value. |
bmel:switch | bmel:switch(subject, case, result, [otherwise]) → bmel:any | Evaluates subject against one or more case/result pairs and returns the first match. |
bmel:round | bmel:round(expr: bmel:number, decimals: bmel:integer) → bmel:number | Rounds to the specified number of decimal places. |
bmel:sum / bmel:avg | bmel:sum(array: bmel:array<number>) → bmel:number | Aggregates values across a mapped array column. |
bmel:to-string / bmel:to-number / bmel:to-boolean | bmel:to-string(expr: bmel:any) → bmel:string | Explicit type conversion. |
bmel:json-path | bmel:json-path(json: bmel:any, path: bmel:string) → bmel:any | Extracts a value from a JSON payload by path. |
The names in a signature document each position; you don't write them in the call.
BMEL Editor¶
The BMEL Editor opens as a dialog when you click the ƒ icon on a connector line in the mapping canvas.
Editor panels¶
- Left — Expression editor: Monaco-based editor with BMEL syntax highlighting, bracket matching, and error markers.
- Right — Available source fields: Lists only the fields connected in the mapper for this target component, shown with their canonical
{op:Section}.$.pathreferences. Click any field to insert it at the cursor position.
Inline validation¶
The editor validates your expression as you type:
- Red underline — syntax error or unknown function.
- Yellow underline — type mismatch warning.
- Green checkmark — expression is valid and ready to save.
Saving a malformed expression is blocked until all errors are resolved.
Expression Examples¶
{getOrder:Response Payload}.$.order_id
bmel:concat({getOrder:Response Payload}.$.firstName, ' ', {getOrder:Response Payload}.$.lastName)
bmel:if({placeOrder:Response Payload}.$.status == 'SUCCESS', 1, 0)
bmel:coalesce({getOrder:Response Payload}.$.region, 'GLOBAL')
bmel:sum({getOrder:Response Payload}.$.lineItems.amount)
bmel:to-number({getOrder:Response Payload}.$.totalCents)
bmel:json-path({getOrder:Response Payload}.$.payload, '$.payment.card.last4')
bmel:switch({getOrder:Response Payload}.$.channel, 'W', 'Web', 'M', 'Mobile', 'Other')
bmel:time-diff({getOrder:Response Context}.$.bm.response.timestamp, {getOrder:Request Context}.$.bm.request.timestamp)

