From deb3ad0386fd6bf0254dcd0e2928995fff297a12 Mon Sep 17 00:00:00 2001 From: Andrei Petraru Date: Thu, 9 Jul 2026 16:52:55 +0300 Subject: [PATCH] docs: document LLM-as-judge guardrail validator [AL-469] Add an "LLM-as-judge" section to the core guardrails docs: a decorator example plus the guardrail_text/model/threshold/examples parameters and their limits. Include it in the Execution Stages table (PRE_AND_POST) and add an API Reference mkdocstrings block for LLMAsJudgeValidator. Co-Authored-By: Claude Opus 4.8 (1M context) --- packages/uipath/docs/core/guardrails.md | 41 ++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/packages/uipath/docs/core/guardrails.md b/packages/uipath/docs/core/guardrails.md index 4c380c20c..6a220bfe2 100644 --- a/packages/uipath/docs/core/guardrails.md +++ b/packages/uipath/docs/core/guardrails.md @@ -95,7 +95,7 @@ The `stage` parameter controls when the guardrail evaluates. Not all validators |-------|---------------|--------------| | `PRE` | Before the function runs | All validators | | `POST` | After the function runs | All except `UserPromptAttacksValidator` | -| `PRE_AND_POST` | Both before and after | `PIIValidator`, `HarmfulContentValidator`, `CustomValidator` | +| `PRE_AND_POST` | Both before and after | `PIIValidator`, `HarmfulContentValidator`, `LLMAsJudgeValidator`, `CustomValidator` | ## Built-in Validators @@ -208,6 +208,40 @@ def generate_code(spec: str) -> str: ... ``` +### LLM-as-judge + +Evaluates content against a rule written in plain language, using a judge LLM to decide whether the payload complies. Use it for policy checks that are hard to express as fixed entities or rules — tone, topicality, disclaimers, domain-specific policies. + +```python +from uipath.platform.guardrails import ( + BlockAction, + GuardrailExecutionStage, + LLMAsJudgeValidator, + guardrail, +) + +@guardrail( + validator=LLMAsJudgeValidator( + guardrail_text=( + "The response must remain professional and must not contain " + "financial or investment advice." + ), + model="gpt-4o-2024-08-06", + threshold=2, + ), + action=BlockAction(), + name="No financial advice", + stage=GuardrailExecutionStage.POST, +) +def answer_question(question: str) -> str: + ... +``` + +- `guardrail_text` (required) — the rule the judge evaluates against, at most 4000 characters. +- `model` (required) — the judge model id, e.g. `"gpt-4o-2024-08-06"`. It must be a model your organization's governance policy allows for the LLM-as-judge guardrail — LLM Gateway enforces the permitted list, so a model that isn't authorized for judging is rejected. +- `threshold` — strictness from `0` (strictest) to `6` (most lenient), defaulting to `2`. Higher values flag only clear violations. +- `positive_examples` / `negative_examples` — optional example payloads (not descriptions) that comply with / violate the rule, used to calibrate the judge. At most 2 entries per list, each at most 1000 characters. + ## Actions Actions define what happens when a violation is detected. @@ -433,6 +467,11 @@ print(result.result, result.reason) members: - IntellectualPropertyValidator +::: uipath.platform.guardrails.decorators.validators.llm_as_judge + options: + members: + - LLMAsJudgeValidator + ::: uipath.platform.guardrails.decorators.validators.user_prompt_attacks options: members: