# Invariant Guardrails

> Open-source rule-based guardrail layer that secures LLM and MCP-powered AI agent systems.

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-ai` Python 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.

## 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

## Integrations
MCP, Invariant Gateway, LLM providers

## Platforms
DEVELOPER_SDK, API

## Pricing
Open Source

## Links
- Website: https://invariantlabs.ai
- Documentation: https://invariantlabs-ai.github.io/docs/mcp-scan/guardrails-reference/
- Repository: https://github.com/invariantlabs-ai/invariant
- EveryDev.ai: https://www.everydev.ai/tools/invariant-guardrails
