BerriAI/litellm · error · ValueError
Error compiling prompt
Error message
Error compiling prompt: {e}. Prompt id={prompt_id} What it means
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.
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
Example fix
# before (Langfuse prompt stored as Text -> prompt_template is a str)
resp = litellm.completion(model='gpt-4o', prompt_id='my-text-prompt', prompt_variables={'q': 'hi'})
# ValueError: Error compiling prompt: can only concatenate list (not "str") to list. Prompt id=my-text-prompt
# after (Langfuse prompt stored as Chat -> prompt_template is a list)
resp = litellm.completion(model='gpt-4o', prompt_id='my-chat-prompt', prompt_variables={'q': 'hi'}) Defensive patterns
Strategy: try-catch
Validate before calling
compiled = integration.compile_prompt_helper_result_for('my-prompt')
template = compiled.get('prompt_template') if isinstance(compiled, dict) else None
if not isinstance(template, list):
raise RuntimeError(f'prompt my-prompt returned non-list template: {type(template).__name__}') Type guard
def is_message_list(template: object) -> bool:
return isinstance(template, list) and all(
isinstance(m, dict) and isinstance(m.get('content'), (str, list)) for m in template
) Try / catch
try:
resp = litellm.completion(model='gpt-4o', prompt_id='my-prompt', prompt_variables={'q': q})
except ValueError as e:
if 'Error compiling prompt' in str(e):
logger.error('prompt %s unusable, falling back to raw messages: %s', prompt_id, e)
resp = litellm.completion(model='gpt-4o', messages=msgs)
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- api_base is required in generic_prompt_config
- 'apply_guardrail' must be a callable function
- aretrieve_container_file_content expected bytes, got
- bitbucket_config is required for BitBucket prompt…
- BitBucket configuration not found. Please set…
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/9854ed8d42fc872e.
Report an issue: GitHub.
Appendix: 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 77b7c6c40c)