You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/how_to_guides/instructions.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
1
1
# `Instructions` Element
2
2
3
+
**Note**: Instructions element support has been dropped in 0.6.0 in support of [messages](./messages).
4
+
3
5
The `<instructions></instructions>` element is passed to the LLM as secondary input. Different model may use these differently. For example, chat models may receive instructions in the system-prompt.
| Variables |`${variable_name}`| These are provided by the user at runtime, and substituted in the prompt. |
12
+
| Output Schema |`${output_schema}`| This is the schema of the expected output, and is compiled based on the `output` element. For more information on how the output schema is compiled for the prompt, check out [`output` element compilation](/docs/concepts/output/#adding-compiled-output-element-to-prompt). |
13
+
| Prompt Primitives |`${gr.prompt_primitive_name}`| These are pre-constructed prompts that are useful for common tasks. E.g., some primitives may contain information that helps the LLM understand the output schema better. To see the full list of prompt primitives, check out [`guardrails/constants.xml`](https://github.com/guardrails-ai/guardrails/blob/main/guardrails/constants.xml). |
14
+
15
+
```xml
16
+
<railversion="0.1">
17
+
<messages>
18
+
<messagerole="system">
19
+
<!-- (1)! -->
20
+
You are a helpful assistant only capable of communicating with valid JSON, and no other text.
21
+
</message>
22
+
<messagerole="user">
23
+
<!-- (2)! -->
24
+
Given the following document, answer the following questions. If the answer doesn't exist in the document, enter 'None'.
25
+
26
+
${document} <!-- (3)! -->
27
+
28
+
29
+
${gr.xml_prefix_prompt} <!-- (4)! -->
30
+
31
+
32
+
${output_schema} <!-- (5)! -->
33
+
34
+
35
+
${gr.json_suffix_prompt} <!-- (6)! -->
36
+
</message>
37
+
</message>
38
+
</rail>
39
+
```
40
+
41
+
1. The instructions element contains high level background information for the LLM containing textual context and constraints.
42
+
2. The prompt contains high level task information.
43
+
3. The variable `${document}` is provided by the user at runtime.
44
+
4.`${gr.xml_prefix_prompt}` is a prompt primitive provided by guardrails. It is equivalent to typing the following lines in the prompt: `Given below is XML that describes the information to extract from this document and the tags to extract it into.`
45
+
5.`${output_schema}` is the output schema and contains information about , which is compiled based on the `output` element.
46
+
6.`${gr.json_suffix_prompt}` is a prompt primitive provided by guardrails. It is equivalent to typing the following lines in the prompt:
47
+
```
48
+
ONLY return a valid JSON object (no other text is necessary). The JSON MUST conform to the XML format, including any types and format requests e.g. requests for lists, objects and specific types. Be correct and concise. If you are unsure anywhere, enter `null`.
49
+
```
50
+
51
+
The messages element is made up of message elements with role attributes. Messages with the role system are intended to be system level prompt. Messages with the role assistant are intended to be messages from the llm to be repassed to itself as additional context and history. Messages with role user are input from the user and also convey history of the conversation.
Copy file name to clipboardExpand all lines: docs/how_to_guides/rail.md
+30-95Lines changed: 30 additions & 95 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -78,15 +78,17 @@ Let's see an example of an `RAIL` specification in action:
78
78
</output>
79
79
80
80
81
-
<prompt> <!-- (2)! -->
81
+
<messages> <!-- (2)! -->
82
+
<messagerole="user">
82
83
...
83
-
</prompt>
84
+
</message>
85
+
</message>
84
86
85
87
</rail>
86
88
```
87
89
88
90
1. The `output` element contains the structure of the expected output of the LLM. It contains the spec for the overall structure of the LLM output, type info for each field, and the quality criteria for each field and the corrective action to be taken in case quality criteria is not met.
89
-
2. The `prompt` element contains the high level instructions that are sent to the LLM. Check out the [RAIL Prompt](#components-of-a-prompt-element) page for more details.
91
+
2. The `messages` element contains the high level instructions that are sent to the LLM. Check out the [RAIL Prompt](#components-of-a-message-element) page for more details.
1. A `Guard` object is created from a `RAIL` specification. This object manages the validation and correction of the output of the LLM, as well as the prompt that is sent to the LLM.
111
113
2. Wrap the LLM API call (`openai.Completion.create`) with the `Guard` object, and add any additional arguments that you want to pass to the LLM API call. Instead of returning the raw text object, the `Guard` object will return a JSON object that is validated and corrected according to the `RAIL` specification.
112
114
113
-
# `Instructions` Element
115
+
# `Messages` Element
114
116
115
-
The `<instructions></instructions>` element is passed to the LLM as secondary input. Different model may use these differently. For example, chat models may receive instructions in the system-prompt.
117
+
The `<messages></messages>` element contains instructions and the query that describes the high level task.
116
118
117
-
## Components of an Instructions Element
119
+
## 📚 Components of a Prompt Element
118
120
119
-
In addition to any static text describing the context of the task, instructions can also contain any of the following:
| Variables |`${variable_name}`| These are provided by the user at runtime, and substituted in the instructions. |
124
-
| Output Schema |`${output_schema}`| This is the schema of the expected output, and is compiled based on the `output` element. For more information on how the output schema is compiled for the instructions, check out [`output` element compilation](#adding-compiled-output-element-to-prompt)|
125
-
| Prompt Primitives |`${gr.prompt_primitive_name}`| These are pre-constructed blocks of text that are useful for common tasks. E.g., some primitives may contain information that helps the LLM understand the output schema better. To see the full list of prompt primitives, check out [`guardrails/constants.xml`](https://github.com/guardrails-ai/guardrails/blob/main/guardrails/constants.xml). |
126
-
127
-
128
-
Here's an example of how you could compose instructions using RAIL xml:
129
-
```xml
130
-
<railversion="0.1">
131
-
<instructions>
132
-
<!-- (1)! -->
133
-
You are a helpful assistant only capable of communicating with valid JSON, and no other text.
134
-
135
-
${gr.json_suffix_prompt_examples} <!-- (2)! -->
136
-
</instructions>
137
-
</rail>
138
-
```
139
-
140
-
1. The instructions element contains high level background information for the LLM containing textual context and constraints.
141
-
2.`${gr.json_suffix_prompt_examples}` is a prompt primitive provided by guardrails. It is equivalent to typing the following lines in the instructions:
142
-
````
143
-
ONLY return a valid JSON object (no other text is necessary), where the key of the field in JSON is the `name` attribute of the corresponding XML, and the value is of the type specified by the corresponding XML's tag. The JSON MUST conform to the XML format, including any types and format requests e.g. requests for lists, objects and specific types. Be correct and concise. If you are unsure anywhere, enter `null`.
144
-
145
-
Here are examples of simple (XML, JSON) pairs that show the expected behavior:
1. The instructions element contains high level background information for the LLM containing textual context and constraints.
161
-
2.`${gr.json_suffix_prompt_examples}` is a prompt primitive provided by guardrails. It is equivalent to typing the following lines in the instructions:
162
-
````
163
-
ONLY return a valid JSON object (no other text is necessary), where the key of the field in JSON is the `name` attribute of the corresponding XML, and the value is of the type specified by the corresponding XML's tag. The JSON MUST conform to the XML format, including any types and format requests e.g. requests for lists, objects and specific types. Be correct and concise. If you are unsure anywhere, enter `null`.
164
-
165
-
Here are examples of simple (XML, JSON) pairs that show the expected behavior:
| Variables |`${variable_name}`| These are provided by the user at runtime, and substituted in the prompt. |
199
-
| Output Schema |`${output_schema}`| This is the schema of the expected output, and is compiled based on the `output` element. For more information on how the output schema is compiled for the prompt, check out [`output` element compilation](#adding-compiled-output-element-to-prompt). |
126
+
| Output Schema |`${output_schema}`| This is the schema of the expected output, and is compiled based on the `output` element. For more information on how the output schema is compiled for the prompt, check out [`output` element compilation](/docs/concepts/output/#adding-compiled-output-element-to-prompt). |
200
127
| Prompt Primitives |`${gr.prompt_primitive_name}`| These are pre-constructed prompts that are useful for common tasks. E.g., some primitives may contain information that helps the LLM understand the output schema better. To see the full list of prompt primitives, check out [`guardrails/constants.xml`](https://github.com/guardrails-ai/guardrails/blob/main/guardrails/constants.xml). |
201
128
202
129
```xml
203
130
<railversion="0.1">
204
-
<prompt>
131
+
<messages>
132
+
<messagerole="system">
205
133
<!-- (1)! -->
134
+
You are a helpful assistant only capable of communicating with valid JSON, and no other text.
135
+
</message>
136
+
<messagerole="user">
137
+
<!-- (2)! -->
206
138
Given the following document, answer the following questions. If the answer doesn't exist in the document, enter 'None'.
207
139
208
-
${document} <!-- (2)! -->
209
-
140
+
${document} <!-- (3)! -->
210
141
211
-
${gr.xml_prefix_prompt} <!-- (3)! -->
212
142
143
+
${gr.xml_prefix_prompt} <!-- (4)! -->
213
144
214
-
${output_schema} <!-- (4)! -->
215
145
146
+
${output_schema} <!-- (5)! -->
216
147
217
-
${gr.json_suffix_prompt} <!-- (5)! -->
218
148
219
-
</prompt>
149
+
${gr.json_suffix_prompt} <!-- (6)! -->
150
+
</message>
151
+
</message>
220
152
</rail>
221
153
```
222
154
223
-
1. The prompt contains high level task information.
224
-
2. The variable `${document}` is provided by the user at runtime.
225
-
3.`${gr.xml_prefix_prompt}` is a prompt primitive provided by guardrails. It is equivalent to typing the following lines in the prompt: `Given below is XML that describes the information to extract from this document and the tags to extract it into.`
226
-
4.`${output_schema}` is the output schema and contains information about , which is compiled based on the `output` element.
227
-
5.`${gr.json_suffix_prompt}` is a prompt primitive provided by guardrails. It is equivalent to typing the following lines in the prompt:
155
+
1. The instructions element contains high level background information for the LLM containing textual context and constraints.
156
+
2. The prompt contains high level task information.
157
+
3. The variable `${document}` is provided by the user at runtime.
158
+
4.`${gr.xml_prefix_prompt}` is a prompt primitive provided by guardrails. It is equivalent to typing the following lines in the prompt: `Given below is XML that describes the information to extract from this document and the tags to extract it into.`
159
+
5.`${output_schema}` is the output schema and contains information about , which is compiled based on the `output` element.
160
+
6.`${gr.json_suffix_prompt}` is a prompt primitive provided by guardrails. It is equivalent to typing the following lines in the prompt:
228
161
```
229
162
ONLY return a valid JSON object (no other text is necessary). The JSON MUST conform to the XML format, including any types and format requests e.g. requests for lists, objects and specific types. Be correct and concise. If you are unsure anywhere, enter `null`.
230
163
```
231
164
165
+
The messages element is made up of message elements with role attributes. Messages with the role system are intended to be system level prompt. Messages with the role assistant are intended to be messages from the llm to be repassed to itself as additional context and history. Messages with role user are input from the user and also convey history of the conversation.
166
+
232
167
# `Output` Element
233
168
234
169
The `<output>...</output>` element of a `RAIL` spec is used to give precise specification of the expected output of the LLM. It specifies
0 commit comments