{"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":"exception","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/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/integrations/prompt_management_base.py#L72-L108","documentation":"In the sync prompt-management path, litellm concatenates the fetched template with your messages: compiled['prompt_template'] + client_messages. If the provider integration returned a prompt_template that is not a list of messages (a plain string, None, or a payload missing the key), the + operation raises, and it is re-raised as ValueError('Error compiling prompt: ... Prompt id=...') with the underlying error inline. The prompt id tells you which fetch produced the unusable template.","triggerScenarios":"Calling litellm.completion(..., prompt_id='...', prompt_variables={...}) with a prompt-management integration (Langfuse/Humanlike/PromptLayer-style) where the stored prompt is a Text prompt (single string) rather than a Chat prompt (message list); the prompt was deleted so the client returned None; a shape change in the provider SDK after upgrade.","commonSituations":"Creating the prompt in the provider dashboard as the wrong type; prompt_id pointing at another environment's deleted prompt; provider client version drift changing what prompt_template contains.","solutions":["Open prompt_id in the provider UI and confirm it is a chat/message prompt (list of role/content messages), not a text prompt","Recreate the prompt as a chat prompt or map the text template into a single user message yourself","Verify prompt_variables values are the expected scalar types so the provider returns a fully resolved template","Check prompt_label/prompt_version resolve to an existing version, then retry","Update litellm if the integration had fixes for the provider's response shape"],"exampleFix":"# before (Langfuse prompt stored as Text -> prompt_template is a str)\nresp = litellm.completion(model='gpt-4o', prompt_id='my-text-prompt', prompt_variables={'q': 'hi'})\n# ValueError: Error compiling prompt: can only concatenate list (not \"str\") to list. Prompt id=my-text-prompt\n\n# after (Langfuse prompt stored as Chat -> prompt_template is a list)\nresp = litellm.completion(model='gpt-4o', prompt_id='my-chat-prompt', prompt_variables={'q': 'hi'})","handlingStrategy":"try-catch","validationCode":"compiled = integration.compile_prompt_helper_result_for('my-prompt')\ntemplate = compiled.get('prompt_template') if isinstance(compiled, dict) else None\nif not isinstance(template, list):\n    raise RuntimeError(f'prompt my-prompt returned non-list template: {type(template).__name__}')","typeGuard":"def is_message_list(template: object) -> bool:\n    return isinstance(template, list) and all(\n        isinstance(m, dict) and isinstance(m.get('content'), (str, list)) for m in template\n    )","tryCatchPattern":"try:\n    resp = litellm.completion(model='gpt-4o', prompt_id='my-prompt', prompt_variables={'q': q})\nexcept ValueError as e:\n    if 'Error compiling prompt' in str(e):\n        logger.error('prompt %s unusable, falling back to raw messages: %s', prompt_id, e)\n        resp = litellm.completion(model='gpt-4o', messages=msgs)\n    else:\n        raise","preventionTips":["Create provider prompts as chat prompts (message lists), never text prompts, for litellm prompt management","Smoke-test each prompt_id after creation or environment migration","Keep a fallback path to plain messages so one bad prompt does not take down serving"],"tags":["prompt-management","langfuse","prompt-template","type-error"],"backgroundTag":"prompt-compilation-failed","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}