JSON TransformArray
filter
Keep array elements that match a comparison expression
filter
Keeps only the elements of an array that satisfy a compact comparison expression. See Expressions for the full syntax.
Options
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
expression | string | Yes | — | Comparison of the form FIELD (==|!=) `value` (operators wrapped in backticks). |
Example
Input
[
{ "role": "system", "content": "Old prompt" },
{ "role": "user", "content": "Hi" },
{ "role": "assistant", "content": "Hello" }
]Operation
{ "type": "filter", "options": { "expression": "role != `system`" } }Output
[
{ "role": "user", "content": "Hi" },
{ "role": "assistant", "content": "Hello" }
]In a Circuit Step
{
"name": "drop_system_messages",
"description": "Remove any system messages from the conversation",
"function": "circuit.core.transform.json",
"input": {
"source": "${{ messages }}",
"operations": [
{ "type": "filter", "options": { "expression": "role != `system`" } }
]
},
"outputs": [
{
"name": "non_system_messages",
"description": "Conversation with all system messages removed",
"value": "${{ drop_system_messages.output.transformed_result }}"
}
]
}Notes & gotchas
- Errors with
filter: expected arrayif the input is not an array. - Each array element must be an object; the expression looks up
<field>on it. A missing field surfaces asfilter: field '<field>' not found in item. - Only
==and!=operators are supported. The right-hand value must be wrapped in backticks. - Numeric, boolean, and
nullvalues are compared via their string form ("5","true","null"), socount == \5`` works without explicit type casting. filterdoes not support boolean combinators (&&,||) or nested paths. Chain multiplefilteroperations or usereplaceMatchingfor richer JMESPath conditions.