Skip to content

feat: add UiPathByoGuardrailMiddleware (BYOG) [AL-512] - #1013

Merged
apetraru-uipath merged 1 commit into
mainfrom
feat/byog-middleware
Jul 30, 2026
Merged

feat: add UiPathByoGuardrailMiddleware (BYOG) [AL-512]#1013
apetraru-uipath merged 1 commit into
mainfrom
feat/byog-middleware

Conversation

@apetraru-uipath

@apetraru-uipath apetraru-uipath commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

What changed?

Adds Bring Your Own Guardrail (BYOG) support for coded agents — middleware flavor.

New middleware

  • UiPathByoGuardrailMiddleware (src/uipath_langchain/guardrails/middlewares/byo.py): runs a customer-managed validator (a cloud content-safety subscription, a vendor validation service, or a custom Integration Service connector) configured under Admin → AI Trust Layer → Guardrails Configurations. References the configuration by validator_name (byoValidatorName) + recommended connection_id, and builds a builtInValidator guardrail with validator_type="byo" — reusing the shared BuiltInGuardrailMiddlewareMixin hook wiring unchanged (scopes × stage, tool match_names, asyncio.to_thread offload, exception routing). No changes to the mixin itself.
  • validator_parameters is an optional passthrough of raw ValidatorParameter values, because BYO parameter schemas are defined by the connector. Scopes and stages are developer-supplied: BYOG validators are not scope- or stage-restricted, so all three scopes and both stages are available exactly as for the built-in validators.
  • Exports from uipath_langchain.guardrails and .middlewares.

Small refactor across existing middlewares (review feedback)

  • Extracted BUILT_IN_VALIDATOR_GUARDRAIL_TYPE in middlewares/_base.py and used it in all 7 built-in middlewares in place of the repeated "builtInValidator" literal. It is typed Literal["builtInValidator"] because GuardrailType.BUILT_IN_VALIDATOR.value is typed str and does not satisfy the model's Literal field under mypy.

Docs & sample

  • docs/guardrails.md: new "Bring Your Own Guardrail (BYOG)" section (admin prerequisite, config lookup, error semantics) plus a "Tuning a BYOG validator" subsection covering validator_parameters.
  • New starter sample samples/joke-agent-bring-your-own-guardrail/ — joke agent guarded on AGENT (PRE+POST) and TOOL (PRE) scopes, bindings.json declaring the IS connection for per-environment rebinding, and a README covering setup, tuning and expected outcomes. All identifiers are placeholders (my-harmful-content-guardrail, my-byog-guardrail-connection, public uipath-azure-contentsafety-guardrails connector key), following the bring-your-own-model sample convention; the Azure Content Safety parameter example ships commented out so the sample stays vendor-neutral.

Review feedback addressed (@valentinabojan)

  • Discovery via the CLI, not the API. uip agent guardrails list replaces the raw GET agents_/api/designer/byog-guardrails?includeConnectionDetails=true everywhere (docs, sample README, sample graph.py). BYOG configurations are listed alongside the built-in validators, which the docs now call out so the duplicate validator type is not confusing.
  • Parameters discovery via the same command. The validator_parameters guidance now points at the entry's Parameters array and names the fields you read from it (Id, Type, Required, DefaultValue, Options, KeySource, Min, Max, Step) instead of "your configuration's validator definition". This also replaced a guess: the previous text said omitting the argument uses "whatever the connector applies by default, which may be its strictest setting" — the definition reports a concrete DefaultValue, so the docs now say that.
  • Scopes/stages claim corrected. The PR previously stated that the connector declares which scopes/stages a validator supports and that an unsupported one surfaces as PROVIDER_ERROR. That was wrong. Removed from docs/guardrails.md, the sample README, and the UiPathByoGuardrailMiddleware docstring, and replaced with the correct behaviour — the developer chooses. The list output confirms it: the BYO-backed harmful_content entry returns AllowedScopes: [Agent, Llm, Tool] with PreExecution+PostExecution on all three.
  • Removed the "decorator flavor ships separately" note from the docs and sample README (release sequencing), and softened the neighbouring feature-flag mention to "BYOG not enabled for the tenant".

⚠️ Depends on a CLI follow-up. The discovery instructions assume the BYOG entries in uip agent guardrails list carry the configuration's own validator name and its connection id. Today's output shows "Validator": "harmful_content" (the validator type) and no connection id, so until that CLI change lands, take both values from Admin → AI Trust Layer → Guardrails Configurations.

Release

The decorator flavor is independent and ships separately: ByoValidator in UiPath/uipath-python#1833 and its LangChain wiring in #1014.

How has this been tested?

  • tests/guardrails/middlewares/test_byo.py26 new unit tests: guardrail construction (byo sentinel, byoValidatorName/byoConnectionId alias serialization, parameter passthrough, defaults), constructor validation errors, hook wiring parity (scopes × stage → before_*/after_*/wrap_tool_call), and the evaluation path (BYO fields reach evaluate_guardrail; BlockAction raises on VALIDATION_FAILED). Wire-payload coverage already exists in uipath-python's test_guardrails_service.py, so it is not duplicated here.

  • Full suite green; ruff check, ruff format --check, mypy clean; uv lock --check clean. Every python fence in the BYOG docs section is compile-checked and its imports verified to resolve (the middleware constructs from the documented snippet).

  • Live E2E on alpha (AdminStudioTest) against a real BYOG harmful-content configuration backed by a customer Azure Content Safety connector with fallbackOnUiPath=false, via uipath run on the new sample. Three guardrails/validate calls per run, matching the sample's two registrations (agent PRE, tool PRE, agent POST):

    • benign topic → PASSED → joke returned ✅
    • harmful topic → blocked at BYOG_Harmful_Content_before_agent, before the LLM is called, with the vendor verdict "Harmful content detected: Violence (severity 4)"
  • validator_parameters verified across three threshold settings on the same prompts, confirming the connector honours the values rather than merely accepting them:

    per-category threshold low-severity topic (2) high-severity topic (4)
    omitted blocked blocked
    4 passes blocked
    6 passes passes

Note: since the committed sample now carries placeholder identifiers, running it requires substituting your own configuration's validator name and connection id (same as the bring-your-own-model sample).

Are there any breaking changes?

  • Under Feature Flag
  • None
  • DB migrations
  • API removals

Purely additive: one new exported middleware class, one new internal constant, plus docs/sample. The BUILT_IN_VALIDATOR_GUARDRAIL_TYPE refactor is behaviour-preserving (same string value, now typed). Server-side, BYOG evaluation availability is controlled by the tenant's AI Trust Layer configuration.

🤖 Generated with Claude Code

Comment thread samples/joke-agent-bring-your-own-guardrail/graph.py
Comment thread samples/joke-agent-byog/README.md Outdated
Comment thread samples/joke-agent-byog/README.md Outdated
Comment thread src/uipath_langchain/guardrails/middlewares/byo.py Outdated
Copilot AI review requested due to automatic review settings July 29, 2026 09:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds “Bring Your Own Guardrail (BYOG)” support to uipath-langchain guardrails via a new middleware (UiPathByoGuardrailMiddleware) that references an admin-defined BYOG configuration (validator name + optional connection id) and evaluates it through the existing built-in middleware wiring.

Changes:

  • Introduces UiPathByoGuardrailMiddleware and exports it from the guardrails public API.
  • Refactors built-in guardrail middlewares to use a shared BUILT_IN_VALIDATOR_GUARDRAIL_TYPE constant (typed Literal) for guardrail_type.
  • Adds a full sample project and documentation section for BYOG, plus a dedicated unit test suite for the new middleware.

Reviewed changes

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

Show a summary per file
File Description
src/uipath_langchain/guardrails/middlewares/byo.py New BYOG middleware building a BuiltInValidatorGuardrail with validator_type="byo" and BYO reference fields.
tests/guardrails/middlewares/test_byo.py Unit tests covering construction, validation, hook wiring, and evaluation forwarding for BYOG middleware.
src/uipath_langchain/guardrails/middlewares/_base.py Adds BUILT_IN_VALIDATOR_GUARDRAIL_TYPE constant typed as Literal["builtInValidator"].
src/uipath_langchain/guardrails/middlewares/{harmful_content,pii_detection,llm_as_judge,intellectual_property,prompt_injection,user_prompt_attacks}.py Switches guardrail_type from a raw string literal to the shared constant.
src/uipath_langchain/guardrails/middlewares/__init__.py Exports UiPathByoGuardrailMiddleware.
src/uipath_langchain/guardrails/__init__.py Re-exports UiPathByoGuardrailMiddleware from the top-level guardrails package.
docs/guardrails.md Adds BYOG section + updates the middleware table and samples list.
samples/README.md Links the new BYOG sample.
samples/joke-agent-bring-your-own-guardrail/* New runnable sample project demonstrating BYOG middleware usage + bindings.

Comment thread docs/guardrails.md
Comment thread src/uipath_langchain/guardrails/middlewares/byo.py
apetraru-uipath added a commit that referenced this pull request Jul 29, 2026
…parameters

Bring the decorator-flavor sample and docs in line with the middleware PR
(#1013):

- Replace tenant-specific values with placeholders following the
  bring-your-own-model convention: validator name
  `my-harmful-content-guardrail`, connection `my-byog-guardrail-connection`,
  and the public `uipath-azure-contentsafety-guardrails` connector key in
  bindings.json.
- Document `ByoValidator(parameters=...)`: a "Tuning the validator" section in
  the sample README plus a commented-out Azure Content Safety
  `harmful_content` example in graph.py, stressing that parameter ids and
  types are defined by the guardrail connector rather than by this SDK.
- Drop the EnableByoGuardrails feature-flag prerequisite from user-facing docs
  (internal knowledge) and genericize vendor-specific wording.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
apetraru-uipath added a commit that referenced this pull request Jul 29, 2026
Decorator-flavor Bring Your Own Guardrail support, pairing with the
ByoValidator shipped in uipath (UiPath/uipath-python#1833):

- Re-export ByoValidator from uipath_langchain.guardrails and the
  .guardrails.decorators shim via a guarded getattr, so the package keeps
  importing (ByoValidator is None) on uipath releases that predate it.
  TODO in-code: switch to a direct import once the dependency floor
  includes it.
- Adapter hardening: the LLM/agent wrappers previously swallowed evaluator
  exceptions silently; they now log a WARNING with the guardrail name and
  traceback (still fail-open). This makes BYOG misconfiguration
  (PROVIDER_ERROR, removed/disabled config, feature flag off) visible.
- Tests: adapter error-logging tests (always run) + ByoValidator-through-
  @guardrail tests (tool / plain function / validator reuse) that skip
  automatically until the installed uipath ships ByoValidator; verified
  passing locally against the uipath-python ByoValidator branch.
- Docs: BYOG section under the decorator pattern in docs/guardrails.md,
  using placeholder validator/connection values and documenting the
  connector-defined `parameters` passthrough.
- Sample: samples/joke-agent-byog-decorator starter (agent-factory AGENT
  scope + tool TOOL scope, bindings.json connection binding), with a
  commented-out Azure Content Safety `parameters` example.

Bump to 0.14.18 (0.14.17 was taken by #1012 and is published on PyPI).

Independent of the middleware-flavor PR (#1013); branched from main.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
apetraru-uipath added a commit that referenced this pull request Jul 29, 2026
Decorator-flavor Bring Your Own Guardrail support, pairing with the
ByoValidator shipped in uipath (UiPath/uipath-python#1833):

- Re-export ByoValidator from uipath_langchain.guardrails and the
  .guardrails.decorators shim via a guarded getattr, so the package keeps
  importing (ByoValidator is None) on uipath releases that predate it.
  TODO in-code: switch to a direct import once the dependency floor
  includes it.
- Adapter hardening: the LLM/agent wrappers previously swallowed evaluator
  exceptions silently; they now log a WARNING with the guardrail name and
  traceback (still fail-open). This makes BYOG misconfiguration
  (PROVIDER_ERROR, removed/disabled config, feature flag off) visible.
- Tests: adapter error-logging tests (always run) + ByoValidator-through-
  @guardrail tests (tool / plain function / validator reuse) that skip
  automatically until the installed uipath ships ByoValidator; verified
  passing locally against the uipath-python ByoValidator branch.
- Docs: BYOG section under the decorator pattern in docs/guardrails.md,
  using placeholder validator/connection values and documenting the
  connector-defined `parameters` passthrough.
- Sample: samples/joke-agent-byog-decorator starter (agent-factory AGENT
  scope + tool TOOL scope, bindings.json connection binding), with a
  commented-out Azure Content Safety `parameters` example.
- Discovery: docs and sample point at `uip agent guardrails
  byo-configurations` (UiPath/cli#3298) rather than the raw
  agents_/api/designer/byog-guardrails endpoint, and note that the command
  needs an org-admin user session.

Bump to 0.14.18 (0.14.17 was taken by #1012 and is published on PyPI).

Independent of the middleware-flavor PR (#1013); branched from main.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Comment thread samples/joke-agent-bring-your-own-guardrail/graph.py Outdated
Comment thread samples/joke-agent-bring-your-own-guardrail/graph.py
Comment thread samples/joke-agent-bring-your-own-guardrail/README.md Outdated
Comment thread docs/guardrails.md Outdated
Comment thread docs/guardrails.md Outdated
Comment thread docs/guardrails.md Outdated
apetraru-uipath added a commit that referenced this pull request Jul 30, 2026
Decorator-flavor Bring Your Own Guardrail support, pairing with the
ByoValidator shipped in uipath (UiPath/uipath-python#1833):

- Re-export ByoValidator from uipath_langchain.guardrails and the
  .guardrails.decorators shim via a guarded getattr, so the package keeps
  importing (ByoValidator is None) on uipath releases that predate it.
  TODO in-code: switch to a direct import once the dependency floor
  includes it.
- Adapter hardening: the LLM/agent wrappers previously swallowed evaluator
  exceptions silently; they now log a WARNING with the guardrail name and
  traceback (still fail-open). This makes BYOG misconfiguration
  (PROVIDER_ERROR, removed/disabled config, BYOG not enabled) visible.
- Tests: adapter error-logging tests (always run) + ByoValidator-through-
  @guardrail tests (tool / plain function / validator reuse) that skip
  automatically until the installed uipath ships ByoValidator; verified
  passing locally against the uipath-python ByoValidator branch.
- Docs: BYOG section under the decorator pattern in docs/guardrails.md,
  using placeholder validator/connection values and documenting the
  connector-defined `parameters` passthrough.
- Sample: samples/joke-agent-byog-decorator starter (agent-factory AGENT
  scope + tool TOOL scope, bindings.json connection binding), with a
  commented-out Azure Content Safety `parameters` example.
- Discovery: docs and sample point at `uip agent guardrails list` for the
  validator name, connection id and the connector-defined `Parameters`
  schema, rather than the raw agents_/api/designer/byog-guardrails endpoint.
- Scopes/stages: BYOG validators are not scope- or stage-restricted, so the
  developer chooses; here the scope is inferred from each decorated target.

Bump to 0.14.18 (0.14.17 was taken by #1012 and is published on PyPI).

Independent of the middleware-flavor PR (#1013); branched from main.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
apetraru-uipath added a commit that referenced this pull request Jul 30, 2026
Decorator-flavor Bring Your Own Guardrail support, pairing with the
ByoValidator shipped in uipath (UiPath/uipath-python#1833):

- Re-export ByoValidator from uipath_langchain.guardrails and the
  .guardrails.decorators shim via a guarded getattr, so the package keeps
  importing (ByoValidator is None) on uipath releases that predate it.
  TODO in-code: switch to a direct import once the dependency floor
  includes it.
- Adapter hardening: the LLM/agent wrappers previously swallowed evaluator
  exceptions silently; they now log a WARNING with the guardrail name and
  traceback (still fail-open). This makes BYOG misconfiguration
  (PROVIDER_ERROR, removed/disabled config, BYOG not enabled) visible.
- Tests: adapter error-logging tests (always run) + ByoValidator-through-
  @guardrail tests (tool / plain function / validator reuse) that skip
  automatically until the installed uipath ships ByoValidator; verified
  passing locally against the uipath-python ByoValidator branch.
- Docs: BYOG section under the decorator pattern in docs/guardrails.md,
  using placeholder validator/connection values and documenting the
  connector-defined `parameters` passthrough.
- Sample: samples/joke-agent-byog-decorator starter (agent-factory AGENT
  scope + tool TOOL scope, bindings.json connection binding), with a
  commented-out Azure Content Safety `parameters` example.
- Discovery: docs and sample point at `uip agent guardrails list` for the
  validator name, connection id and the connector-defined `Parameters`
  schema, rather than the raw agents_/api/designer/byog-guardrails endpoint.
- Scopes/stages: BYOG validators are not scope- or stage-restricted, so the
  developer chooses; here the scope is inferred from each decorated target.

Bump to 0.14.19: 0.14.17 was taken by #1012 and is published on PyPI, and
0.14.18 belongs to the middleware flavor (#1013), which lands first.

Independent of the middleware-flavor PR (#1013); branched from main.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Add Bring Your Own Guardrail (BYOG) support so coded agents can run
customer-managed validators (a cloud content-safety subscription, a vendor
validation service, or a custom Integration Service connector) configured
under Admin -> AI Trust Layer -> Guardrails Configurations.

- UiPathByoGuardrailMiddleware references the admin configuration by
  validator name + IS connection id and builds a builtInValidator guardrail
  with validator_type="byo" (byoValidatorName/byoConnectionId), reusing the
  shared BuiltInGuardrailMiddlewareMixin hook wiring unchanged.
- validator_parameters is an optional passthrough of raw ValidatorParameter
  values. Scopes and stages are developer-supplied: BYOG validators are not
  scope- or stage-restricted, so all three scopes and both stages are
  available exactly as for the built-in validators.
- Extract BUILT_IN_VALIDATOR_GUARDRAIL_TYPE (Literal-typed, in
  middlewares/_base.py) and use it across all built-in middlewares in place
  of the repeated "builtInValidator" string.
- Docs: "Bring Your Own Guardrail (BYOG)" section in docs/guardrails.md plus
  a "Tuning a BYOG validator" subsection for validator_parameters.
- Sample: samples/joke-agent-bring-your-own-guardrail, guarding AGENT
  (PRE+POST) and TOOL (PRE) scopes, with bindings.json declaring the IS
  connection for per-environment rebinding. All identifiers are placeholders,
  following the bring-your-own-model convention; the Azure Content Safety
  parameter example ships commented out to keep the sample vendor-neutral.
- Discovery: docs and sample point at `uip agent guardrails list` for the
  validator name, connection id and the connector-defined `Parameters`
  schema, rather than the raw agents_/api/designer/byog-guardrails endpoint.
- Bump version to 0.14.18 and sync uv.lock (0.14.17 was taken by #1012 and
  is published on PyPI).

Verified live on alpha against a real BYOG harmful-content configuration:
benign input passes, harmful input blocks at before_agent with the vendor
verdict, and per-category severity thresholds are honoured (omitted blocks
any non-zero severity, 4 lets severity-2 through while blocking 4, 6 lets
both through).

The decorator flavor ships separately (uipath-python ByoValidator + #1014,
which follows at 0.14.19).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@apetraru-uipath
apetraru-uipath merged commit 7f4315f into main Jul 30, 2026
43 of 44 checks passed
@apetraru-uipath
apetraru-uipath deleted the feat/byog-middleware branch July 30, 2026 11:35
apetraru-uipath added a commit that referenced this pull request Jul 30, 2026
Decorator-flavor Bring Your Own Guardrail support, the counterpart to the
UiPathByoGuardrailMiddleware shipped in #1013.

- Re-export ByoValidator from uipath_langchain.guardrails and the
  .guardrails.decorators shim. `uipath-platform` is floored at >=0.2.14, the
  release that ships ByoValidator (UiPath/uipath-python#1833), so this is a
  plain import rather than a guarded getattr.
- Adapter hardening: the LLM/agent wrappers previously swallowed evaluator
  exceptions silently; they now log a WARNING with the guardrail name and
  traceback (still fail-open). This makes BYOG misconfiguration
  (PROVIDER_ERROR, removed/disabled config, BYOG not enabled) visible.
- Tests: adapter error-logging tests plus ByoValidator-through-@guardrail
  tests (tool / plain function / validator reuse), all running against the
  published uipath-platform - no conditional skips.
- Docs: BYOG section under the decorator pattern in docs/guardrails.md. The
  admin prerequisite, discovery command and parameter-schema lookup are
  cross-referenced to the middleware section instead of repeated; only the
  decorator-specific notes are spelled out.
- Sample: samples/joke-agent-byog-decorator (agent-factory AGENT scope +
  tool TOOL scope, bindings.json connection binding), with a commented-out
  Azure Content Safety `parameters` example. Cross-links the middleware
  sample as the sibling starter.
- Replace the leftover tenant-specific validator name and connection GUID
  with the placeholder values used elsewhere, in this PR's tests and in
  tests/guardrails/middlewares/test_byo.py from #1013.
- Bump to 0.14.19 (main is at 0.14.18, published on PyPI).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
apetraru-uipath added a commit that referenced this pull request Jul 30, 2026
Decorator-flavor Bring Your Own Guardrail support, the counterpart to the
UiPathByoGuardrailMiddleware shipped in #1013.

- Re-export ByoValidator from uipath_langchain.guardrails and the
  .guardrails.decorators shim. `uipath-platform` is floored at >=0.2.14, the
  release that ships ByoValidator (UiPath/uipath-python#1833), so this is a
  plain import rather than a guarded getattr.
- Adapter hardening: the LLM/agent wrappers previously swallowed evaluator
  exceptions silently; they now log a WARNING with the guardrail name and
  traceback (still fail-open), via a shared _EVALUATION_FAILED_MSG constant
  rather than repeating the format string at each of the four call sites.
  This makes BYOG misconfiguration (PROVIDER_ERROR, removed/disabled config,
  BYOG not enabled) visible.
- Tests: adapter error-logging tests plus ByoValidator-through-@guardrail
  tests (tool / plain function / validator reuse), all running against the
  published uipath-platform - no conditional skips.
- Docs: BYOG section under the decorator pattern in docs/guardrails.md. The
  admin prerequisite, discovery command and parameter-schema lookup are
  cross-referenced to the middleware section instead of repeated; only the
  decorator-specific notes are spelled out.
- Sample: samples/joke-agent-byog-decorator (agent-factory AGENT scope +
  tool TOOL scope, bindings.json connection binding), with a commented-out
  Azure Content Safety `parameters` example. Cross-links the middleware
  sample as the sibling starter.
- Replace the leftover tenant-specific validator name and connection GUID
  with the placeholder values used elsewhere, in this PR's tests and in
  tests/guardrails/middlewares/test_byo.py from #1013.
- Bump to 0.14.19 (main is at 0.14.18, published on PyPI).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
apetraru-uipath added a commit that referenced this pull request Jul 30, 2026
Decorator-flavor Bring Your Own Guardrail support, the counterpart to the
UiPathByoGuardrailMiddleware shipped in #1013.

- Re-export ByoValidator from uipath_langchain.guardrails and the
  .guardrails.decorators shim. `uipath-platform` is floored at >=0.2.14, the
  release that ships ByoValidator (UiPath/uipath-python#1833), so this is a
  plain import rather than a guarded getattr.
- Adapter hardening: the LLM/agent wrappers previously swallowed evaluator
  exceptions silently; they now log a WARNING with the guardrail name and
  traceback (still fail-open), via a shared _EVALUATION_FAILED_MSG constant.
  This makes BYOG misconfiguration (PROVIDER_ERROR, removed/disabled config,
  BYOG not enabled) visible.
- Tests: adapter error-logging tests plus ByoValidator-through-@guardrail
  tests (tool / plain function / validator reuse), all running against the
  published uipath-platform - no conditional skips.
- Sample: merge both flavors into samples/joke-agent-bring-your-own-guardrail
  as ONE agent guarded twice from the same BYOG configuration -- the
  middleware logs on AGENT scope (PRE_AND_POST, LogAction) while the
  decorator blocks on LLM scope (PRE, BlockAction on a create_llm factory),
  so a harmful topic is first logged and then blocked before the model is
  invoked. The separate joke-agent-byog-decorator sample is removed.
- Docs: BYOG section under the decorator pattern in docs/guardrails.md,
  cross-referencing the middleware section for the shared prerequisite and
  discovery steps. Discovery now uses `uip agent guardrails list --byo`,
  whose entries carry ByoValidatorName / ByoConnectionId / ByoConnectorKey
  and the connector-defined Parameters schema.
- Replace the leftover tenant-specific validator name and connection GUID
  with the placeholder values used elsewhere, in this PR's tests and in
  tests/guardrails/middlewares/test_byo.py from #1013.
- Bump to 0.14.19 (main is at 0.14.18, published on PyPI).

Verified live on alpha against a real BYOG harmful-content configuration:
benign topic evaluates on both flavors (agent PRE, LLM PRE per model call,
agent POST) and returns a joke; harmful topic is logged by the agent-scope
guardrail, then blocked by the LLM-scope guardrail before chat/completions,
with the vendor verdict "Harmful content detected: Violence (severity 4)".

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
apetraru-uipath added a commit that referenced this pull request Jul 30, 2026
Decorator-flavor Bring Your Own Guardrail support, the counterpart to the
UiPathByoGuardrailMiddleware shipped in #1013.

- Re-export ByoValidator from uipath_langchain.guardrails and the
  .guardrails.decorators shim. `uipath-platform` is floored at >=0.2.14, the
  release that ships ByoValidator (UiPath/uipath-python#1833), so this is a
  plain import rather than a guarded getattr.
- Adapter hardening: the LLM/agent wrappers previously swallowed evaluator
  exceptions silently; they now log a WARNING with the guardrail name and
  traceback (still fail-open), via a shared _EVALUATION_FAILED_MSG constant.
  This makes BYOG misconfiguration (PROVIDER_ERROR, removed/disabled config,
  BYOG not enabled) visible.
- Tests: adapter error-logging tests plus ByoValidator-through-@guardrail
  tests (tool / plain function / validator reuse), all running against the
  published uipath-platform - no conditional skips.
- Parity suite: new scenario 12 (test_byog_agent_block) runs for BOTH flavors
  and asserts they deliver the same byo wire contract to the service
  (validator_type="byo", byoValidatorName, byoConnectionId) and block
  identically on a failing verdict; both parity mock agents gain an
  "Agent BYOG Detection" guardrail (AGENT scope, PRE, BlockAction).
- Sample: merge both flavors into samples/joke-agent-bring-your-own-guardrail
  as ONE agent guarded twice from the same BYOG configuration -- the
  middleware logs on AGENT scope (PRE_AND_POST, LogAction) while the
  decorator blocks on LLM scope (PRE, BlockAction on a create_llm factory),
  so a harmful topic is first logged and then blocked before the model is
  invoked. The separate joke-agent-byog-decorator sample is removed.
- Docs: BYOG section under the decorator pattern in docs/guardrails.md,
  cross-referencing the middleware section for the shared prerequisite and
  discovery steps. Discovery now uses `uip agent guardrails list --byo`,
  whose entries carry ByoValidatorName / ByoConnectionId / ByoConnectorKey
  and the connector-defined Parameters schema.
- Replace the leftover tenant-specific validator name and connection GUID
  with the placeholder values used elsewhere, in this PR's tests and in
  tests/guardrails/middlewares/test_byo.py from #1013.
- Bump to 0.14.20 (0.14.19 was taken by #1008 and is published on PyPI).

Verified live on alpha against a real BYOG harmful-content configuration:
benign topic evaluates on both flavors (agent PRE, LLM PRE per model call,
agent POST) and returns a joke; harmful topic is logged by the agent-scope
guardrail, then blocked by the LLM-scope guardrail before chat/completions,
with the vendor verdict "Harmful content detected: Violence (severity 4)".

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
apetraru-uipath added a commit that referenced this pull request Jul 31, 2026
Decorator-flavor Bring Your Own Guardrail support, the counterpart to the
UiPathByoGuardrailMiddleware shipped in #1013.

- Re-export ByoValidator from uipath_langchain.guardrails and the
  .guardrails.decorators shim. `uipath-platform` is floored at >=0.2.14, the
  release that ships ByoValidator (UiPath/uipath-python#1833), so this is a
  plain import rather than a guarded getattr.
- Adapter hardening: the LLM/agent wrappers previously swallowed evaluator
  exceptions silently; they now log a WARNING with the guardrail name and
  traceback (still fail-open), via a shared _EVALUATION_FAILED_MSG constant.
  This makes BYOG misconfiguration (PROVIDER_ERROR, removed/disabled config,
  BYOG not enabled) visible.
- Tests: adapter error-logging tests plus ByoValidator-through-@guardrail
  tests (tool / plain function / validator reuse), all running against the
  published uipath-platform - no conditional skips.
- Parity suite: new scenario 12 (test_byog_agent_block) runs for BOTH flavors
  and asserts they deliver the same byo wire contract to the service
  (validator_type="byo", byoValidatorName, byoConnectionId) and block
  identically on a failing verdict; both parity mock agents gain an
  "Agent BYOG Detection" guardrail (AGENT scope, PRE, BlockAction).
- Sample: merge both flavors into samples/joke-agent-bring-your-own-guardrail
  as ONE agent guarded twice from the same BYOG configuration -- the
  middleware logs on AGENT scope (PRE_AND_POST, LogAction) while the
  decorator blocks on LLM scope (PRE, BlockAction on a create_llm factory),
  so a harmful topic is first logged and then blocked before the model is
  invoked. The separate joke-agent-byog-decorator sample is removed.
- No solution binding for the BYOG connection (review feedback): the
  connection is resolved server-side from the BYOG configuration, so the
  sample ships no bindings.json and the docs no longer point ByoConnectorKey
  at a connection binding.
- Docs: BYOG section under the decorator pattern in docs/guardrails.md,
  cross-referencing the middleware section for the shared prerequisite and
  discovery steps. Discovery uses `uip agent guardrails list --byo`, whose
  entries carry ByoValidatorName / ByoConnectionId and the connector-defined
  Parameters schema.
- Replace the leftover tenant-specific validator name and connection GUID
  with the placeholder values used elsewhere, in this PR's tests and in
  tests/guardrails/middlewares/test_byo.py from #1013.
- Bump to 0.14.20 (0.14.19 was taken by #1008 and is published on PyPI).

Verified live on alpha against a real BYOG harmful-content configuration:
benign topic evaluates on both flavors (agent PRE, LLM PRE per model call,
agent POST) and returns a joke; harmful topic is logged by the agent-scope
guardrail, then blocked by the LLM-scope guardrail before chat/completions,
with the vendor verdict "Harmful content detected: Violence (severity 4)".

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants