@@ -63,3 +63,37 @@ def check_model_structure(context: Context) -> None:
6363 assert (
6464 llm_model ["identifier" ] == f"{ expected_provider } /{ expected_model } "
6565 ), f"identifier should be '{ expected_provider } /{ expected_model } '"
66+
67+
68+ @then ("The body of the response has proper shield structure" )
69+ def check_shield_structure (context : Context ) -> None :
70+ """Check that the first shield has the correct structure and required fields."""
71+ response_json = context .response .json ()
72+ assert response_json is not None , "Response is not valid JSON"
73+
74+ assert "shields" in response_json , "Response missing 'shields' field"
75+ shields = response_json ["shields" ]
76+ assert len (shields ) > 0 , "Response has empty list of shields"
77+
78+ # Find first shield
79+ found_shield = None
80+ for shield in shields :
81+ if shield .get ("type" ) == "shield" :
82+ found_shield = shield
83+ break
84+
85+ assert found_shield is not None , "No shield found in response"
86+
87+ expected_model = context .default_model
88+
89+ # Validate structure and values
90+ assert found_shield ["type" ] == "shield" , "type should be 'shield'"
91+ assert (
92+ found_shield ["provider_id" ] == "llama-guard"
93+ ), "provider_id should be 'llama-guard'"
94+ assert (
95+ found_shield ["provider_resource_id" ] == expected_model
96+ ), f"provider_resource_id should be '{ expected_model } '"
97+ assert (
98+ found_shield ["identifier" ] == "llama-guard-shield"
99+ ), "identifier should be 'llama-guard-shield'"
0 commit comments