Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions tests/cli/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
from unittest.mock import patch

import pytest
from uipath.core.guardrails import GuardrailValidationResult


@pytest.fixture
def mock_env_vars():
return {
"UIPATH_URL": "http://example.com",
"UIPATH_ACCESS_TOKEN": "***",
"UIPATH_TENANT_ID": "test-tenant-id",
}


@pytest.fixture
def mock_guardrails_service():
"""Mock the guardrails service to avoid HTTP errors in tests."""

def mock_evaluate_guardrail(text, guardrail):
"""Mock guardrail evaluation - always passes validation."""
return GuardrailValidationResult(validation_passed=True, reason="")

with patch(
"uipath.platform.guardrails.GuardrailsService.evaluate_guardrail",
side_effect=mock_evaluate_guardrail,
) as mock:
yield mock
8 changes: 8 additions & 0 deletions tests/cli/mocks/joke_agent_langgraph.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"dependencies": ["."],
"graphs": {
"agent": "./joke_agent_with_guardrails.py:graph"
},
"env": ".env"
}

139 changes: 139 additions & 0 deletions tests/cli/mocks/joke_agent_uipath.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{
"entryPoints": [
{
"filePath": "agent",
"uniqueId": "0afddb15-cecc-4a20-87ef-c1a65a690fcb",
"type": "agent",
"input": {
"type": "object",
"properties": {
"word": {
"type": "string",
"description": "The word to base the joke on"
}
},
"required": ["word"]
},
"output": {
"type": "object",
"properties": {
"joke": {
"type": "string",
"description": "The generated family-friendly joke"
},
"randomName": {
"type": "string",
"description": "A randomly generated name"
},
"analysis": {
"type": "string",
"description": "The analysis result from the SentenceAnalyzer tool"
},
"explanation": {
"type": "string",
"description": "An explanation if a joke couldn't be generated"
}
},
"required": ["joke", "randomName", "analysis"]
}
}
],
"bindings": {
"version": "2.0",
"resources": [],
"guardrails": [
{
"$guardrailType": "custom",
"id": "0dac2299-a8ae-43aa-8703-3eb93c657b2a",
"name": "Guardrail on input for donkey",
"description": "Filters out the word 'donkey' from tool inputs",
"enabledForEvals": true,
"selector": {
"scopes": ["Tool"],
"matchNames": ["Agent _ Sentence Analyzer"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the correct tool name? with spaces?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've downloaded the uis archive and in agent.json the tool names are always with spaces:
Screenshot 2025-12-29 at 15 18 18

We can double check, I know that I had to change the input files agent.json to have tools original names.

},
"rules": [
{
"$ruleType": "word",
"fieldSelector": {
"$selectorType": "specific",
"fields": [
{
"path": "sentence",
"source": "input"
}
]
},
"operator": "contains",
"value": "donkey"
}
],
"action": {
"$actionType": "filter",
"fields": [
{
"path": "sentence",
"source": "input"
}
]
}
},
{
"$guardrailType": "builtInValidator",
"id": "3b4d5416-202a-47ab-bba6-89fa8940a5cf",
"name": "PII detection guardrail",
"description": "This validator is designed to detect personally identifiable information",
"validatorType": "pii_detection",
"validatorParameters": [
{
"$parameterType": "enum-list",
"id": "entities",
"value": ["Email", "Address", "Person"]
},
{
"$parameterType": "map-enum",
"id": "entityThresholds",
"value": {
"Email": 0.5,
"Address": 0.5,
"Person": 0.5
}
}
],
"action": {
"$actionType": "block",
"reason": "PII detected"
},
"enabledForEvals": true,
"selector": {
"scopes": ["Agent", "Llm"],
"matchNames": []
}
},
{
"$guardrailType": "builtInValidator",
"id": "255b1220-97f8-4d79-be8e-052a664b2b90",
"name": "Prompt injection guardrail",
"description": "This validator is built to detect malicious attack attempts",
"validatorType": "prompt_injection",
"validatorParameters": [
{
"$parameterType": "number",
"id": "threshold",
"value": 0.5
}
],
"action": {
"$actionType": "block",
"reason": "Prompt Injection detected"
},
"enabledForEvals": true,
"selector": {
"scopes": ["Llm"],
"matchNames": []
}
}
]
}
}

Loading