BerriAI/litellm · error · ValueError
safety_settings must be a list of dicts
Error message
safety_settings must be a list of dicts
What it means
Type guard on safety_settings elements: the value is a list but its items are not dicts (the Vertex SDK expects [{'category': ..., 'threshold': ...}] entries), so the malformed setting is refused before the API call.
Source
Thrown at litellm/llms/vertex_ai/vertex_ai_non_gemini.py:167
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:
llm_model: Any = _vertex_llm_model_object or GenerativeModel(model)
mode = "vision"View on GitHub (pinned to 77b7c6c40c)
Solutions
- Ensure every entry in safety_settings is a dict with 'category' and 'threshold' keys.
- Remove or convert non-dict entries (strings, None) in the safety_settings list.
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at litellm/llms/vertex_ai/vertex_ai_non_gemini.py:167 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/5aa1d124305234f8.
Report an issue: GitHub.