Skip to content

feat(guardrails): add LLMAsJudgeValidator for the @guardrail decorator [AL-470]#1802

Merged
apetraru-uipath merged 1 commit into
mainfrom
feat/AL-470-llm-as-judge-decorator
Jul 8, 2026
Merged

feat(guardrails): add LLMAsJudgeValidator for the @guardrail decorator [AL-470]#1802
apetraru-uipath merged 1 commit into
mainfrom
feat/AL-470-llm-as-judge-decorator

Conversation

@apetraru-uipath

Copy link
Copy Markdown
Contributor

What changed?

Adds LLMAsJudgeValidator — the llm_as_judge built-in validator for the @guardrail
decorator path. This closes the last coded-agent gap: low-code agents and the guardrail
middleware already support llm_as_judge; the decorator path did not.

  • LLMAsJudgeValidator(BuiltInGuardrailValidator) builds a BuiltInValidatorGuardrail with
    validator_type="llm_as_judge" and parameters guardrailText (text), model (enum),
    threshold (number, 0–6, default 2), plus optional positiveExamples / negativeExamples
    (text-list). The wire ids match the low-code catalog exactly.
  • No scope/action on the validator (those are @guardrail arguments); selector stays None
    (scope comes from the wrapped target); all stages supported.
  • Exported through validators/__init__.py, decorators/__init__.py, and
    platform/guardrails/__init__.py.

How has this been tested?

  • New tests/services/test_llm_as_judge_validator.py: validator_type, parameter ids/values,
    examples-only-when-present, selector is None, all-stages, and constructor validation.
  • tests/services/test_guardrails_decorators.py: decorator-level behavior — BlockAction
    raises GuardrailBlockException, LogAction continues, and a real-validator, mocked-backend
    case (patch("uipath.platform.UiPath", ...)).
  • ruff + mypy clean; full guardrails decorator + azure-validator suites pass.
  • Validated end-to-end via the joke-agent-decorator sample (separate uipath-langchain PR,
    AL-470): the @guardrail judge fires at POST and calls the real validate endpoint.

Are there any breaking changes?

  • None
  • Under Feature Flag
  • UiPath CLI Runtime changes

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings July 7, 2026 20:36
@github-actions github-actions Bot added test:uipath-langchain Triggers tests in the uipath-langchain-python repository test:uipath-integrations labels Jul 7, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new decorator-path built-in guardrail validator (LLMAsJudgeValidator) so @guardrail can use the llm_as_judge validator type (bringing the decorator path to feature parity with low-code agents and the middleware path).

Changes:

  • Introduces LLMAsJudgeValidator, which builds a BuiltInValidatorGuardrail with validator_type="llm_as_judge" and the expected parameter IDs/types.
  • Exports the validator through the guardrails decorator/validator public modules.
  • Adds focused unit tests for guardrail construction and decorator behavior (block/log actions + mocked backend).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/uipath-platform/tests/services/test_llm_as_judge_validator.py New unit tests validating guardrail construction, parameters, defaults, stage support, and input validation.
packages/uipath-platform/tests/services/test_guardrails_decorators.py Adds decorator-level behavior tests covering block/log actions and an end-to-end mocked API path.
packages/uipath-platform/src/uipath/platform/guardrails/decorators/validators/llm_as_judge.py Implements the new LLMAsJudgeValidator and its BuiltInValidatorGuardrail construction.
packages/uipath-platform/src/uipath/platform/guardrails/decorators/validators/init.py Re-exports LLMAsJudgeValidator from the validators package.
packages/uipath-platform/src/uipath/platform/guardrails/decorators/init.py Re-exports LLMAsJudgeValidator from the decorators public API.
packages/uipath-platform/src/uipath/platform/guardrails/init.py Re-exports LLMAsJudgeValidator from the top-level guardrails package API.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +16 to +17
# Threshold scale matches the backend OOTB catalog (0-6, step 2, default 2):
# HIGHER = more lenient (only flag clear violations), LOWER = stricter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 4f27bee — clarified the wording: threshold accepts any float in [0,6] (the catalog 'step 2' is a UI increment only, not enforced), and supported_stages is the default empty list meaning all stages are allowed. Documentation-only, no behavior change.

Comment on lines +28 to +29
any scope/stage the ``@guardrail`` decorator wraps (scope is implicit in the
decorated target; ``supported_stages`` is unset so both PRE and POST are allowed).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 4f27bee — reworded to: supported_stages is left as the default empty list, which means all stages are allowed (both PRE and POST). No behavior change.

@apetraru-uipath apetraru-uipath force-pushed the feat/AL-470-llm-as-judge-decorator branch from 4f27bee to 8bcd9f9 Compare July 7, 2026 20:50
@sonarqubecloud

sonarqubecloud Bot commented Jul 7, 2026

Copy link
Copy Markdown

❌ The last analysis has failed.

See analysis details on SonarQube Cloud

@apetraru-uipath apetraru-uipath force-pushed the feat/AL-470-llm-as-judge-decorator branch 2 times, most recently from fe9f1fb to abd92af Compare July 7, 2026 21:21
value=self.threshold,
),
]
if self.positive_examples:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add some validations to match the constraints we have for low coded agents?
Like max 2 positive and max 2 negative examples, and each example to have a max of 1000 chars?
Also the guardrail text to be at most 4000 chars?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added those constraints

…r [AL-470]

Adds an llm_as_judge built-in validator to the coded-agent decorator path,
closing the last gap (low-code and the guardrail middleware already support it).

- LLMAsJudgeValidator(BuiltInGuardrailValidator) builds a BuiltInValidatorGuardrail
  with validator_type="llm_as_judge" and parameters guardrailText (text), model
  (enum), threshold (number, 0-6, default 2), plus optional
  positiveExamples/negativeExamples (text-list). No scope/action on the validator
  (those are @guardrail args); selector stays None (scope comes from the wrapped
  target); all stages supported.
- Exported through validators/__init__, decorators/__init__, and
  platform/guardrails/__init__.
- Tests: construction/params/validation (test_llm_as_judge_validator.py) and
  decorator-level block/log behavior including a real-validator, mocked-backend
  case (test_guardrails_decorators.py).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@apetraru-uipath apetraru-uipath force-pushed the feat/AL-470-llm-as-judge-decorator branch from f4edfee to 713fe9c Compare July 8, 2026 07:57
@sonarqubecloud

sonarqubecloud Bot commented Jul 8, 2026

Copy link
Copy Markdown

@apetraru-uipath apetraru-uipath merged commit e1ceda5 into main Jul 8, 2026
165 checks passed
@apetraru-uipath apetraru-uipath deleted the feat/AL-470-llm-as-judge-decorator branch July 8, 2026 08:58
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

🚨 Heads up: uipath-langchain cross-tests are FAILING 🚨

Your changes may break the uipath-langchain-python integration.

⚠️ These checks are NOT enforced by branch protection rules. Please review the failures before merging.

🔍 Inspect the failed run →

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:uipath-integrations test:uipath-langchain Triggers tests in the uipath-langchain-python repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants