Skip to content

get_model_name_from_config raises KeyError instead of returning empty string #3810

Description

@miatco

backend/utils/config_utils.py:41-49:

def get_model_name_from_config(model_config: Dict[str, Any]) -> str:
    """Get model name from model id"""
    if model_config is None:
        return ""
    model_repo = model_config["model_repo"]
    model_name = model_config["model_name"]
    if not model_repo:
        return model_name
    return f"{model_repo}/{model_name}"

The function defends against None but not against partial dicts. Two callers — backend/utils/llm_utils.py:77 (OpenAIModel(model_id=get_model_name_from_config(llm_model_config) if llm_model_config else "")) and backend/utils/memory_utils.py:47, 55 — pass dicts that come straight from tenant_config_manager.get_model_config(). That manager returns default={} whenever the model id can't be parsed (config_utils.py:101), which means a sneaky path exists where you get an {} dict rather than None, and accessing model_config["model_repo"] then raises KeyError.

Concrete repro: configure a tenant with a non-numeric LLM_ID. get_model_config returns default which the caller may have passed as {} or as a partial dict like {"model_name": "x"}. The next call into get_model_name_from_config blows up.

Suggested fix

def get_model_name_from_config(model_config: Dict[str, Any]) -> str:
    if not model_config:
        return ""
    model_repo = model_config.get("model_repo") or ""
    model_name = model_config.get("model_name") or ""
    if not model_repo:
        return model_name
    return f"{model_repo}/{model_name}"

Severity: Medium. The crash propagates up and the user sees a 500.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions