Logic Steps
The logic section is an ordered list of steps that execute sequentially. Each step is one of three types: SQL, Lark, or Expr.
logic:
- sql: ... # query your database
- lark: ... # transform with Starlark
- expr: ... # lightweight expression
Every step has an omit field that controls whether its result appears in the response:
omit | Result |
|---|---|
false (default) | Included in response |
true | Available to later steps but not returned |
SQL Step
Runs a SQL query against the configured database.
- sql: |
SELECT * FROM users ORDER BY id DESC
omit: true
Parameter Binding
Use ?:field_name to bind values from a previous step or from the request input:
- sql: |
INSERT INTO users VALUES(?:id, '?:name', '?:email', now('UTC'))
omit: true
String fields require quotes around the placeholder. Numeric fields do not:
# Numeric — no quotes
?:id
# String — single quotes required
'?:name'
'?:email'
Values are resolved from the most recent step result that contains that field name.
Lark Step (Starlark)
Runs Starlark code — a deterministic, sandboxed subset of Python. Use Lark for loops, custom functions, and complex transformations.
- lark: enhance_data
omit: true
code: |
load("math", "upby10")
load("strings", "slugify")
def mask_email(email):
parts = email.split("@")
return parts + "***@" + parts[1]
result = []
for row in step_0:
result.append({
"id": upby10(row["id"]),
"name": slugify(row["name"]),
"email": mask_email(row["email"]),
})
The final value assigned to result becomes the step's output.
Built-in Modules
load("math", "upby10") # Math utilities
load("strings", "slugify") # String utilities
Accessing Previous Steps
step_0 # result of first step
step_1 # result of second step
Accessing Request Input
input.field_name # field from request body or query params
Expr Step
A lightweight expression evaluator for simple transformations. Use Expr when you don't need loops or custom functions.
- expr: build_response
code: |
{
"version": input.version,
"total_users": len(step_0),
"has_data": len(step_0) > 0
}
The expression must be a single value — an object, array, or scalar. The result becomes the step output.
Available Variables
| Variable | Description |
|---|---|
input | Request body or query parameters |
step_N | Result of step N |
Built-in Functions
| Function | Description |
|---|---|
len() | Length of array or string |
Expr vs Lark
| Use Case | Use |
|---|---|
| Build a response object | expr |
| Count rows, check length | expr |
| Loop over rows | lark |
| Define custom functions | lark |
| Complex multi-step transforms | lark |