From 3f93052e4455bdd9c63f0d009b5c671c7e9a2987 Mon Sep 17 00:00:00 2001 From: iliescucristian Date: Fri, 3 Apr 2026 18:26:37 +0300 Subject: [PATCH] fix: match guardrail tools by display_name in addition to tool name When matching tools for deterministic guardrails, also check the tool's metadata display_name field. This fixes cases where the guardrail match_names reference the display name rather than the internal tool name. Co-Authored-By: Claude Opus 4.6 (1M context) --- pyproject.toml | 2 +- .../agent/guardrails/guardrails_factory.py | 12 +++++++++++- tests/agent/guardrails/test_guardrails_factory.py | 1 + uv.lock | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7bbe49a4f..a2b5b2a3c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "uipath-langchain" -version = "0.9.18" +version = "0.9.19" description = "Python SDK that enables developers to build and deploy LangGraph agents to the UiPath Cloud Platform" readme = { file = "README.md", content-type = "text/markdown" } requires-python = ">=3.11" diff --git a/src/uipath_langchain/agent/guardrails/guardrails_factory.py b/src/uipath_langchain/agent/guardrails/guardrails_factory.py index d86a8582c..35e4cbe27 100644 --- a/src/uipath_langchain/agent/guardrails/guardrails_factory.py +++ b/src/uipath_langchain/agent/guardrails/guardrails_factory.py @@ -315,8 +315,18 @@ def _compute_field_sources_for_guardrail( # Deterministic guardrails have one single tool if guardrail.selector.match_names and len(guardrail.selector.match_names) > 0: + match_name = guardrail.selector.match_names[0] matching_tool = next( - (t for t in tools if t.name == guardrail.selector.match_names[0]), None + ( + t + for t in tools + if t.name == match_name + or ( + isinstance(t.metadata, dict) + and t.metadata.get("display_name") == match_name + ) + ), + None, ) if matching_tool: diff --git a/tests/agent/guardrails/test_guardrails_factory.py b/tests/agent/guardrails/test_guardrails_factory.py index a163655db..87e42dd3c 100644 --- a/tests/agent/guardrails/test_guardrails_factory.py +++ b/tests/agent/guardrails/test_guardrails_factory.py @@ -1179,6 +1179,7 @@ def test_convert_with_nonexistent_tool_raises_error(self) -> None: mock_tool = Mock(spec=BaseTool) mock_tool.name = "different_tool" + mock_tool.metadata = None agent_guardrail = AgentCustomGuardrail.model_validate( { diff --git a/uv.lock b/uv.lock index 315263d0b..f6635b9cf 100644 --- a/uv.lock +++ b/uv.lock @@ -3420,7 +3420,7 @@ wheels = [ [[package]] name = "uipath-langchain" -version = "0.9.18" +version = "0.9.19" source = { editable = "." } dependencies = [ { name = "httpx" },