AgentMark provides a set of built-in filters that you can use to manipulate and transform data within your prompts. Filters are functions that take an input value and return a transformed output.

Basic Usage

Use filters by calling them on values in your prompts:

---
name: greeting
metadata:
  model:
    name: gpt-4
test_settings:
  props:
    userName: "alice"
    items: ["apple", "banana", "cherry"]
---

<System>
Your name is {capitalize(props.userName)}!
Your items are: {join(props.items, ", ")}
</System>
<User>
What is your name, and what items do you have?
</User>

Built-in Filters

AgentMark includes several built-in filters:

Text Manipulation

  • capitalize(str): Capitalizes first character of string
  • lower(str): Converts string to lowercase
  • upper(str): Converts string to uppercase
  • truncate(str, length): Truncates string to specified length
  • replace(str, search, replace): Replaces text in string

Array Operations

  • join(array, separator): Joins array elements with separator

Number Formatting

  • abs(num): Returns absolute value
  • round(num, decimals): Rounds number to decimal places

Data Transformation

  • dump(obj): Converts object to JSON string
  • urlencode(str): URL encodes a string

Creating Custom Filters

You can create and register custom filters:

import { FilterRegistry } from "@puzzlet/agentmark";

// Create filter function
const reverse = (input: string): string => {
  return input.split('').reverse().join('');
};

// Register the filter
FilterRegistry.register("reverse", reverse);

Then use in your prompts:

---
name: reverse-text
metadata:
  model:
    name: gpt-4
test_settings:
  props:
    text: "Hello World"
---

<System>
Original: {props.text}
Reversed: {reverse(props.text)}
</System>

Best Practices

  1. Use descriptive filter names
  2. Handle invalid input types gracefully
  3. Keep filters focused on single transformations

Have Questions?

We’re here to help! Choose the best way to reach us: