Skip to content

feat(guardrails): let the runtime choose where guardrail check containers go - #1267

Open
daniel-joica wants to merge 1 commit into
mainfrom
feat/guardrail-parent-resolver
Open

daniel-joica wants to merge 1 commit into
mainfrom
feat/guardrail-parent-resolver

Conversation

@daniel-joica

Copy link
Copy Markdown
Contributor

Summary

Lets the runtime choose where a middleware guardrail check's trace container goes.

  • register_guardrail_parent_resolver registers a GuardrailParentResolver that, given the scope, stage, component and call id, returns the span the container should open under. With no resolver registered, placement is unchanged.
  • Containers opened under a span that has already ended are deferred and closed with close_deferred_guardrail_containers / close_guardrail_container_under, so parallel calls and resumed runs keep their checks under the right model or tool call.
  • Tool-scope stages pass the tool name and the tool call id to guardrail_stage.
  • Version bumped to 0.21.12.

Coded agents don't change unless a resolver is registered; uipath-agents registers one in its trace PR.

Split out of #1260 as a pure move, with no behaviour change.

Testing

  • TestParentResolver covers resolved placement, deferred containers and closing them.
  • tests/guardrails passes (532); ruff and mypy are clean.

🤖 Generated with Claude Code

…ners go

Add a registrable parent resolver so a runtime can place guardrail check
containers under the right model or tool call span, including parallel
tool calls and resumed runs. Tool-scope stages now pass the tool name and
call id. Coded agents are unchanged unless a resolver is registered.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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.

🟡 Changes recommended

Already-closed guardrail containers remain in deferred tracking, allowing later flushes or shutdown to end their spans again and trigger SDK warnings.

1 open issue
What changed in this PR

Adds runtime-controlled placement of middleware guardrail trace containers, preserving default placement when no resolver is registered.

Changes:

  • Adds parent resolution and deferred-container closing APIs.
  • Passes tool names and call IDs to guardrail stages.
  • Adds resolver tests and bumps the version to 0.21.12.
File Description
uv.lock Updates the locked package version.
tests/​guardrails/​middlewares/​test_grouping.py Tests resolved placement, fallback, and deferred closure.
src/​uipath_langchain/​guardrails/​middlewares/​_grouping.py Adds parent resolution and deferred-container lifecycle handling.
src/​uipath_langchain/​guardrails/​middlewares/​_base.py Supplies tool identity to guardrail stages.
pyproject.toml Bumps the package version to 0.21.12.

Review effort: Balanced

Comment on lines +157 to +158
for container in waiting:
container.end(container.last_check_end or None)
@sonarqubecloud

sonarqubecloud Bot commented Dec 3, 2026

Copy link
Copy Markdown

_parent_resolver: GuardrailParentResolver | None = None


def register_guardrail_parent_resolver(

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.

Make this API public before uipath-agents depends on it

UiPath/uipath-agents-python#935 imports register_guardrail_parent_resolver, close_deferred_guardrail_containers and close_guardrail_container_under from this private module: in the runtime factory at import time (factory.py:43-46), and in its guardrail, LLM and tool instrumentors. A rename here passes this repo's CI, and then every agent in uipath-agents fails to start, advanced or not.

Export them from a public module, and add a test that pins their names and signatures, so a breaking change shows up here first.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants