Skip to content

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.

Gate policies are JavaScript files in the policies/ directory. They are executed by goja, a Go-native JavaScript engine.

Runs before the tool executes. Can reject the call or modify parameters.

policies/block-dangerous-params.js
function evaluate(context) {
if (context.params.force_delete === true) {
return { allow: false, reason: "force_delete is blocked by policy" };
}
return { allow: true };
}

Runs after the tool executes. Can redact sensitive data from the response.

policies/redact-pii.js
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) };
}

The gate receives the CallerClass, enabling tiered content filtering:

CallerClassFiltering
trustedCredentials only
standardHigh-risk PII + credentials
untrustedAll PII patterns
Terminal window
GATE_EVALUATORS=goja # Enable goja evaluator (default)

Place policy files in the policies/ directory. ToolMesh loads them at startup.

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.