BerriAI/litellm · error · ValueError

Invalid template message type

Error message

Invalid template message type: {type(template_message)}

What it means

Humanloop integration guard: the 'template' field fetched from the Humanloop API response is neither a dict nor a list, i.e. an unexpected payload shape the template-message handler cannot process.

Solutions

  1. Ensure each template message is a dict or a supported message type, not a raw string or other object.

Example fix

template = [{'role': 'user', 'content': 'Hello {{name}}'}]
Defensive patterns

Strategy: validation

When it happens

Trigger: A Humanloop prompt template contains a message entry of an unexpected type.

Common situations: Template fetched in an unexpected format or hand-built template with malformed entries.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/1d2cbee75f025b70. Report an issue: GitHub.

Appendix: source

Thrown at litellm/integrations/humanloop.py:88

            headers={
                "X-Api-Key": humanloop_api_key,
                "Content-Type": "application/json",
            },
        )

        try:
            response.raise_for_status()
        except httpx.HTTPStatusError as e:
            raise Exception(f"Error getting prompt from Humanloop: {e.response.text}")

        json_response: Final = response.json()
        template_message: Final = json_response["template"]
        if isinstance(template_message, dict):
            template_messages = [template_message]
        elif isinstance(template_message, list):
            template_messages = template_message
        else:
            raise ValueError(f"Invalid template message type: {type(template_message)}")
        template_model: Final = json_response["model"]
        optional_params: Final = {}
        for k, v in json_response.items():
            if k in litellm.OPENAI_CHAT_COMPLETION_PARAMS:
                optional_params[k] = v
        return PromptManagementClient(
            prompt_id=humanloop_prompt_id,
            prompt_template=cast(list[AllMessageValues], template_messages),
            model=template_model,
            optional_params=optional_params,
        )

    def _get_prompt_from_id(self, humanloop_prompt_id: str, humanloop_api_key: str) -> PromptManagementClient:
        prompt = self._get_prompt_from_id_cache(humanloop_prompt_id)
        if prompt is None:
            prompt = self._get_prompt_from_id_api(humanloop_prompt_id, humanloop_api_key)
            self.set_cache(
                key=humanloop_prompt_id,

View on GitHub (pinned to 77b7c6c40c)