{"record":{"id":"1d2cbee75f025b70","repo":"BerriAI/litellm","slug":"invalid-template-message-type-type-template-mess","errorCode":null,"errorMessage":"Invalid template message type: {type(template_message)}","messagePattern":"Invalid template message type: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/integrations/humanloop.py","lineNumber":88,"sourceCode":"            headers={\n                \"X-Api-Key\": humanloop_api_key,\n                \"Content-Type\": \"application/json\",\n            },\n        )\n\n        try:\n            response.raise_for_status()\n        except httpx.HTTPStatusError as e:\n            raise Exception(f\"Error getting prompt from Humanloop: {e.response.text}\")\n\n        json_response: Final = response.json()\n        template_message: Final = json_response[\"template\"]\n        if isinstance(template_message, dict):\n            template_messages = [template_message]\n        elif isinstance(template_message, list):\n            template_messages = template_message\n        else:\n            raise ValueError(f\"Invalid template message type: {type(template_message)}\")\n        template_model: Final = json_response[\"model\"]\n        optional_params: Final = {}\n        for k, v in json_response.items():\n            if k in litellm.OPENAI_CHAT_COMPLETION_PARAMS:\n                optional_params[k] = v\n        return PromptManagementClient(\n            prompt_id=humanloop_prompt_id,\n            prompt_template=cast(list[AllMessageValues], template_messages),\n            model=template_model,\n            optional_params=optional_params,\n        )\n\n    def _get_prompt_from_id(self, humanloop_prompt_id: str, humanloop_api_key: str) -> PromptManagementClient:\n        prompt = self._get_prompt_from_id_cache(humanloop_prompt_id)\n        if prompt is None:\n            prompt = self._get_prompt_from_id_api(humanloop_prompt_id, humanloop_api_key)\n            self.set_cache(\n                key=humanloop_prompt_id,","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/integrations/humanloop.py#L70-L106","documentation":"ValueError from Humanloop prompt fetching: the JSON 'template' field must be a dict (single message) or a list (message array); any other JSON type (string, null, number) triggers this. It indicates the Humanloop prompt response schema doesn't match what litellm expects.","triggerScenarios":"A Humanloop prompt of a type whose serialized 'template' is not messages (e.g. a text-completion style prompt or a misconfigured prompt), or 'template' being null in the API response for an empty/invalid prompt. Also possible after Humanloop API schema changes across versions.","commonSituations":"Using a Humanloop prompt configured as a 'generator' type that returns a string template; deleted/empty prompt returning null; litellm version lagging behind a Humanloop API change; model-type mismatch in the Humanloop project.","solutions":["Open the prompt in Humanloop and confirm it is a chat prompt with a proper message array","Re-fetch the raw API response (curl with X-Api-Key) and inspect the 'template' field's JSON type","Recreate the prompt as a chat-style prompt with at least one message object","Upgrade litellm if a newer release handles the current Humanloop schema"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":"def is_valid_template(value) -> bool:\n    \"\"\"Humanloop 'template' must be a message dict or list of message dicts.\"\"\"\n    if isinstance(value, dict):\n        return \"role\" in value or \"content\" in value\n    if isinstance(value, list):\n        return all(isinstance(m, dict) for m in value)\n    return False","tryCatchPattern":"try:\n    pmc = get_humanloop_prompt(prompt_id)\nexcept ValueError as e:\n    if \"Invalid template message type\" in str(e):\n        raise RuntimeError(\"Reconfigure the Humanloop prompt as a chat prompt\") from e\n    raise","preventionTips":["Create Humanloop prompts as chat-type with message arrays","Inspect raw API responses when integrating new prompt types","Keep litellm updated for Humanloop schema changes"],"tags":["humanloop","prompt-management","litellm","schema","validation"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}