Governance & Security
Govern AI in production with middleware, guardrails, prompt-injection defense, human approval, and audit trails.
Enterprises adopt AI when they can control it. BoxLang AI puts governance in a middleware layer that wraps model and tool calls, so you add controls without changing agent logic.
🧅 Middleware
Middleware can observe, modify, retry, reject, suspend, or cancel work around every model and tool call.
Attach it to an agent:
agent = aiAgent(
name: "assistant",
middleware: [
new LoggingMiddleware(),
new RetryMiddleware( maxRetries: 3 ),
new GuardrailMiddleware( blockedTools: [ "deleteRecord" ] )
]
)🛡️ Built-In Controls
Observability
LoggingMiddleware, FlightRecorderMiddleware for an audit trail
Reliability
RetryMiddleware, MaxToolCallsMiddleware
Policy
GuardrailMiddleware blocks tools or argument patterns
Approval
HumanInTheLoopMiddleware
Prompt injection
InputSanitizerMiddleware scans inbound content and tool results
Output safety
OutputGuardMiddleware redacts sensitive output offline
AI-assisted review
LLMGuardMiddleware classifies content with an LLM as judge
Security middleware is opt-in and can be tested offline.
🚫 Guardrails
Block tools outright and validate arguments with patterns:
🧑⚖️ Human in the Loop
Some actions should never run unsupervised: deleting records, moving money, deploying to production. HumanInTheLoopMiddleware pauses the run and asks a person to approve, reject, or edit the call.
Later, when a person decides:
In CLI mode the prompt appears in the terminal. In web mode the run suspends and resumes when the decision arrives, even days later.
🌐 Gateways
A gateway presents approvals and messages on the right channel: the CLI, signed HTTP webhooks, or a platform module you register. HTTP gateways sign requests with HMAC, bound them by timestamp, deduplicate nonces, and claim decisions atomically.
See Providers & Gateways.
🔐 More Security Practices
Isolate every user's memory with
userIdandconversationId.Fence untrusted content with
aiFence.Give agents least privilege, and expose only the tools they need.
🔍 Go Deeper
Last updated
Was this helpful?
