Output Gate
The Output Gate is ToolMesh’s content control layer. JavaScript policies run before (pre) and after (post) every tool execution, enabling input validation, output filtering, and PII redaction.
How It Works
Section titled “How It Works”Gate policies are JavaScript files in the policies/ directory. They are executed by goja, a Go-native JavaScript engine.
Pre-Gate (Input Validation)
Section titled “Pre-Gate (Input Validation)”Runs before the tool executes. Can reject the call or modify parameters.
function evaluate(context) { if (context.params.force_delete === true) { return { allow: false, reason: "force_delete is blocked by policy" }; } return { allow: true };}Post-Gate (Output Filtering)
Section titled “Post-Gate (Output Filtering)”Runs after the tool executes. Can redact sensitive data from the response.
function evaluate(context) { let output = JSON.stringify(context.result); // Redact email addresses output = output.replace(/[\w.-]+@[\w.-]+\.\w+/g, "[REDACTED]"); return { allow: true, result: JSON.parse(output) };}CallerClass-Based Filtering
Section titled “CallerClass-Based Filtering”The gate receives the CallerClass, enabling tiered content filtering:
| CallerClass | Filtering |
|---|---|
trusted | Credentials only |
standard | High-risk PII + credentials |
untrusted | All PII patterns |
Configuration
Section titled “Configuration”GATE_EVALUATORS=goja # Enable goja evaluator (default)Place policy files in the policies/ directory. ToolMesh loads them at startup.
Enterprise: Compliance-LLM
Section titled “Enterprise: Compliance-LLM”The enterprise extension adds an LLM-based gate evaluator that classifies content against compliance rules. This enables policies like “block responses containing financial advice” without writing regex patterns.