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/guardrails.md
+44-1Lines changed: 44 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,6 +45,7 @@ from uipath_langchain.guardrails import (
45
45
UiPathDeterministicGuardrailMiddleware,
46
46
UiPathHarmfulContentMiddleware,
47
47
UiPathIntellectualPropertyMiddleware,
48
+
UiPathLLMAsJudgeMiddleware,
48
49
UiPathPIIDetectionMiddleware,
49
50
UiPathUserPromptAttacksMiddleware,
50
51
PIIDetectionEntity,
@@ -67,9 +68,10 @@ from uipath.core.guardrails import GuardrailScope
67
68
|`UiPathHarmfulContentMiddleware`| AGENT, LLM, TOOL | PRE / POST / PRE_AND_POST |`entities`, `tools`, `stage`|
68
69
|`UiPathUserPromptAttacksMiddleware`| LLM only | PRE only | — |
69
70
|`UiPathIntellectualPropertyMiddleware`| AGENT, LLM only | POST only |`entities`|
71
+
|`UiPathLLMAsJudgeMiddleware`| AGENT, LLM, TOOL | PRE / POST / PRE_AND_POST |`guardrail_text`, `model`, `threshold`, `positive_examples`, `negative_examples`, `tools`, `stage`|
70
72
|`UiPathDeterministicGuardrailMiddleware`| TOOL only | PRE / POST / PRE_AND_POST |`tools`, `rules`, `stage`|
71
73
72
-
TOOL scope for `UiPathPIIDetectionMiddleware`and `UiPathHarmfulContentMiddleware` requires passing `tools=[...]` to restrict `wrap_tool_call` hooks to specific tools.
74
+
TOOL scope for `UiPathPIIDetectionMiddleware`, `UiPathHarmfulContentMiddleware`, and `UiPathLLMAsJudgeMiddleware` requires passing `tools=[...]` to restrict `wrap_tool_call` hooks to specific tools.
73
75
74
76
All classes share these common parameters:
75
77
@@ -83,6 +85,7 @@ Additional parameters per class:
83
85
-**`UiPathPIIDetectionMiddleware`** / **`UiPathHarmfulContentMiddleware`**: `entities` (list of entity configs), `tools` (restrict TOOL-scope hooks to specific tools), `stage`.
84
86
-**`UiPathUserPromptAttacksMiddleware`**: no extra parameters.
85
87
-**`UiPathIntellectualPropertyMiddleware`**: `entities` (list of `IntellectualPropertyEntityType` values).
88
+
-**`UiPathLLMAsJudgeMiddleware`**: `guardrail_text` (required — the plain-language rule the judge evaluates against, ≤ 4000 chars), `model` (required — judge model id, e.g. `"gpt-4o-2024-08-06"`; must be a model your governance policy allows for the LLM-as-judge guardrail — LLM Gateway enforces the permitted list), `threshold` (`0` strictest … `6` most lenient, default `2`), `positive_examples` / `negative_examples` (optional calibration payloads — ≤ 2 each, ≤ 1000 chars each), `tools` (required only when `GuardrailScope.TOOL` is used), `stage`. See the [core guardrails documentation](https://uipath.github.io/uipath-python/core/guardrails/#llm-as-judge) for the full parameter reference.
86
89
-**`UiPathDeterministicGuardrailMiddleware`**: `tools` (required — list of tools to guard), `rules` (list of lambda functions), `stage`.
87
90
88
91
### Full example
@@ -98,6 +101,7 @@ from uipath_langchain.guardrails import (
# LLM-as-judge: block responses that violate a plain-language rule (POST)
176
+
*UiPathLLMAsJudgeMiddleware(
177
+
name="No financial advice",
178
+
scopes=[GuardrailScope.AGENT],
179
+
action=BlockAction(),
180
+
guardrail_text=(
181
+
"The response must remain professional and must not contain "
182
+
"financial or investment advice."
183
+
),
184
+
model="gpt-4o-2024-08-06",
185
+
stage=GuardrailExecutionStage.POST,
186
+
),
171
187
# Deterministic: block tool input longer than 1000 chars
172
188
*UiPathDeterministicGuardrailMiddleware(
173
189
tools=[analyze_text],
@@ -391,6 +407,33 @@ def create_my_agent():
391
407
agent = create_my_agent()
392
408
```
393
409
410
+
### LLM-as-judge
411
+
412
+
Use `LLMAsJudgeValidator` to check content against a plain-language rule via a judge LLM. Scope is inferred from the decorated target (here, the agent factory → AGENT scope). See the [core guardrails documentation](https://uipath.github.io/uipath-python/core/guardrails/#llm-as-judge) for the full parameter reference (`threshold`, `positive_examples`, `negative_examples`, and their limits).
413
+
414
+
```python
415
+
from langchain.agents import create_agent
416
+
from uipath_langchain.guardrails import guardrail, LLMAsJudgeValidator, BlockAction, GuardrailExecutionStage
417
+
418
+
@guardrail(
419
+
validator=LLMAsJudgeValidator(
420
+
guardrail_text=(
421
+
"The response must remain professional and must not contain "
0 commit comments