Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into dtam/051_6x_deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
dtam committed Jul 31, 2024
2 parents 04006df + 70fa5ac commit 8b4df1f
Show file tree
Hide file tree
Showing 36 changed files with 1,405 additions and 530 deletions.
14 changes: 14 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
blank_issues_enabled: false
contact_links:
- name: Guardrails Documentation
url: https://www.guardrailsai.com/docs
about: Check our documentation for answers to common questions and usage guides.
- name: Guardrails Hub
url: https://hub.guardrailsai.com/
about: Explore pre-built validators and guards for specific types of risks.
- name: GitHub Discussions
url: https://github.com/guardrails-ai/guardrails/discussions
about: Ask questions and discuss with other community members about Guardrails.
- name: Join our Discord Community
url: https://discord.com/invite/gw4cR9QvYE
about: Connect with other Guardrails users and get real-time support.
25 changes: 25 additions & 0 deletions .github/ISSUE_TEMPLATE/documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
name: Documentation issue
about: Report a problem or suggest an improvement for Guardrails documentation
title: "[docs]"
labels: documentation
assignees: ''

---

**Description**
[Add a clear description of the documentation issue or improvement suggestion]

**Current documentation**
[Provide a link to the current documentation page or section that needs attention]

**Suggested changes**
[If you have specific changes in mind, describe them here. Be as detailed as possible]

**Additional context**
[Add any other context, screenshots, or examples that could help explain the issue or improvement]

**Checklist**
- [ ] I have checked that this issue hasn't already been reported
- [ ] I have checked the latest version of the documentation to ensure this issue still exists
- [ ] For simple typos or fixes, I have considered submitting a pull request instead
13 changes: 12 additions & 1 deletion docs/concepts/deploying.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

This document is a guide on our preffered method to deploy Guardrails to production. We will discuss the new client/server model and the benefits this approach gains us. We'll also look at some patterns we find useful when deploying to a production environment as well as some practices to keep in mind when developing with this new pattern.

:::note
Read the quick start guide on using Guardrails on the server [here](https://www.guardrailsai.com/docs/getting_started/guardrails_server)
:::

## The Client/Server Model

### Guardrails As A Service
Expand Down Expand Up @@ -86,4 +90,11 @@ When selecting a deployment environment it is important to consider what types o
## Patterns and Practices for Using the Client/Server Model
When considering what to put where when splitting your Guardrails implementation between your client application and the Guardrails API, it mostly comes down to shifting the heavy lifting to the server and keeping your implementation on the client side to a minimum.
For example, you should define your Guards in the `config.py` that is loaded onto the server, not in your client application. Additionally validators from the Guardrails HUB should also be installed on the server since that is where they will be executed; no need to install these in the client application. This also means that _generally_ any extras you need alongside Guardrails would also be installed server side; that is, you would only want to install `guardails-ai` in your application whereas you would install `guardrails-ai[api]` on the server. This keeps additional dependencies where they belong.
For example, you should define your Guards in the `config.py` that is loaded onto the server, not in your client application. Additionally validators from the Guardrails HUB should also be installed on the server since that is where they will be executed; no need to install these in the client application. This also means that _generally_ any extras you need alongside Guardrails would also be installed server side; that is, you would only want to install `guardails-ai` in your application whereas you would install `guardrails-ai[api]` on the server. This keeps additional dependencies where they belong.
## Next Steps
Go ahead and deploy your dockerized Guardrails server on any cloud! We have guides on how to deploy Guardrails on specific clouds.
- [Deploying Guardrails on AWS](https://www.guardrailsai.com/docs/how_to_guides/deploying_aws)
2 changes: 1 addition & 1 deletion docs/examples/json_function_calling_tools.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.2"
"version": "3.11.7"
}
},
"nbformat": 4,
Expand Down
5 changes: 4 additions & 1 deletion docs/how_to_guides/deploying_aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ Guardrails allows you to deploy a dedicated server to run guard executions while

In this cookbook we show an example of deploying a containerized version of Guardrails API into AWS leveraging AWS ECS.

> Note: Guardrails API is a feature is available as of `>=0.5.0`
:::note
- Read the quick start guide on using Guardrails on the server [here](https://www.guardrailsai.com/docs/getting_started/guardrails_server)
- Find generalized information on deploying Guardrails [here](https://www.guardrailsai.com/docs/concepts/deploying)
:::


## Step 1: Containerizing Guardrails API
Expand Down
8 changes: 3 additions & 5 deletions docs/how_to_guides/generate_structured_data.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

Guardrails provides several interfaces to help llms respond in valid JSON which can then be validated using Guardrails validators. In this cookbook, we'll demonstrate how each interface is used with examples.

To learn more about our approach to structured data, see the [Structured Data](https://guardrailsai.com/docs/structured_data) guide.

## Prerequisites

First, create a Pydantic model and guard for the structured data. The model should describe the data structure to be returned. Pydantic Fields support Guardrails validators and are initialized at the same time as validators.
Expand Down Expand Up @@ -64,7 +62,7 @@ messages = [{

### Function/tool calling structured response formatting

For models that support openai tool/function calling(`gpt-4o`, `gpt-4-turbo`, or `gpt-3.5-turbo`). Learn more about tools [here](https://guardrailsai.com/docs/tools).
For models that support openai tool/function calling(`gpt-4o`, `gpt-4-turbo`, or `gpt-3.5-turbo`).

```py
tools = [] # an open ai compatible list of tools
Expand All @@ -80,7 +78,7 @@ response = guard(

### Prompt Updates

For models that support JSON through prompt engineering and hinting (most models). Learn more about prompt engineering for structured data [here](https://guardrailsai.com/docs/prompt_engineering).
For models that support JSON through prompt engineering and hinting (most models).


```py
Expand All @@ -100,7 +98,7 @@ response = guard(

### Constrained decoding structured response formatting

For Hugging Face models structured JSON output maybe returned utilizing constrained decoding. Constrained decoding is a technique that allows you to guide the model to generate a specific type of output, a little bit like JSON ad-libs. Learn more about constrained decoding [here](https://guardrailsai.com/docs/constrained_decoding).
For Hugging Face models structured JSON output maybe returned utilizing constrained decoding. Constrained decoding is a technique that allows you to guide the model to generate a specific type of output, a little bit like JSON ad-libs. Learn more about constrained decoding [here](https://www.guardrailsai.com/blog/json-with-open-source-models).

```python
g = Guard.from_pydantic(NewFriends, output_formatter="jsonformer")
Expand Down
20 changes: 10 additions & 10 deletions docs/how_to_guides/output.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ You can combine `RAIL` elements to create an arbitrarily complex output structur
<rail version="0.1">
<output>
<object name="some_object">
<string name="some_str_key" description="What should the value for this key represent?" format="two-words; upper-case" />
<integer name="some_other_key" description="What should this integer represent?" format="min-val: 0"/>
<string name="some_str_key" description="What should the value for this key represent?" validators="guardrails/uppercase; guardrails/two_words" />
<integer name="some_other_key" description="What should this integer represent?" validators="guardrails/valid_range:0" />
</object>
</output>
</rail>
Expand Down Expand Up @@ -139,7 +139,7 @@ In the above example, `"SOME STRING"` is the value for the `some_str_key` key, a
<rail version="0.1">
<output>
<list name="some_list" format="min-len: 2">
<string format="two-words; upper-case" />
<string validators="guardrails/uppercase; guardrails/two_words" />
</list>
</output>
</rail>
Expand Down Expand Up @@ -237,7 +237,7 @@ Each element can have attributes that specify additional information about the d

2. `description` attribute that specifies the description of the field. This is similar to a prompt that will be provided to the LLM. It can contain more context to help the LLM generate the correct output.
3. (Coming soon!) `required` attribute that specifies whether the field is required or not. If the field is required, the LLM will be asked to generate the field until it is generated correctly. If the field is not required, the LLM will not be asked to generate the field if it is not generated correctly.
4. `format` attribute that specifies the quality criteria that the field should respect. The `format` attribute can contain multiple quality criteria separated by a colon (`;`). For example, `two-words; upper-case`.
4. `validators` attribute that specifies the quality criteria that the field should respect. The `format` attribute can contain multiple quality criteria separated by a colon (`;`). For example, `guardrails/uppercase; guardrails/two_words`.
5. `on-fail-{quality-criteria}` attribute that specifies the corrective action to take in case the quality criteria is not met. For example, `on-fail-two-words="reask"` specifies that if the field does not have two words, the LLM should be asked to re-generate the field.


Expand All @@ -251,9 +251,9 @@ E.g.,
name="some_key"
description="Detailed description of what the value of the key should be"
required="true"
format="two-words; upper-case"
on-fail-two-words="reask"
on-fail-upper-case="noop"
validators="guardrails/uppercase; guardrails/two_words"
on-fail-guardrails_two_words="reask"
on-fail-guardrails_uppercase="noop"
/>
</output>
</rail>
Expand All @@ -277,8 +277,8 @@ The `format` attribute allows specifying the quality criteria for each field in
<string
name="text"
description="The generated text"
format="two-words; upper-case"
on-fail-two-words="reask"
validators="guardrails/uppercase; guardrails/two_words"
on-fail-guardrails_two_words="reask"
/>
</output>
</rail>
Expand Down Expand Up @@ -339,7 +339,7 @@ An example of the compiled `output` element:
<string
name="text"
description="The generated text"
format="two-words; upper-case"
validators="guardrails/uppercase; guardrails/two_words"
/>
</output>
</rail>
Expand Down
21 changes: 11 additions & 10 deletions docs/how_to_guides/rail.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ You can combine `RAIL` elements to create an arbitrarily complex output structur
<rail version="0.1">
<output>
<object name="some_object">
<string name="some_str_key" description="What should the value for this key represent?" format="two-words; upper-case" />
<string name="some_str_key" description="What should the value for this key represent?" validators="guardrails/uppercase; guardrails/two_words" />
<integer name="some_other_key" description="What should this integer represent?" format="min-val: 0"/>
</object>
</output>
Expand Down Expand Up @@ -362,15 +362,15 @@ In the above example, `"SOME STRING"` is the value for the `some_str_key` key, a
- Currently, a list element can only contain a single child element. This means that a list can only contain a single type of data. For example, a list can only contain strings, or a list can only contain integers, but a list cannot contain both strings and integers.
- This child element can be any RAIL element, including another `list` or `object` elements.
- The child of a list element doesn't need to have a `name` attribute, since items in a list don't have names.
- Formatters can be applied to the child element of a list element. For example, if the child element is a `string` element, the `format` attribute can be used to specify the quality criteria for the strings in the list.
- Formatters can be applied to the child element of a list element. For example, if the child element is a `string` element, the `validators` attribute can be used to specify the quality criteria for the strings in the list.

=== "RAIL Spec"

```xml
<rail version="0.1">
<output>
<list name="some_list" format="min-len: 2">
<string format="two-words; upper-case" />
<string validators="guardrails/uppercase; guardrails/two_words" />
</list>
</output>
</rail>
Expand Down Expand Up @@ -466,7 +466,7 @@ Each element can have attributes that specify additional information about the d

2. `description` attribute that specifies the description of the field. This is similar to a prompt that will be provided to the LLM. It can contain more context to help the LLM generate the correct output.
3. (Coming soon!) `required` attribute that specifies whether the field is required or not. If the field is required, the LLM will be asked to generate the field until it is generated correctly. If the field is not required, the LLM will not be asked to generate the field if it is not generated correctly.
4. `format` attribute that specifies the quality criteria that the field should respect. The `format` attribute can contain multiple quality criteria separated by a colon (`;`). For example, `two-words; upper-case`.
4. `validators` attribute that specifies the quality criteria that the field should respect. The `validators` attribute can contain multiple quality criteria separated by a colon (`;`). For example, `guardrails/uppercase; guardrails/two_words`.
5. `on-fail-{quality-criteria}` attribute that specifies the corrective action to take in case the quality criteria is not met. For example, `on-fail-two-words="reask"` specifies that if the field does not have two words, the LLM should be asked to re-generate the field.


Expand All @@ -480,9 +480,9 @@ E.g.,
name="some_key"
description="Detailed description of what the value of the key should be"
required="true"
format="two-words; upper-case"
on-fail-two-words="reask"
on-fail-upper-case="noop"
validators="guardrails/uppercase; guardrails/two_words"
on-fail-guardrails_two_words="reask"
on-fail-guardrails_uppercase="noop"
/>
</output>
</rail>
Expand All @@ -506,8 +506,9 @@ The `format` attribute allows specifying the quality criteria for each field in
<string
name="text"
description="The generated text"
format="two-words; upper-case"
on-fail-two-words="reask"
validators="guardrails/uppercase; guardrails/two_words"
on-fail-guardrails_two_words="reask"
on-fail-guardrails_uppercase="noop"
/>
</output>
</rail>
Expand Down Expand Up @@ -568,7 +569,7 @@ An example of the compiled `output` element:
<string
name="text"
description="The generated text"
format="two-words; upper-case"
validators="guardrails/uppercase; guardrails/two_words"
/>
</output>
</rail>
Expand Down
3 changes: 2 additions & 1 deletion docs/how_to_guides/structured_data_with_guardrails.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ Below is the syntax for generating structured data with Guardrails AI using `Pyd
<integer name="age" />
<boolean name="is_employed" />
</output>
</rail>
```

Then, create a `Guard` object that uses the RAIL spec to generate structured data.
```python
from guardrails import Guard

guard = Guard.from_s("""
guard = Guard.from_rail_string("""
<rail version="0.1">
<output>
<string name="name" />
Expand Down
4 changes: 2 additions & 2 deletions docs/how_to_guides/using_llms.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ guard = Guard.from_pydantic(Basket)
result = guard(
messages=[{"role":"user", "content":"Generate a basket of 5 fruits"}],
model="gpt-4o",
tools=guard.add_json_function_calling_tool([]),
tools=guard.json_function_calling_tool([]),
tool_choice="required",
)

Expand Down Expand Up @@ -248,4 +248,4 @@ print(f"{result.validated_output}")

## Other LLMs

See LiteLLM’s documentation [here](https://docs.litellm.ai/docs/providers) for details on many other llms.
See LiteLLM’s documentation [here](https://docs.litellm.ai/docs/providers) for details on many other llms.
Binary file added docs/integrations/assets/langsmith_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/integrations/assets/langsmith_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8b4df1f

Please sign in to comment.