@@ -1366,3 +1366,59 @@ async def mock_streaming_response():
1366
1366
1367
1367
except Exception as e :
1368
1368
pytest .fail (f"Should not raise exception when disable_exception_on_block=True in streaming, but got: { e } " )
1369
+
1370
+ @pytest .mark .asyncio
1371
+ async def test_bedrock_guardrail_post_call_success_hook_no_output_text ():
1372
+ """Test that async_post_call_success_hook skips when there's no output text"""
1373
+ from unittest .mock import AsyncMock , MagicMock , patch
1374
+ from litellm .proxy ._types import UserAPIKeyAuth
1375
+ from litellm .types .utils import ModelResponseStream
1376
+ import litellm
1377
+
1378
+ # Create proper mock objects
1379
+ mock_user_api_key_dict = UserAPIKeyAuth ()
1380
+
1381
+ # Create guardrail instance
1382
+ guardrail = BedrockGuardrail (
1383
+ guardrailIdentifier = "test-guardrail" ,
1384
+ guardrailVersion = "DRAFT"
1385
+ )
1386
+
1387
+ # Mock Bedrock API with no output text
1388
+ mock_bedrock_response = MagicMock ()
1389
+ mock_bedrock_response .status_code = 200
1390
+ mock_bedrock_response .json .return_value = {
1391
+ "output" : {
1392
+ "message" : {
1393
+ "role" : "assistant" ,
1394
+ "content" : [
1395
+ {
1396
+ "toolUse" : {
1397
+ "toolUseId" : "tooluse_kZJMlvQmRJ6eAyJE5GIl7Q" ,
1398
+ "name" : "top_song" ,
1399
+ "input" : {
1400
+ "sign" : "WZPZ"
1401
+ }
1402
+ }
1403
+ }
1404
+ ]
1405
+ }
1406
+ },
1407
+ "stopReason" : "tool_use"
1408
+ }
1409
+
1410
+ data = {
1411
+ "model" : "gpt-4o" ,
1412
+ "messages" : [
1413
+ {"role" : "user" , "content" : "Hello" },
1414
+ ],
1415
+ }
1416
+ mock_user_api_key_dict = UserAPIKeyAuth ()
1417
+
1418
+ return await guardrail .async_post_call_success_hook (
1419
+ data = data ,
1420
+ response = mock_bedrock_response ,
1421
+ user_api_key_dict = mock_user_api_key_dict ,
1422
+ )
1423
+ # If no error is raised, then the test passes
1424
+ print ("✅ No output text in response test passed" )
0 commit comments