Invariant Guardrails
Open-source rule-based guardrail layer that secures LLM and MCP-powered AI agent systems.
At a Glance
About Invariant Guardrails
Invariant Guardrails is an open-source project from Invariant Labs that adds a rule-based guardrailing layer to LLM or MCP-powered applications. It sits between the application and its MCP servers or LLM provider, so agent behavior can be monitored and steered without invasive code changes. The homepage notes that Snyk has acquired Invariant Labs.
What It Is
Guardrails is a contextual security layer for AI agents. Developers write simple Python-inspired matching rules that identify and block malicious or unwanted agent behavior. Rules can match individual messages, such as banned phrases, or flows between tool calls, such as reading an inbox and then sending an email to an unknown address.
How Rules Work
A rule starts with a raise statement and a set of conditions. Conditions bind messages, tool calls, or tool outputs and are then evaluated like regular Python. A standard library of operations and detectors, including prompt injection detection, supports the checks. Rules that match raise errors, which block the offending LLM or MCP request.
Deployment Options
There are two ways to use it:
- Through Invariant Gateway, which acts as an MCP or LLM proxy and evaluates the rules on each request, both before and after the call.
- Programmatically with the
invariant-aiPython package, which loads a policy and analyzes an agent trace locally on your machine.
Place in the Invariant Family
Invariant Labs lists Guardrails alongside Explorer, which inspects and observes agent behavior, and MCP Scan, a security scanning tool for MCP servers. The code is released under the Apache License 2.0.
Community Discussions
Be the first to start a conversation about Invariant Guardrails
Share your experience with Invariant Guardrails, ask questions, or help others learn from your insights.
Pricing
Open Source
Invariant Guardrails core is open source under the Apache License 2.0 and can be self-hosted or run locally.
- Apache License 2.0
- Rule-based guardrails for LLM and MCP-powered agents
- Run locally via the invariant-ai Python package
- Integrates via Gateway as an MCP or LLM proxy
Capabilities
Key Features
- Rule-based guardrails for LLM and MCP applications
- Python-inspired rule language
- Detects tool-call flows across agent traces
- Transparent MCP and LLM proxy via Gateway
- Local programmatic policy analysis
- Built-in detectors such as prompt injection
- Standard library of checking operations
