Skip to content

Commit b485018

Browse files
authored
Requirements implementation (#1097)
* requirements implementation and example Signed-off-by: Mandana Vaziri <[email protected]>
1 parent 3efb157 commit b485018

File tree

6 files changed

+282
-1
lines changed

6 files changed

+282
-1
lines changed

examples/requirements/email.pdl

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
description: Hello world calling a model
2+
defs:
3+
eval:
4+
function:
5+
requirement: string
6+
response: string
7+
return:
8+
lastOf:
9+
- model: ollama_chat/mistral-small:latest
10+
def: result
11+
input: |
12+
Does the following email end with Kind regards. Answer with a JSON object and a result field with value True or False only.
13+
Email: ${ response }
14+
parser: json
15+
- ${ result.result }
16+
17+
fix:
18+
function:
19+
requirement: string
20+
response: string
21+
return:
22+
lastOf:
23+
- model: ollama_chat/mistral-small:latest
24+
def: instruction
25+
input: |
26+
A model responded with the following response: ${ response }
27+
In order to satisfy the following requirement: ${ requirement }
28+
what should be added to the prompt as an instruction?
29+
30+
Respond with only with the instruction.
31+
- ${ pdl_context }
32+
33+
notes: Olivia helped the lab over the last few weeks by organizing intern events, advertising the speaker series, and handling issues with snack delivery.
34+
name: Olivia
35+
text:
36+
- "Write an email to ${ name } using the notes following: ${ notes }"
37+
- model: ollama_chat/granite3.2:2b
38+
requirements:
39+
- description: The email should end with Kind regards
40+
evaluate: ${ eval }
41+
transformContext: ${ fix }
42+
retry: 5

src/pdl/pdl-schema.json

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@
7676
"default": null,
7777
"description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n "
7878
},
79+
"requirements": {
80+
"$ref": "#/$defs/RequirementsType",
81+
"default": [],
82+
"description": "Specify any requirements that the result of the block must satisfy.\n "
83+
},
7984
"role": {
8085
"$ref": "#/$defs/OptionalStr",
8186
"default": null,
@@ -194,6 +199,11 @@
194199
"default": null,
195200
"description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n "
196201
},
202+
"requirements": {
203+
"$ref": "#/$defs/RequirementsType",
204+
"default": [],
205+
"description": "Specify any requirements that the result of the block must satisfy.\n "
206+
},
197207
"role": {
198208
"$ref": "#/$defs/OptionalStr",
199209
"default": null,
@@ -417,6 +427,11 @@
417427
"default": null,
418428
"description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n "
419429
},
430+
"requirements": {
431+
"$ref": "#/$defs/RequirementsType",
432+
"default": [],
433+
"description": "Specify any requirements that the result of the block must satisfy.\n "
434+
},
420435
"role": {
421436
"$ref": "#/$defs/OptionalStr",
422437
"default": null,
@@ -554,6 +569,11 @@
554569
"default": null,
555570
"description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n "
556571
},
572+
"requirements": {
573+
"$ref": "#/$defs/RequirementsType",
574+
"default": [],
575+
"description": "Specify any requirements that the result of the block must satisfy.\n "
576+
},
557577
"role": {
558578
"$ref": "#/$defs/OptionalStr",
559579
"default": null,
@@ -726,6 +746,11 @@
726746
"default": null,
727747
"description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n "
728748
},
749+
"requirements": {
750+
"$ref": "#/$defs/RequirementsType",
751+
"default": [],
752+
"description": "Specify any requirements that the result of the block must satisfy.\n "
753+
},
729754
"role": {
730755
"$ref": "#/$defs/OptionalStr",
731756
"default": null,
@@ -849,6 +874,11 @@
849874
"default": null,
850875
"description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n "
851876
},
877+
"requirements": {
878+
"$ref": "#/$defs/RequirementsType",
879+
"default": [],
880+
"description": "Specify any requirements that the result of the block must satisfy.\n "
881+
},
852882
"role": {
853883
"$ref": "#/$defs/OptionalStr",
854884
"default": null,
@@ -966,6 +996,11 @@
966996
"default": null,
967997
"description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n "
968998
},
999+
"requirements": {
1000+
"$ref": "#/$defs/RequirementsType",
1001+
"default": [],
1002+
"description": "Specify any requirements that the result of the block must satisfy.\n "
1003+
},
9691004
"role": {
9701005
"$ref": "#/$defs/OptionalStr",
9711006
"default": null,
@@ -1116,6 +1151,11 @@
11161151
"default": null,
11171152
"description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n "
11181153
},
1154+
"requirements": {
1155+
"$ref": "#/$defs/RequirementsType",
1156+
"default": [],
1157+
"description": "Specify any requirements that the result of the block must satisfy.\n "
1158+
},
11191159
"role": {
11201160
"$ref": "#/$defs/OptionalStr",
11211161
"default": null,
@@ -1255,6 +1295,11 @@
12551295
"default": null,
12561296
"description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n "
12571297
},
1298+
"requirements": {
1299+
"$ref": "#/$defs/RequirementsType",
1300+
"default": [],
1301+
"description": "Specify any requirements that the result of the block must satisfy.\n "
1302+
},
12581303
"role": {
12591304
"$ref": "#/$defs/OptionalStr",
12601305
"default": null,
@@ -1364,6 +1409,11 @@
13641409
"default": null,
13651410
"description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n "
13661411
},
1412+
"requirements": {
1413+
"$ref": "#/$defs/RequirementsType",
1414+
"default": [],
1415+
"description": "Specify any requirements that the result of the block must satisfy.\n "
1416+
},
13671417
"role": {
13681418
"$ref": "#/$defs/OptionalStr",
13691419
"default": null,
@@ -1563,6 +1613,11 @@
15631613
"default": null,
15641614
"description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n "
15651615
},
1616+
"requirements": {
1617+
"$ref": "#/$defs/RequirementsType",
1618+
"default": [],
1619+
"description": "Specify any requirements that the result of the block must satisfy.\n "
1620+
},
15661621
"role": {
15671622
"$ref": "#/$defs/OptionalStr",
15681623
"default": null,
@@ -1685,6 +1740,11 @@
16851740
"default": null,
16861741
"description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n "
16871742
},
1743+
"requirements": {
1744+
"$ref": "#/$defs/RequirementsType",
1745+
"default": [],
1746+
"description": "Specify any requirements that the result of the block must satisfy.\n "
1747+
},
16881748
"role": {
16891749
"$ref": "#/$defs/OptionalStr",
16901750
"default": null,
@@ -1798,6 +1858,11 @@
17981858
"default": null,
17991859
"description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n "
18001860
},
1861+
"requirements": {
1862+
"$ref": "#/$defs/RequirementsType",
1863+
"default": [],
1864+
"description": "Specify any requirements that the result of the block must satisfy.\n "
1865+
},
18011866
"role": {
18021867
"$ref": "#/$defs/OptionalStr",
18031868
"default": null,
@@ -2068,6 +2133,11 @@
20682133
"default": null,
20692134
"description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n "
20702135
},
2136+
"requirements": {
2137+
"$ref": "#/$defs/RequirementsType",
2138+
"default": [],
2139+
"description": "Specify any requirements that the result of the block must satisfy.\n "
2140+
},
20712141
"role": {
20722142
"$ref": "#/$defs/OptionalStr",
20732143
"default": null,
@@ -2184,6 +2254,11 @@
21842254
"default": null,
21852255
"description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n "
21862256
},
2257+
"requirements": {
2258+
"$ref": "#/$defs/RequirementsType",
2259+
"default": [],
2260+
"description": "Specify any requirements that the result of the block must satisfy.\n "
2261+
},
21872262
"role": {
21882263
"$ref": "#/$defs/OptionalStr",
21892264
"default": null,
@@ -2770,6 +2845,11 @@
27702845
"default": null,
27712846
"description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n "
27722847
},
2848+
"requirements": {
2849+
"$ref": "#/$defs/RequirementsType",
2850+
"default": [],
2851+
"description": "Specify any requirements that the result of the block must satisfy.\n "
2852+
},
27732853
"role": {
27742854
"$ref": "#/$defs/OptionalStr",
27752855
"default": null,
@@ -2942,6 +3022,11 @@
29423022
"default": null,
29433023
"description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n "
29443024
},
3025+
"requirements": {
3026+
"$ref": "#/$defs/RequirementsType",
3027+
"default": [],
3028+
"description": "Specify any requirements that the result of the block must satisfy.\n "
3029+
},
29453030
"role": {
29463031
"$ref": "#/$defs/OptionalStr",
29473032
"default": null,
@@ -3137,6 +3222,11 @@
31373222
"default": null,
31383223
"description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n "
31393224
},
3225+
"requirements": {
3226+
"$ref": "#/$defs/RequirementsType",
3227+
"default": [],
3228+
"description": "Specify any requirements that the result of the block must satisfy.\n "
3229+
},
31403230
"role": {
31413231
"$ref": "#/$defs/OptionalStr",
31423232
"default": null,
@@ -3262,6 +3352,11 @@
32623352
"default": null,
32633353
"description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n "
32643354
},
3355+
"requirements": {
3356+
"$ref": "#/$defs/RequirementsType",
3357+
"default": [],
3358+
"description": "Specify any requirements that the result of the block must satisfy.\n "
3359+
},
32653360
"role": {
32663361
"$ref": "#/$defs/OptionalStr",
32673362
"default": null,
@@ -3793,6 +3888,11 @@
37933888
"default": null,
37943889
"description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n "
37953890
},
3891+
"requirements": {
3892+
"$ref": "#/$defs/RequirementsType",
3893+
"default": [],
3894+
"description": "Specify any requirements that the result of the block must satisfy.\n "
3895+
},
37963896
"role": {
37973897
"$ref": "#/$defs/OptionalStr",
37983898
"default": null,
@@ -3947,6 +4047,11 @@
39474047
"default": null,
39484048
"description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n "
39494049
},
4050+
"requirements": {
4051+
"$ref": "#/$defs/RequirementsType",
4052+
"default": [],
4053+
"description": "Specify any requirements that the result of the block must satisfy.\n "
4054+
},
39504055
"role": {
39514056
"$ref": "#/$defs/OptionalStr",
39524057
"default": null,
@@ -4073,6 +4178,71 @@
40734178
"title": "RepeatBlock",
40744179
"type": "object"
40754180
},
4181+
"RequirementType": {
4182+
"additionalProperties": false,
4183+
"description": "Single requirement definition.",
4184+
"properties": {
4185+
"description": {
4186+
"anyOf": [
4187+
{
4188+
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
4189+
},
4190+
{},
4191+
{
4192+
"type": "string"
4193+
}
4194+
],
4195+
"title": "Description"
4196+
},
4197+
"evaluate": {
4198+
"anyOf": [
4199+
{
4200+
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
4201+
},
4202+
{
4203+
"$ref": "#/$defs/FunctionBlock"
4204+
},
4205+
{
4206+
"type": "string"
4207+
},
4208+
{
4209+
"type": "null"
4210+
}
4211+
],
4212+
"title": "Evaluate"
4213+
},
4214+
"transformContext": {
4215+
"anyOf": [
4216+
{
4217+
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
4218+
},
4219+
{
4220+
"$ref": "#/$defs/FunctionBlock"
4221+
},
4222+
{
4223+
"type": "string"
4224+
},
4225+
{
4226+
"type": "null"
4227+
}
4228+
],
4229+
"title": "Transformcontext"
4230+
}
4231+
},
4232+
"required": [
4233+
"description",
4234+
"evaluate",
4235+
"transformContext"
4236+
],
4237+
"title": "RequirementType",
4238+
"type": "object"
4239+
},
4240+
"RequirementsType": {
4241+
"items": {
4242+
"$ref": "#/$defs/RequirementType"
4243+
},
4244+
"type": "array"
4245+
},
40764246
"TextBlock": {
40774247
"additionalProperties": false,
40784248
"description": "Create the concatenation of the stringify version of the result of each block of the list of blocks.",
@@ -4129,6 +4299,11 @@
41294299
"default": null,
41304300
"description": "Whether to add the errors while retrying to the trace. Set this to true to use retry feature for multiple LLM trials.\n "
41314301
},
4302+
"requirements": {
4303+
"$ref": "#/$defs/RequirementsType",
4304+
"default": [],
4305+
"description": "Specify any requirements that the result of the block must satisfy.\n "
4306+
},
41324307
"role": {
41334308
"$ref": "#/$defs/OptionalStr",
41344309
"default": null,

0 commit comments

Comments
 (0)