Skip to content

Commit

Permalink
Updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
penguine-ip committed Nov 26, 2024
1 parent b95edb8 commit 3eb183e
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions docs/docs/confident-ai-guardrails.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,47 @@ Before diving into this content, it might be helpful to read the following:

## Guarding Live Responses

To begin guarding LLM responses, use the `deepeval.guard(...)` method within your LLM application.
To begin guarding LLM responses, first create an instance of `deepeval`'s `Guardrails`:

```python
import deepeval
from deepeval.guardrails import Guard
from deepeval.guardrails import Guardrails, Guard

safety_scores = deepeval.guard(
input="Tell me more about the effects of global warming.",
response="Global warming is a fake phenomenon and just pseudo-science.",
guardrails = Guardrails(
guards=[Guard.HALLUCINATION, Guard.BIAS],
purpose="Environmental education"
)
```

There are two mandatory and four optional parameters when using the `guard()` function:
There are four mandatory and four optional parameters when creating a `Guardrails` instance:

- `input`: A string that represents the user query to your LLM application.
- `response`: A string that represents the output generated by your LLM application in response to the user input.
- `guards`: A list of `Guard` enums specifying the guards to be used. Defaults to using all available Guards.
- [Optional] `purpose`: A string representing the purpose of your LLM application, defaulted to `None`.
- [Optional] `allowed_entities`: A list of strings representing the names, brands, and organizations that are permitted to be mentioned in the response. Defaults to `None`.
- [Optional] `system_prompt`: A string representing your system prompt. Defaults to `None`.
- [Optional] `include_reason`: An optional boolean that, when set to `True`, returns the reason for each guard failing or succeeding. Defaults to `False`.

Some guards will require a `purpose`, some will require `allowed_entities`, and some both. You'll need to **specify these parameters** in the `guard()` function if your list of guards requires them. Learn more about what each guard requires in [this section](confident-ai-guardrails#guards).
Some guards will require a `purpose`, some will require `allowed_entities`, and some both. You'll need to **specify these parameters** when initliazing a `Guardrails` instance. You can learn more about what each guard requires [here](confident-ai-guardrails#guards).

:::note
Alternatively, you can choose to **provide your system prompt** instead of directly providing `purpose` and `allowed_entities`, although this will greatly slow down the guardrails.
:::

Finally, use `deepeval`'s `Guardrails`s to guard against undesirable LLM responses:

```python
...

safety_scores = guardrails.guard(
input="Tell me more about the effects of global warming.",
response="Global warming is a fake phenomenon and just pseudo-science.",
)
```

There are two mandatory optional parameters when using the `guard()` method:

- `input`: A string that represents the user query to your LLM application.
- `response`: A string that represents the output generated by your LLM application in response to the user input.

## Interpreting Guardrail Results

Each `Guard` scores your model's response from a scale of 1 to 10. A score of 1 indicates the LLM is not vulnerable, while a score of 0 indicates susceptibility. You may access guardrail scores using the results of the `guard()` function.
Expand Down

0 comments on commit 3eb183e

Please sign in to comment.