-
Notifications
You must be signed in to change notification settings - Fork 29
Add integration tests for agent with guardrails #378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
apetraru-uipath
wants to merge
1
commit into
main
Choose a base branch
from
chore/tests_for_guardrails
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"] | ||
| }, | ||
| "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": [] | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:

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