> ## Documentation Index
> Fetch the complete documentation index at: https://developers.drpn.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Query functions

> What a Darpan query's script can call: the fn: functions, the JEXL built-ins, the result it returns, and the limits on every run.

A query's script reads `input` and returns one value. It can call the `fn:` functions on this page and JEXL's own built-ins, and nothing else: no method calls on values, no clock, no randomness, no network, so the same input always gives the same result. The script language comes from the [moqui-jexl](https://github.com/drpn-ai/moqui-jexl) component, which Darpan runs from 3.4.0. Before 3.4.0 the prefix was `d:`.

## What the script gets

* `input.<name>`: the rows each input of the read returned, a list of maps. Dates arrive as ISO-8601 text, for example `2026-11-20T10:00:00Z`.
* `input.run`: `date` and `timeZone` of the run.

What a read may name is in [Queries](https://docs.drpn.ai/reference/queries#what-a-query-may-read) in the product docs.

## The fn: functions

| Function | Returns |
| - | - |
| `fn:dec(x)` | x as a decimal number (text or number); null stays null |
| `fn:round(x, places)` | x rounded half-up to places decimals; fn:round(x, 2) for money |
| `fn:str(x)` | x as text |
| `fn:lower(s) / upper(s) / trim(s)` | text case and surrounding spaces |
| `fn:has(s, part)` | true when text s contains part |
| `fn:replace(s, from, to)` | every from in s replaced with to (plain text, no patterns) |
| `fn:split(s, sep)` | text s split on sep into a list |
| `fn:join(list, sep)` | the list as one text, sep between items |
| `fn:keys(map) / vals(map)` | a map's keys / values as a list |
| `fn:push(list, item)` | adds item to the end of a list made with \[...], in place (cheap); returns the list |
| `fn:pluck(list, field)` | field from each map in the list |
| `fn:where(list, field, value)` | the maps in the list whose field equals value; size(...) counts them |
| `fn:sum(list) / sum(list, field)` | the total of the numbers, or of field across maps |
| `fn:groupCount(list, field)` | a map of each value of field to how many maps have it |
| `fn:sorted(list) / distinct(list)` | the list sorted / with repeats removed |
| `fn:sortBy(list, 'field')` | the maps ordered by field: '-field' descending, '^field' ignoring case, 'a,b' by several |
| `fn:day(x)` | a date or timestamp as yyyy-MM-dd (UTC) |
| `fn:daysBetween(a, b) / hoursBetween(a, b)` | whole days / hours from a to b (dates, timestamps or epoch ms) |
| `fn:log(x)` | adds x to the run log and returns it |

## Built into JEXL

These need no `fn:` prefix, so there is no `fn:len`, `fn:min` or `fn:count`.

| Expression | Returns |
| - | - |
| `size(x)` | How many items a list or map holds, or characters in text. |
| `empty(x)` | True when `x` is null, empty text, or an empty list or map. |
| `a =^ b` / `a =$ b` | True when text `a` begins / ends with `b`. |
| `x =~ list` | True when `x` is in `list`. |
| `a ? b : c` | `b` when `a` is true, else `c`. |
| `a ?? b` | `a`, or `b` when `a` is null. |
| `for (var row : list) { ... }` | Runs the block for each item. |

Map keys are quoted: `{'summary': 'x'}`. A bare word is a variable. A list you add to starts as `[...]` and grows with `fn:push`; `[]` is a fixed, empty array.

## What the script returns

Nothing (nothing is sent), a text or number (the summary), or:

```jexl theme={null}
{ 'summary': '3 orders are late',
  'files': [ { 'name': 'late.csv', 'columns': ['order', 'days'], 'rows': [['SO-1', 3]] } ] }
```

At most 5 files, sent as CSV (UTF-8 with a byte order mark; a text cell that could start a spreadsheet formula gets a leading `'`). The summary is up to 4,000 characters. A map with other keys, or a list, is `data`: it comes back to the caller and is never sent.

## Limits

Every query runs with the `QUERY` profile. A run stops with an error when it passes a limit; the error names the limit and, where there is one, the line.

| Limit | Value |
| - | - |
| Rows per input (groups, for a grouped read) | 20,000 |
| Values read in all | 2,000,000 |
| Time to read | 60 seconds |
| Time to run the script | 10 seconds |
| Work per run | 5,000,000 units |
| Script length | 64,000 characters |
| Text | 65,536 characters |
| Lists and maps | 20,000 items |
| The whole result, files included | 8,000,000 characters as JSON, and 400,000 values (about 20,000 rows of 20 columns) |
| Nesting | 32 levels |

## Example

If `input.findings` is an audit's findings read with `recordKey`, `headline` and `firstFoundDate`, this returns their count and a file:

```jexl theme={null}
var rows = [...];
for (var f : input.findings) { fn:push(rows, [f.recordKey, f.headline, f.firstFoundDate]); }
{ 'summary': fn:str(size(rows)) + ' open findings',
  'files': [{ 'name': 'findings.csv', 'columns': ['record', 'headline', 'first found'], 'rows': rows }] }
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.