{"record":{"id":"9854ed8d42fc872e","repo":"BerriAI/litellm","slug":"error-compiling-prompt-e-prompt-id-prompt-id","errorCode":null,"errorMessage":"Error compiling prompt: {e}. Prompt id={prompt_id}","messagePattern":"Error compiling prompt: (.+?)\\. Prompt id=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/integrations/prompt_management_base.py","lineNumber":90,"sourceCode":"        client_messages: list[AllMessageValues],\n        dynamic_callback_params: StandardCallbackDynamicParams,\n        prompt_label: str | None = None,\n        prompt_version: int | None = None,\n        prompt_spec: PromptSpec | None = None,\n    ) -> PromptManagementClient:\n        compiled_prompt_client: Final = self._compile_prompt_helper(\n            prompt_id=prompt_id,\n            prompt_spec=prompt_spec,\n            prompt_variables=prompt_variables,\n            dynamic_callback_params=dynamic_callback_params,\n            prompt_label=prompt_label,\n            prompt_version=prompt_version,\n        )\n\n        try:\n            messages: Final = compiled_prompt_client[\"prompt_template\"] + client_messages\n        except Exception as e:\n            raise ValueError(f\"Error compiling prompt: {e}. Prompt id={prompt_id}\")\n\n        compiled_prompt_client[\"completed_messages\"] = messages\n        return compiled_prompt_client\n\n    async def async_compile_prompt(\n        self,\n        prompt_id: str | None,\n        prompt_variables: dict | None,\n        client_messages: list[AllMessageValues],\n        dynamic_callback_params: StandardCallbackDynamicParams,\n        prompt_spec: PromptSpec | None = None,\n        prompt_label: str | None = None,\n        prompt_version: int | None = None,\n    ) -> PromptManagementClient:\n        compiled_prompt_client: Final = await self.async_compile_prompt_helper(\n            prompt_id=prompt_id,\n            prompt_spec=prompt_spec,\n            prompt_variables=prompt_variables,","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/integrations/prompt_management_base.py#L72-L108","documentation":"In the sync prompt-management path, after the prompt manager compiles a template, the code does compiled_prompt_client['prompt_template'] + client_messages. If prompt_template is missing, None, or not a list, that concatenation raises and is re-wrapped as ValueError('Error compiling prompt: ... Prompt id=<id>'). The root exception text is embedded in the message.","triggerScenarios":"A prompt id whose stored template is not a message list (e.g. a plain string template in PromptLayer/Anthropic prompt config); the manager returning an empty/None prompt_template because the prompt id does not exist; client_messages not being a list.","commonSituations":"Switching a prompt from raw-text format to chat format (or vice versa) in the prompt manager; referencing a deleted prompt id; prompt variables that make the template render to a non-list value.","solutions":["Read the inner exception in the message — it tells you exactly whether it was a KeyError ('prompt_template') or TypeError (str + list)","Open the prompt in the manager UI and save it as a chat/messages template (a list of {role, content} objects)","Verify the prompt id exists and the integration name prefix in the model string matches (e.g. 'promptlayer/<id>')"],"exampleFix":"# before (prompt stored as plain text in PromptLayer)\nmodel = \"promptlayer/my-prompt\"  # prompt_template == \"You are...\" -> TypeError\n\n# after (store as chat template: list of messages)\n# prompt_template = [{\"role\": \"system\", \"content\": \"You are...\"}]\nmodel = \"promptlayer/my-prompt\"","handlingStrategy":"validation","validationCode":"def is_compilable(prompt_result: dict) -> bool:\n    return isinstance(prompt_result.get(\"prompt_template\"), list)\n\ncompiled = client._compile_prompt_helper(prompt_id=pid, ...)\nassert is_compilable(compiled), f\"prompt {pid} did not return a message list\"","typeGuard":"from typing import Any, TypeGuard\n\ndef is_message_list(v: Any) -> TypeGuard[list[dict]]:\n    return isinstance(v, list) and all(isinstance(m, dict) and \"role\" in m for m in v)","tryCatchPattern":"try:\n    compiled = pm.compile_prompt(prompt_id=pid, prompt_variables=vars_, client_messages=msgs,\n                                dynamic_callback_params={})\nexcept ValueError as e:\n    raise ValueError(f\"Prompt '{pid}' has a malformed template: {e}\") from e","preventionTips":["Store all prompt-manager prompts in chat (messages) format, never raw text, when compiling with client messages","Add a deploy-time check that fetches every referenced prompt id and asserts prompt_template is a list","Watch prompt format after imports/migrations between completion-style and chat-style templates"],"tags":["prompt-management","promptlayer","templates","configuration"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}