-
Notifications
You must be signed in to change notification settings - Fork 46
Open
Description
What happened?
When sending a malformed metadata field (as an array instead of an object) in a chat completion request, LiteLLM returns an obscure authentication error instead of a clear validation error message.
What should happen?
LiteLLM should return a clear validation error message indicating that the metadata field must be an object/dictionary, not an array.
Reproduction
Request with malformed metadata:
curl -X POST http://localhost/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer some-api-key" \
-d '{
"messages": [{
"content": "Hi",
"role": "user"
}],
"model": "any-authorized-model-id",
"metadata": [
"task_type",
"ranking"
],
"stream": false,
"temperature": 0.1
}'Current error response:
{
"error": {
"message": "Authentication Error, 'list' object has no attribute 'get'",
"type": "auth_error",
"param": "None",
"code": "401"
}
}Expected behavior: A clear validation error such as:
{
"error": {
"message": "Invalid request: 'metadata' must be an object, not an array",
"type": "invalid_request_error",
"param": "metadata",
"code": "400"
}
}Correct format
For reference, the correct metadata format is:
"metadata": {
"task_type": "ranking"
}Relevant log output
"message": "Task exception was never retrieved
future: <Task finished name='Task-6564' coro=<ProxyLogging.post_call_failure_hook() done, defined at /usr/lib/python3.13/site-packages/litellm/proxy/utils.py:1460> exception=AttributeError(\"'list' object has no attribute 'get'\")>",
"level": "ERROR",
"timestamp": "2026-02-04T22:47:41.422472",
"stacktrace": "Traceback (most recent call last):
File \"/usr/lib/python3.13/site-packages/litellm/proxy/utils.py\", line 1518, in post_call_failure_hook
await self._handle_logging_proxy_only_error(...)
File \"/usr/lib/python3.13/site-packages/litellm/proxy/utils.py\", line 1606, in _handle_logging_proxy_only_error
litellm_logging_obj, data = litellm.utils.function_setup(...)
File \"/usr/lib/python3.13/site-packages/litellm/utils.py\", line 876, in function_setup
raise e
File \"/usr/lib/python3.13/site-packages/litellm/utils.py\", line 586, in function_setup
applied_guardrails = get_applied_guardrails(kwargs)
File \"/usr/lib/python3.13/site-packages/litellm/utils.py\", line 537, in get_applied_guardrails
request_guardrails = get_request_guardrails(kwargs)
File \"/usr/lib/python3.13/site-packages/litellm/utils.py\", line 526, in get_request_guardrails
requester_metadata = metadata.get(\"requester_metadata\") or {}
^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'get'"
}
LiteLLM Version
litellm/litellm-non_root:v1.81.3.rc.5
This issue affects user experience by making it difficult to debug malformed requests. The error message is misleading (suggests an authentication problem) and doesn't clearly indicate the actual issue (invalid metadata format).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels