Skip to content

Commit d5b9581

Browse files
docs: guardrails in explorer
1 parent 209b51d commit d5b9581

13 files changed

+1574
-4
lines changed

docs/guardrails/explorer-and-gateway.svg

Lines changed: 345 additions & 0 deletions
Loading

docs/guardrails/explorer-landing.png

951 KB
Loading

docs/guardrails/explorer.md

Lines changed: 121 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,124 @@ title: Overview
55
# Guardrails in Explorer
66

77
<div class="subtitle">
8-
Learn how to use Guardrails in Explorer.
9-
</div>
8+
Learn how to configure and manage your guardrailing rules in Explorer.
9+
</div>
10+
11+
[Explorer](../explorer/index.md) is Invariant's configuration and observability tool. It allows you to configure guardrails, inspect and debug your agent traces and analyze your agentic system for novel failure modes.
12+
13+
It exposes a simple configuration interface, that allows you to configure, test and deploy guardrails to your agentic system, as well as inspect guardrail failures in detail.
14+
15+
<img src="site:/guardrails/guardrails-configuration-explorer.png" alt="Explorer Landing" class="invariant-architecture" style="display: block; margin: 0 auto; width: 100%; max-width: 650pt;"/>
16+
17+
## How Gateway and Explorer Work Together
18+
19+
By default, each Explorer project exposes its own [Gateway](../gateway/index.md) instance, allowing you to easily get started quickly with your first Invariant-augmented agent.
20+
21+
You can think of an Explorer project as a _customized version of your LLM and MCP servers_ that automatically adhere to the set of guardrailing rules you configure in Explorer.
22+
23+
Apart from this, Explorer will also log all your requests, allowing you to inspect your agent behavior in detail and configure the guardrails to your liking.
24+
25+
<br/><br/>
26+
<img src="site:/guardrails/explorer-and-gateway.svg" alt="Invariant Architecture" class="invariant-architecture" style="display: block; margin: 0 auto; width: 100%; max-width: 450pt;"/>
27+
28+
## Getting Started
29+
30+
You can get started with Explorer and Guardrails, simply by adjusting your project's LLM base URL.
31+
32+
33+
**Example:** Setting Up Your OpenAI client to use Explorer and Guardrails
34+
```python hl_lines='11'
35+
import os
36+
from openai import OpenAI
37+
38+
# 1. Explorer+Gateway Integration
39+
40+
client = OpenAI(
41+
default_headers={
42+
"Invariant-Authorization": "Bearer " + os.getenv("INVARIANT_API_KEY")
43+
},
44+
# replace '<your-project-id>' with an new Explorer project ID (alphanumeric, dash allowed)
45+
base_url="https://explorer.invariantlabs.ai/api/v1/gateway/<your-project-id>/openai",
46+
)
47+
48+
# 2. Using the model
49+
client.chat.completions.create(
50+
messages=[{"role": "user", "content": "What do you know about Fight Club?"}],
51+
model="gpt-4o",
52+
)
53+
```
54+
55+
After this change, all your LLM requests will automatically be logged in your Explorer project. If the project does not exist on first use, it will be created automatically.
56+
57+
To use Anthropic models instead, you can adjust the `/openai` portion of your base URL to `/anthropic`. Apart from this, functionality like streaming and tool calling are supported seamlessly through Gateway.
58+
59+
To learn more about how Gateway works, check out the [Gateway documentation](../gateway/index.md).
60+
61+
## Configuring Your First Guardrailing Rules
62+
63+
To configure guardrails, switch to the `Guardrails` tab in the top navigation bar of your Explorer project.
64+
65+
<br/><br/>
66+
<img src="site:/guardrails/guardrails-configuration-explorer.png" alt="Explorer Landing" class="invariant-architecture" style="display: block; margin: 0 auto; width: 100%; max-width: 650pt;"/>
67+
68+
Here, you are presented with two options:
69+
70+
1. **Create a new guardrail**: This allows you to create a new guardrail from scratch.
71+
2. **Use a Guardrail Suggestion**: This allows you to use a pre-defined guardrail for your project.
72+
73+
## Creating a New Guardrail
74+
75+
To create a new Guardrail from scratch, click on the `Create Guardrail` button.
76+
77+
This will open the following modal, allowing for further configuration of the guardrail:
78+
79+
<img src="site:/guardrails/new-guardrail.png" alt="New Guardrail" class="invariant-architecture" style="display: block; margin: 0 auto; width: 100%; max-width: 650pt;"/>
80+
81+
Here, you can configure the following parameters:
82+
83+
**Name**: The name of the guardrail.
84+
85+
**Action**: The behavior of the guardrail in case of a violation. This can be one of the following:
86+
87+
| Action | Description |
88+
|---------------|----------------------------------------|
89+
| Block | Blocks the request outright, returning an HTTP error to the client. |
90+
| Log | Let's the request pass, but logs the violation in Explorer via designated Guardrail violation annotations in the resulting agent traces. This is useful to monitor your agent's violation patterns, without disrupting the agentic process. |
91+
| Paused | Pauses the enforcement of the guardrail, allowing all request to pass through without evaluating it. This is useful to temporarily disable a guardrail. |
92+
93+
94+
**Guardrailing Rule**: The guardrailing rules that need to be matched for the overall guardrail to be triggered. This is an editor of the Guardrails rule language, providing Invariant's full expressive power as described in this documentation.
95+
96+
97+
## Using a Guardrail Suggestion
98+
99+
To use a pre-defined guardrail, navigate to the bottom part of the Guardrails configuration page.
100+
101+
Here, you will see a list of pre-defined guardrails, along with a short description of the guardrail. These preconfigured rules, are meant to be a starting point for your guardrail configuration.
102+
103+
Click on the `Details` button to review and modify any preconfigured rule before deploying it to your project. Each guardrail suggestion comes with comments explaining its functionality.
104+
105+
<img src="site:/guardrails/guardrail-suggestions.png" alt="New Guardrail" class="invariant-architecture" style="display: block; margin: 0 auto; width: 100%; max-width: 650pt;"/>
106+
107+
## Deploying Your Guardrail
108+
109+
All changes made in Explorer are automatically deployed to your Gateway instance, enabling you to deploy new guardrails and security policies within seconds.
110+
111+
This means, even though your agentic system may be running in a slow-to-update production environment, you can quickly respond to new security threats and update your guardrails to your liking, without having to manually update your agent system or re-deploy.
112+
113+
It also enables quick experimentation with new guardrails, without having to worry about the underlying infrastructure. Gateway will automatically pull the latest guardrail configuration from Explorer once a new version is deployed, updating your agent's behavior in real-time.
114+
115+
## Inspecting Guardrail Failures
116+
117+
Lastly, to inspect guardrail failures in detail, navigate to the `Traces` tab in your Explorer project.
118+
119+
Newly pushed traces with Guardrail violations will be automatically annoated with Guardrail violation annotations, highlighting the exact range and location of the guardrail violation in the agent trace.
120+
121+
<figure style="display: block; margin: 0 auto; width: 100%; max-width: 800pt !important; border: 2pt solid #efefef; padding: 10pt; background-color: white;">
122+
<img src="site:/guardrails/guardrail-highlight.png" alt="New Guardrail" class="invariant-architecture" style="display: block; margin: 0 auto; width: 100%; max-width: 650pt;"/>
123+
<figcaption style="text-align: center; font-size: 0.8em; color: #666;">Guardrails precisely highlights the location and cause for guardrail violations in the agent trace, allowing users to exactly pinpoint the cause of the violation.</figcaption>
124+
</figure>
125+
126+
As you can see, the guardrail violation is highlighted in the trace down to the violating character range. Given this information, you can easily inspect and refine your guardrailing rules, to precisely match and constrain the behavior of your agentic system.
127+
128+
Further, the shown user annotation view, allows you to comment and collaboratively discuss the guardrail violation with your team, allowing for a collaborative debugging experience, including revisions over time and a full history of past guardrailing behavior.

0 commit comments

Comments
 (0)