|
32 | 32 | ) |
33 | 33 | from uipath.core.guardrails import ( |
34 | 34 | AllFieldsSelector, |
| 35 | + ApplyTo, |
35 | 36 | BooleanRule, |
36 | 37 | DeterministicGuardrail, |
37 | 38 | FieldSource, |
38 | 39 | GuardrailSelector, |
39 | 40 | NumberRule, |
| 41 | + UniversalRule, |
40 | 42 | WordRule, |
41 | 43 | ) |
42 | 44 |
|
@@ -818,6 +820,32 @@ def test_convert_boolean_rule(self) -> None: |
818 | 820 | assert result.detects_violation(True) is True |
819 | 821 | assert result.detects_violation(False) is False |
820 | 822 |
|
| 823 | + def test_convert_universal_rule_sets_rule_description(self) -> None: |
| 824 | + """UniversalRule should have rule_description set based on apply_to value.""" |
| 825 | + universal_rule = UniversalRule( |
| 826 | + rule_type="always", |
| 827 | + apply_to=ApplyTo.INPUT_AND_OUTPUT, |
| 828 | + ) |
| 829 | + # Create a minimal guardrail for testing |
| 830 | + guardrail = AgentCustomGuardrail.model_validate( |
| 831 | + { |
| 832 | + "$guardrailType": "custom", |
| 833 | + "id": "test-id", |
| 834 | + "name": "test-guardrail", |
| 835 | + "description": "Test", |
| 836 | + "enabledForEvals": True, |
| 837 | + "selector": {"$selectorType": "all"}, |
| 838 | + "rules": [], |
| 839 | + "action": {"$actionType": "block", "reason": "test"}, |
| 840 | + } |
| 841 | + ) |
| 842 | + result = _convert_agent_rule_to_deterministic(universal_rule, guardrail, []) |
| 843 | + |
| 844 | + assert isinstance(result, UniversalRule) |
| 845 | + assert ( |
| 846 | + result.rule_description == "Always enforce the guardrail on inputAndOutput" |
| 847 | + ) |
| 848 | + |
821 | 849 | def test_unsupported_rule_type_raises_value_error(self) -> None: |
822 | 850 | # Create a mock rule that's not a supported type |
823 | 851 | invalid_rule = cast(AgentWordRule, types.SimpleNamespace()) |
|
0 commit comments