Skip to content

fix(guardrails): drop the client evaluate_guardrail span in jobs - #1997

Open
daniel-joica wants to merge 4 commits into
mainfrom
fix/guardrail-duplicate-span-AL-712
Open

daniel-joica wants to merge 4 commits into
mainfrom
fix/guardrail-duplicate-span-AL-712

Conversation

@daniel-joica

@daniel-joica daniel-joica commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What changed?

Every guardrail evaluation produced two spans side by side in a job's trace:

  • evaluate_guardrail, created on the client by @traced on GuardrailsService.evaluate_guardrail. It holds only the method's input and output.
  • The Guardrails Service's own guardrailEvaluation span (e.g. PII Detection). It holds the configuration, the validation result, the details and the payload.

The goal is to keep only the service's span.

Changes:

  • In a job (UIPATH_JOB_KEY set), evaluate_guardrail no longer opens a client span. The service's span is the only evaluation span.
  • Locally (uipath run, uipath dev), the client span stays. The service's span never reaches a local trace, so without the client span a local run would show no evaluation at all. This is the same job-only rule fix: resolve OpenTelemetry tracing architecture issues #1197 in uipath-langchain uses for client LLM spans.
  • How: @traced decides whether to record when it's applied, not per call. So the public evaluate_guardrail now picks a traced or an untraced private path on each call. The request, the response handling and the public signature are unchanged, so callers need no changes: the uipath-langchain middlewares, the guardrail nodes and the @guardrail decorators.
  • Where the service's span sits: in a job it is now parented to the caller's span. In the LangChain path it already was, since it was a sibling of evaluate_guardrail under PII_Detection_before_model, so the trace just loses the duplicate.
  • Refactor (Sonar S3776): the validate call is split into helpers: _build_validate_payload, _build_validate_headers, _send_validate_request (including the 403 handling) and _to_validation_result. There is no behaviour change. Two except Exception: raise blocks that did nothing are removed, and the inline import json moves to the top of the file.

Versions:

  • uipath-platform 0.3.13.
  • The uv.lock files are refreshed.

How has this been tested?

  • New tests in TestEvaluateGuardrailSpan:
    • Job run: with a job key, only the caller's span is recorded, and the request's traceparent points at the caller. This test fails on main because of the extra evaluate_guardrail span.
    • Local run: with no job key, evaluate_guardrail is recorded under the caller.
  • uipath-platform full suite: 2304 passed, 11 skipped.
  • ruff check, ruff format --check and mypy are clean.
  • check_version_uniqueness.py and check_dependency_version_bumps.py pass, and uv lock --locked is current.
  • End to end: jobs of a LangChain agent with 7 guardrails, run on a local robot with this branch, show only the service's evaluation spans (PII Detection, Harmful Content Detection, ...) and no evaluate_guardrail. The same agent with the released uipath-platform still shows one evaluate_guardrail per check.

🤖 Generated with Claude Code

Development Packages

uipath-platform

[project]
dependencies = [
  # Exact version (copy-paste ready):
  "uipath-platform==0.3.13.dev1019978113",

  # Any version from this PR (uncomment to use a range instead):
  # "uipath-platform>=0.3.13.dev1019970000,<0.3.13.dev1019980000",
]

[[tool.uv.index]]
name = "testpypi"
url = "https://test.pypi.org/simple/"
publish-url = "https://test.pypi.org/legacy/"
explicit = true

[tool.uv.sources]
uipath-platform = { index = "testpypi" }

uipath

[project]
dependencies = [
  # Exact version (copy-paste ready):
  "uipath==2.15.5.dev1019978113",

  # Any version from this PR (uncomment to use a range instead):
  # "uipath>=2.15.5.dev1019970000,<2.15.5.dev1019980000",
]

[[tool.uv.index]]
name = "testpypi"
url = "https://test.pypi.org/simple/"
publish-url = "https://test.pypi.org/legacy/"
explicit = true

[tool.uv.sources]
uipath = { index = "testpypi" }
uipath-platform = { index = "testpypi" }

[tool.uv]
override-dependencies = ["uipath-platform==0.3.13.dev1019978113"]

…712]

In a job, the Guardrails Service publishes its own span for each evaluation
(e.g. "PII Detection"), so the client-side evaluate_guardrail span duplicated
it. Skip the client span when a job key is set; local runs keep it, since the
service span does not reach their trace.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 17, 2026 08:27
@daniel-joica daniel-joica added the build:dev Create a dev build from the pr label Nov 17, 2026
@github-actions github-actions Bot added test:uipath-langchain Triggers tests in the uipath-langchain-python repository test:uipath-integrations labels Nov 17, 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.

🟢 Approval recommended

No active review issues are recorded for the guardrail tracing change.

No open issues 🎉

What changed in this PR

This PR removes duplicate client-side guardrail evaluation spans from job traces while preserving local tracing in the UiPath Python SDK.

Changes:

  • Selects the traced or untraced evaluation path per call based on UIPATH_JOB_KEY, without changing the public API.
  • Adds tests for job span suppression, caller trace propagation, and local span retention.
  • Bumps uipath-platform to 0.3.8 and updates both lockfiles.
File Description
packages/​uipath/​uv.lock Updates the platform dependency version to 0.3.8.
packages/​uipath-platform/​uv.lock Synchronizes the platform package version to 0.3.8.
packages/​uipath-platform/​tests/​services/​test_guardrails_service.py Adds job and local tracing regression tests.
packages/​uipath-platform/​src/​uipath/​platform/​guardrails/​_guardrails_service.py Skips the client evaluation span in jobs while retaining it locally.
packages/​uipath-platform/​pyproject.toml Bumps the platform package version to 0.3.8.

Review effort: Balanced

Addresses Sonar findings on #1997: reduce the cognitive complexity of the
validate call by moving the payload, headers, request and result mapping into
their own helpers (no behaviour change), and split a composite test assertion.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

🟢 Approval recommended

No active review issues were identified for the guardrail evaluation tracing changes.

No open issues 🎉

Review effort: Balanced

@github-actions

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 →

@daniel-joica

daniel-joica commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author
  • Before (evaluate_guardrail client side span exists):
Screenshot 2026-11-17 at 11 56 22
  • After:
Screenshot 2026-11-17 at 10 48 32

…te-span-AL-712

# Conflicts:
#	packages/uipath-platform/pyproject.toml
#	packages/uipath-platform/src/uipath/platform/guardrails/_guardrails_service.py
#	packages/uipath-platform/uv.lock
#	packages/uipath/uv.lock
@daniel-joica daniel-joica changed the title fix(guardrails): drop the client evaluate_guardrail span in jobs [AL-712] fix(guardrails): drop the client evaluate_guardrail span in jobs Nov 20, 2026
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

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

Labels

build:dev Create a dev build from the pr 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