register_filter
Validate and register a restricted Python filter for local file processing. Submit a function filter_item(data) to transform JSON, YAML, or TXT files into a text result.
Instructions
Validate and register a restricted Python filter for later execution on a local file.
Use this tool first when you want to run custom filtering or transformation logic against a local document. The submitted source code must define exactly one top-level function with this exact signature:
def filter_item(data):The server loads the target file before execution and passes the loaded document into filter_item(data).
Input document types:
JSON files -> parsed JSON value such as dict, list, string, number, boolean, or null
YAML files -> parsed YAML value such as dict, list, string, number, boolean, or null
TXT files -> list of text lines
The function must return a text result (str). The returned text may contain any format you want, such as plain text, YAML, CSV-like text, or a custom report.
Preloaded standard-library modules (don't try to import them in your functions):
json, yaml, re
math, statistics, datetime, decimal
collections, itertools, functools, operator
textwrap, html, base64, hashlib, ipaddress, unicodedata, difflib
Safety rules:
The code is validated against a restricted Python subset
Imports, network access, dynamic execution, and unsafe attribute access are rejected
Registered filters are stored in memory only and expire automatically after a server-side TTL
Forbidden:
Using non-standard libraries or modules
Accessing the filesystem, network, or environment variables
Defining multiple top-level functions, classes, or module-level code
Using dynamic features like eval, exec, or import
Args: code: Python source code that defines exactly one function named filter_item(data).
Returns: A structured object containing the new filter identifier, expiration timestamp, TTL in seconds, and validation policy version.
Raises: ValueError: If the code is invalid, unsafe, or does not match the required function signature.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Python source code that defines exactly one top-level function named filter_item(data). The function receives the loaded document and must return a text result. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filter_id | Yes | Unique filter identifier to pass into run_filter. | |
| expires_at | Yes | UTC timestamp in ISO 8601 format when the filter expires. | |
| ttl_seconds | Yes | Server-side lifetime of the registered filter in seconds. | |
| policy_version | Yes | Validation policy version used for the submitted filter code. |