fix(proxy): merge only dict client metadata into pass-through logging

Backport adaptation for rc/1.105.0. main merges a pass-through caller's metadata and litellm_metadata into the logging metadata only when they are dicts. This line merged any value, so a list of pairs could carry standard_logging_guardrail_information past the guardrail strip from #59.
This commit is contained in:
mateo-berri 2026-10-08 09:26:37 -07:00 • committed by yucheng
parent 6566067117
commit fb0506db57

View file

@ -1416,6 +1416,32 @@ async def test_pass_through_request_strips_client_guardrail_information(allow_cl
assert hooked_body["metadata"] == {"trace_id": "keep-me"}
@pytest.mark.parametrize("metadata_key", ["litellm_metadata", "metadata"])
def test_pass_through_logging_ignores_client_guardrail_information_sent_as_pairs(metadata_key: str):
mock_request = MagicMock(spec=Request)
mock_request.method = "POST"
mock_request.url = httpx.URL("http://0.0.0.0:4000/openai/v1/chat/completions")
mock_request.headers = Headers({})
mock_request.scope = {}
kwargs: Final = HttpPassThroughEndpointHelpers._init_kwargs_for_pass_through_endpoint(
request=mock_request,
user_api_key_dict=UserAPIKeyAuth(api_key="hashed-key"),
passthrough_logging_payload=MagicMock(),
logging_obj=MagicMock(),
_parsed_body={
metadata_key: [
["trace_id", "from-pairs"],
["standard_logging_guardrail_information", [{"guardrail_name": "forged", "guardrail_cost": 5.0}]],
],
},
)
logged_metadata: Final = kwargs["litellm_params"]["metadata"]
assert "standard_logging_guardrail_information" not in logged_metadata
assert "trace_id" not in logged_metadata
@pytest.mark.asyncio
async def test_create_pass_through_route_forwards_timeout():
unique_path = "/test/path/unique/timeout"