Anchorage API reference
    Preparing search index...
    • Delegate gating to a pluggable, possibly-async classifier (e.g. a moderation model or an external safety API). Streaming calls classify only once accumulated text since the last call has grown by evaluateEveryChars (a classifiedUpTo:${channel} cursor in streamState, per-channel); the object channel classifies every snapshot, since it is a replaced snapshot rather than append-only text. Input and result phases have no streamState and therefore always classify. With hold-back, the engine classifies text left below the cadence at a channel end or stream finish before releasing it. On Mastra's durable loop, output policies stop the stream a subscriber receives, including terminal classification under hold-back. Mastra logs a result-phase refusal; the saved thread message and returned result come from model output and are not filtered by output policies.

      A classify call that throws, resolves to no decision, or does not settle within timeoutMs is an evaluator failure. PolicyEngine records an error event for it and aborts at input and in-stream, on both of Mastra's agent loops, and throws the fixed policy evaluation failed error at the final result, which stops Mastra's standard loop. Fail-open is not offered. Omit timeoutMs to let classify run unbounded.

      The returned evaluator carries no holdBackChars hint (engine default: 0) — an async classifier has no bounded straddle window to report, unlike a fixed pattern length. A caller wanting this policy to participate in zero-leak hold-back must accept buffering the ENTIRE channel until stream end, and opt in explicitly: { ...classifierPolicy(options), holdBackChars: Infinity }.

      Parameters

      Returns PolicyEvaluator