BerriAI/litellm · error · ValueError
Error compiling prompt: {e}. Prompt id={prompt_id}
Error message
Error compiling prompt: {e}. Prompt id={prompt_id} What it means
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.
Source
Thrown at litellm/integrations/prompt_management_base.py:90
client_messages: list[AllMessageValues],
dynamic_callback_params: StandardCallbackDynamicParams,
prompt_label: str | None = None,
prompt_version: int | None = None,
prompt_spec: PromptSpec | None = None,
) -> PromptManagementClient:
compiled_prompt_client: Final = self._compile_prompt_helper(
prompt_id=prompt_id,
prompt_spec=prompt_spec,
prompt_variables=prompt_variables,
dynamic_callback_params=dynamic_callback_params,
prompt_label=prompt_label,
prompt_version=prompt_version,
)
try:
messages: Final = compiled_prompt_client["prompt_template"] + client_messages
except Exception as e:
raise ValueError(f"Error compiling prompt: {e}. Prompt id={prompt_id}")
compiled_prompt_client["completed_messages"] = messages
return compiled_prompt_client
async def async_compile_prompt(
self,
prompt_id: str | None,
prompt_variables: dict | None,
client_messages: list[AllMessageValues],
dynamic_callback_params: StandardCallbackDynamicParams,
prompt_spec: PromptSpec | None = None,
prompt_label: str | None = None,
prompt_version: int | None = None,
) -> PromptManagementClient:
compiled_prompt_client: Final = await self.async_compile_prompt_helper(
prompt_id=prompt_id,
prompt_spec=prompt_spec,
prompt_variables=prompt_variables,View on GitHub (pinned to 6c2dcb801b)
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>')
Example fix
# before (prompt stored as plain text in PromptLayer)
model = "promptlayer/my-prompt" # prompt_template == "You are..." -> TypeError
# after (store as chat template: list of messages)
# prompt_template = [{"role": "system", "content": "You are..."}]
model = "promptlayer/my-prompt" Defensive patterns
Strategy: validation
Validate before calling
def is_compilable(prompt_result: dict) -> bool:
return isinstance(prompt_result.get("prompt_template"), list)
compiled = client._compile_prompt_helper(prompt_id=pid, ...)
assert is_compilable(compiled), f"prompt {pid} did not return a message list" Type guard
from typing import Any, TypeGuard
def is_message_list(v: Any) -> TypeGuard[list[dict]]:
return isinstance(v, list) and all(isinstance(m, dict) and "role" in m for m in v) Try / catch
try:
compiled = pm.compile_prompt(prompt_id=pid, prompt_variables=vars_, client_messages=msgs,
dynamic_callback_params={})
except ValueError as e:
raise ValueError(f"Prompt '{pid}' has a malformed template: {e}") from e Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Prompt template '{prompt_id}' not found
- bitbucket_config is required for BitBucket prompt integratio
- prompt_id is required for Prompt Management Base class
- BitBucket configuration not found. Please set litellm.global
- Gitlab configuration not found. Please set litellm.global_gi
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/9854ed8d42fc872e.
Report an issue: GitHub.