BerriAI/litellm · error · ValueError
safety_settings must be a list
Error message
safety_settings must be a list
What it means
Type guard while processing safety_settings for a Vertex AI non-Gemini call: the value popped from optional_params is not a list as the Vertex SDK expects, so it is rejected before being passed to the model.
Source
Thrown at litellm/llms/vertex_ai/vertex_ai_non_gemini.py:165
)
vertexai.init(
project=vertex_project,
location=vertex_location,
credentials=cast(Credentials, creds),
)
## Load Config
config: Final = litellm.VertexAIConfig.get_config()
for k, v in config.items():
if k not in optional_params:
optional_params[k] = v
## Process safety settings into format expected by vertex AI
safety_settings = None
if "safety_settings" in optional_params:
safety_settings = optional_params.pop("safety_settings")
if not isinstance(safety_settings, list):
raise ValueError("safety_settings must be a list")
if len(safety_settings) > 0 and not isinstance(safety_settings[0], dict):
raise ValueError("safety_settings must be a list of dicts")
safety_settings = [gapic_content_types.SafetySetting(x) for x in safety_settings]
# vertexai does not use an API key, it looks for credentials.json in the environment
prompt: Final = " ".join(
[message.get("content") for message in messages if isinstance(message.get("content", None), str)]
)
mode = ""
request_str = ""
response_obj: Final = None
instances = None
client_options: Final = {"api_endpoint": f"{vertex_location}-aiplatform.googleapis.com"}
fake_stream = False
if model in litellm.vertex_language_models or model in litellm.vertex_vision_models:View on GitHub (pinned to 77b7c6c40c)
Solutions
- Pass safety_settings as a list, e.g. [{'category': 'HARM_CATEGORY_...', 'threshold': 'BLOCK_...'}].
- Convert a single dict into a one-element list before passing it.
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at litellm/llms/vertex_ai/vertex_ai_non_gemini.py:165 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/90e2f3153f434c94.
Report an issue: GitHub.