89 curated builds·evidence labeled
COMMUNITY OBSERVED

Mastra Agent Guardrail Middleware

A single-file drop-in middleware for Mastra agent workflows that screens prompts and tool parameters in ~400ms.

Overview & Result

A lightweight guardrail for autonomous agent runtimes. By positioning Jev ahead of the main agent reasoning loop, it filters out prompt injections, jailbreaks, and out-of-scope tasks in ~400ms before expensive generative models are invoked.

How Jev fits in the loop

  1. Intercept incoming user requests at the agent runtime boundary.
  2. Call Jev Choice with predefined safety categories (Safe, Jailbreak, Off-topic, Policy-violation).
  3. Instantly reject or divert flagged requests to a safe fallback message.
  4. Pass approved requests forward to the Mastra agent execution loop.

How to reproduce

  1. Install mastra and clone the codealive-ai/mastra-jev-moderation repository.
  2. Configure the moderation middleware in your Mastra agent definition pipeline.
  3. Pass test prompts containing adversarial injections and safe user queries to observe instant classification and routing.

Why this build matters

Proves that safety guardrails can be low-latency, deterministic, and cost-effective rather than relying on slow, verbose LLM self-moderation.

Reported performance

Reported by author

Latency: ~0.4 s median latency

Published benchmark in repository tests across standard moderation test suites.

Limitations

  • Focuses on text-based prompt injection and behavioral boundaries; cannot detect malicious compiled binaries.
  • Edge cases with multi-turn prompt fragmentation need session-level tracking.
  • High-stakes financial or administrative operations still require hard deterministic RBAC rules.

Patterns