Skip to content

DeepTeam is a framework to red team LLMs and AI agents.

.

penguine39f45448a696
diff --git a/docs/docs/guardrails-introduction.mdx b/docs/docs/guardrails-introduction.mdx
index 229cd97d..85eb6cec 100644
--- a/docs/docs/guardrails-introduction.mdx
+++ b/docs/docs/guardrails-introduction.mdx
@@ -91,9 +91,9 @@ Then, simply call the `guard_input()` method and supply the `input`.
```python
...
-guard_result = guardrails.guard_input(input="Is the earth flat")
+res = guardrails.guard_input(input="Is the earth flat")
# Reject if true
-print(guard_result.breached)
+print(res.breached)
```
The `guard_input` method will invoke every single guard within your `Guardrails`s to check whether a particular input has breached any of the defined criteria.
@@ -105,8 +105,8 @@ Simiarly, call the `guard_output` method wherever appropriate in your code to gu
```python
...
-guard_result = guardrails.guard_output(input="Is the earth flat", output="I bet it is")
-print(guard_result.breached)
+res = guardrails.guard_output(input="Is the earth flat", output="I bet it is")
+print(res.breached)
```
It is extremely common to be re-generated LLM outputs for _x_ number of times until successful.
@@ -122,7 +122,7 @@ When using the `guard_output()` method, you must provide both the `input` and th
```python
...
-guard_result = await guardrails.a_guard_output(input, output)
+res = await guardrails.a_guard_output(input, output)
```
## Available Guards
@@ -133,21 +133,21 @@ guard_result = await guardrails.a_guard_output(input, output)
Input guards protect your LLM system by screening user inputs before they reach your model, preventing malicious prompts and unwanted content from being processed:
-- **[Prompt Injection Guard](/docs/guardrails-prompt-injection-guard)** - Detects and blocks prompt injection and jailbreaking attempts that try to manipulate the AI's behavior or bypass safety measures
-- **[Topical Guard](/docs/guardrails-topical-guard)** - Restricts conversations to specific allowed topics, preventing off-topic or unauthorized discussions
-- **[Cybersecurity Guard](/docs/guardrails-cybersecurity-guard)** - (When configured for input) Protects against cybersecurity threats and malicious technical instructions
+- [Prompt Injection Guard](/docs/guardrails-prompt-injection-guard) - Detects and blocks prompt injection and jailbreaking attempts that try to manipulate the AI's behavior or bypass safety measures
+- [Topical Guard](/docs/guardrails-topical-guard) - Restricts conversations to specific allowed topics, preventing off-topic or unauthorized discussions
+- [Cybersecurity Guard](/docs/guardrails-cybersecurity-guard) - (When configured for input) Protects against cybersecurity threats and malicious technical instructions
### Output
Output guards evaluate your LLM's responses before they reach users, ensuring safe and appropriate content delivery:
-- **[Toxicity Guard](/docs/guardrails-toxicity-guard)** - Prevents toxic, harmful, abusive, or discriminatory content from being shared with users
-- **[Privacy Guard](/docs/guardrails-privacy-guard)** - Detects and blocks personally identifiable information (PII) and sensitive data from being exposed
-- **[Illegal Guard](/docs/guardrails-illegal-guard)** - Prevents the sharing of illegal activity instructions or content that violates laws
-- **[Hallucination Guard](/docs/guardrails-hallucination-guard)** - Detects and prevents fabricated, inaccurate, or hallucinated information in responses
-- **[Cybersecurity Guard](/docs/guardrails-cybersecurity-guard)** - (When configured for output) Ensures responses don't contain dangerous cybersecurity information or instructions
+- [Toxicity Guard](/docs/guardrails-toxicity-guard) - Prevents toxic, harmful, abusive, or discriminatory content from being shared with users
+- [Privacy Guard](/docs/guardrails-privacy-guard) - Detects and blocks personally identifiable information (PII) and sensitive data from being exposed
+- [Illegal Guard](/docs/guardrails-illegal-guard) - Prevents the sharing of illegal activity instructions or content that violates laws
+- [Hallucination Guard](/docs/guardrails-hallucination-guard) - Detects and prevents fabricated, inaccurate, or hallucinated information in responses
+- [Cybersecurity Guard](/docs/guardrails-cybersecurity-guard) - (When configured for output) Ensures responses don't contain dangerous cybersecurity information or instructions
-## 3-Tier Safety System
+### 3-Tier Safety System
All of `deepteam`'s guards uses a **3-tier safety assessment system**:
@@ -155,10 +155,13 @@ All of `deepteam`'s guards uses a **3-tier safety assessment system**:
- `uncertain`: The content is borderline or ambiguous, requiring human review
- `unsafe`: The content clearly violates safety guidelines
-```python
-# Access detailed safety assessment
-print(guard_result.safety_level) # "safe", "uncertain", or "unsafe"
-print(guard_result.reason) # Explanation for the assessment
+```python title="main.py"
+...
+
+for verdict in res.verdicts:
+ # Access detailed safety assessment
+ print(verdict.safety_level) # "safe", "uncertain", or "unsafe"
+ print(verdict.reason) # Explanation for the assessment
```
The reason why `deepteam` does this is it allows you to control the strictness of each and every guard, and control what consitutues as a "breached" or "mitigated" event.
@@ -168,3 +171,35 @@ A `Guardrails` is considered **breached** if any guard returns `unsafe` or `unce
:::tip
`Guardrails` used against malicious inputs is the best way to not waste tokens generating text that you shouldn't even be generating in the first place.
:::
+
+## Data Models
+
+There are two data models you should be aware of to access guardrail results after each run.
+
+### `GuardResult`
+
+The `GuardResult` data model is what you'll receive after `guard_input()` or `guard_output()`. It tells you whether the I/O has breached any of the criteria laid out in your guards or not, as well as the individual breakdown of all the guards:
+
+```python file="guard-result.py"
+class GuardResult:
+ breached: bool
+ verdicts: list[GuardVerdict]
+```
+
+### `GuardVerdict`
+
+You can access each individual guard's results through the `GuardVerdict` data model in the `verdicts` field of a `GuardResult`.
+
+```python file="guard-verdict.py"
+class GuardVerdict(BaseModel):
+ name: str
+ safety_level: Literal["safe", "unsafe", "uncertain"]
+ latency: Optional[float] = None
+ reason: Optional[str] = None
+ score: Optional[float] = None
+ error: Optional[str] = None
+```
+
+:::tip
+You should decide what retry logic to run, if any, depending on the results you're getting after each guardrails invocation.
+:::