From d9789919ffa8520c4ab45f823cbe9a248f7dca92 Mon Sep 17 00:00:00 2001 From: Genmin Date: Thu, 30 Apr 2026 10:43:40 -0700 Subject: [PATCH] test: cover nested policy response models --- .../policy_engine/test_policy_endpoints.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/test_litellm/proxy/policy_engine/test_policy_endpoints.py b/tests/test_litellm/proxy/policy_engine/test_policy_endpoints.py index ee4051e866f..bbfc151b82e 100644 --- a/tests/test_litellm/proxy/policy_engine/test_policy_endpoints.py +++ b/tests/test_litellm/proxy/policy_engine/test_policy_endpoints.py @@ -2,6 +2,7 @@ import json import pytest from fastapi.encoders import jsonable_encoder +from pydantic import BaseModel from litellm.proxy.policy_engine.policy_endpoints import ( _dump_pipeline_result_for_response, @@ -19,6 +20,10 @@ class OpaqueSpan: return "opaque-span" +class NestedPolicyPayload(BaseModel): + value: str + + def test_pipeline_test_response_removes_internal_non_json_values(): opaque_span = OpaqueSpan() result = PipelineExecutionResult( @@ -58,3 +63,16 @@ def test_pipeline_test_response_removes_internal_non_json_values(): dumped["step_results"][0]["modified_data"]["non_internal_object"] == "opaque-span" ) + + +def test_pipeline_test_response_preserves_nested_pydantic_models(): + result = PipelineExecutionResult( + terminal_action="allow", + step_results=[], + modified_data={"nested": NestedPolicyPayload(value="kept")}, + ) + + dumped = _dump_pipeline_result_for_response(result) + + json.dumps(dumped) + assert dumped["modified_data"]["nested"] == {"value": "kept"}