ModelWorks logoModelWorks
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

OptionTypeRequiredDefaultDescription
expressionstringYes—Comparison of the form FIELD (==|!=) `value` (operators wrapped in backticks).

Example

Input

JSON
[
  { "role": "system",    "content": "Old prompt" },
  { "role": "user",      "content": "Hi" },
  { "role": "assistant", "content": "Hello" }
]

Operation

JSON
{ "type": "filter", "options": { "expression": "role != `system`" } }

Output

JSON
[
  { "role": "user",      "content": "Hi" },
  { "role": "assistant", "content": "Hello" }
]

In a Circuit Step

JSON
{
  "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 array if the input is not an array.
  • Each array element must be an object; the expression looks up <field> on it. A missing field surfaces as filter: field '<field>' not found in item.
  • Only == and != operators are supported. The right-hand value must be wrapped in backticks.
  • Numeric, boolean, and null values are compared via their string form ("5", "true", "null"), so count == \5`` works without explicit type casting.
  • filter does not support boolean combinators (&&, ||) or nested paths. Chain multiple filter operations or use replaceMatching for richer JMESPath conditions.
On this page

On this page