Skip to content

Commit 98e5ed9

Browse files
fix: address comments
1 parent 94eb397 commit 98e5ed9

1 file changed

Lines changed: 16 additions & 42 deletions

File tree

tests/agent/guardrails/test_guardrails_factory.py

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,27 @@ def test_escalate_action_is_mapped_with_app_and_recipient(self) -> None:
158158
assert action.version == 2
159159
assert action.assignee == "admin@example.com"
160160

161-
def test_deterministic_guardrail_with_llm_scope_raises_value_error(self) -> None:
162-
"""DeterministicGuardrails (AgentCustomGuardrails) with LLM scope should raise ValueError."""
161+
@pytest.mark.parametrize(
162+
"scope,scope_lower",
163+
[
164+
("Llm", "llm"),
165+
("Agent", "agent"),
166+
],
167+
)
168+
def test_deterministic_guardrail_with_invalid_scope_raises_value_error(
169+
self, scope: str, scope_lower: str
170+
) -> None:
171+
"""DeterministicGuardrails with LLM or AGENT scope should raise ValueError."""
163172
guardrail = AgentCustomGuardrail.model_validate(
164173
{
165174
"$guardrailType": "custom",
166-
"id": "test-llm-scope",
167-
"name": "test-guardrail-llm",
168-
"description": "Test guardrail with LLM scope",
175+
"id": f"test-{scope_lower}-scope",
176+
"name": f"test-guardrail-{scope_lower}",
177+
"description": f"Test guardrail with {scope} scope",
169178
"enabledForEvals": True,
170179
"selector": {
171180
"$selectorType": "scoped",
172-
"scopes": ["Llm"], # LLM scope - should be rejected
181+
"scopes": [scope], # Invalid scope - should be rejected
173182
"matchNames": None,
174183
},
175184
"rules": [
@@ -189,42 +198,7 @@ def test_deterministic_guardrail_with_llm_scope_raises_value_error(self) -> None
189198

190199
with pytest.raises(
191200
ValueError,
192-
match=r"Deterministic guardrail 'test-guardrail-llm' can only be used with TOOL scope.*Found invalid scopes.*LLM",
193-
):
194-
build_guardrails_with_actions([guardrail])
195-
196-
def test_deterministic_guardrail_with_agent_scope_raises_value_error(self) -> None:
197-
"""DeterministicGuardrails with AGENT scope should raise ValueError."""
198-
guardrail = AgentCustomGuardrail.model_validate(
199-
{
200-
"$guardrailType": "custom",
201-
"id": "test-agent-scope",
202-
"name": "test-guardrail-agent",
203-
"description": "Test guardrail with AGENT scope",
204-
"enabledForEvals": True,
205-
"selector": {
206-
"$selectorType": "scoped",
207-
"scopes": ["Agent"], # AGENT scope - should be rejected
208-
"matchNames": None,
209-
},
210-
"rules": [
211-
{
212-
"$ruleType": "word",
213-
"fieldSelector": {
214-
"$selectorType": "specific",
215-
"fields": [{"path": "message.content", "source": "input"}],
216-
},
217-
"operator": "contains",
218-
"value": "forbidden",
219-
}
220-
],
221-
"action": {"$actionType": "block", "reason": "test"},
222-
}
223-
)
224-
225-
with pytest.raises(
226-
ValueError,
227-
match=r"Deterministic guardrail 'test-guardrail-agent' can only be used with TOOL scope.*Found invalid scopes.*AGENT",
201+
match=rf"Deterministic guardrail 'test-guardrail-{scope_lower}' can only be used with TOOL scope.*Found invalid scopes.*{scope.upper()}",
228202
):
229203
build_guardrails_with_actions([guardrail])
230204

0 commit comments

Comments
 (0)