{"record":{"id":"71c89a3516bdd4e2","repo":"BerriAI/litellm","slug":"error-compiling-prompt-prompt-id-e-prompt","errorCode":null,"errorMessage":"Error compiling prompt '{prompt_id}': {e}, prompt_spec: {prompt_spec}","messagePattern":"Error compiling prompt '(.+?)': (.+?), prompt_spec: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/integrations/generic_prompt_management/generic_prompt_manager.py","lineNumber":347,"sourceCode":"        try:\n            # Fetch from API\n\n            api_response: Final = await self.async_fetch_prompt_from_api(prompt_id=prompt_id, prompt_spec=prompt_spec)\n\n            # Parse the response\n            prompt_client = self._parse_api_response(prompt_id, prompt_spec, api_response)\n\n            # Cache the result\n            self._prompt_cache[cache_key] = prompt_client\n\n            # Apply variables if provided\n            if prompt_variables:\n                prompt_client = self._apply_variables(prompt_client, prompt_variables)\n\n            return prompt_client\n\n        except Exception as e:\n            raise ValueError(f\"Error compiling prompt '{prompt_id}': {e}, prompt_spec: {prompt_spec}\")\n\n    def _apply_variables(\n        self,\n        prompt_client: PromptManagementClient,\n        variables: dict[str, Any],\n    ) -> PromptManagementClient:\n        \"\"\"\n        Apply variables to the prompt template.\n\n        This performs simple string substitution using {variable_name} syntax.\n\n        Args:\n            prompt_client: The prompt client structure\n            variables: Variables to substitute\n\n        Returns:\n            Updated PromptManagementClient with variables applied\n        \"\"\"","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/integrations/generic_prompt_management/generic_prompt_manager.py#L329-L365","documentation":"Raised by GenericPromptManager.async_compile_prompt_helper (async path) as the catch-all wrapper: any Exception during the async fetch, parse, cache, or variable-application steps becomes a ValueError that also embeds the full prompt_spec in the message for diagnostics. Like the sync variant it only fires on cache misses.","triggerScenarios":"Awaiting an async completion with prompt management where the fetch fails (network/HTTP), the API response does not match the expected schema in _parse_api_response, or _apply_variables hits an unresolvable template variable. The message includes prompt_spec, so passing a large spec produces a very long error string.","commonSituations":"Cold-start requests in the LiteLLM proxy against a misconfigured prompt API; schema drift after upgrading the prompt-management service; callers omitting required prompt variables on their first (uncached) request.","solutions":["Parse the embedded cause between 'Error compiling prompt' and ', prompt_spec:' — it identifies the failing sub-step.","Validate that the prompt API returns the documented schema (the _parse_api_response contract) by curling the endpoint.","Supply all template variables in prompt_variables on the request.","If the prompt_spec dump in the message is too noisy, log/inspect it in your handler rather than printing the whole exception string (it may contain config details)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"async def precheck_prompt_compilation(manager, prompt_id: str, variables: dict | None) -> None:\n    await manager.async_compile_prompt_helper(\n        prompt_id=prompt_id,\n        prompt_variables=variables,\n        dynamic_callback_params={},\n    )  # fail during startup, not on user requests","typeGuard":null,"tryCatchPattern":"try:\n    resp = await litellm.acompletion(model=\"prompt-model\", messages=msgs, variables=vars)\nexcept ValueError as e:\n    msg = str(e)\n    if msg.startswith(\"Error compiling prompt\"):\n        # do not log the whole message: it embeds prompt_spec and may be huge / contain config\n        log.error(\"prompt compilation failed for %s\", prompt_id)\n        raise\n    raise","preventionTips":["Warm/validate prompts at startup with a compile call per configured prompt_id.","Avoid dumping the raw exception string to logs — it includes the serialized prompt_spec.","Pin the prompt-management API version so response schema changes are deliberate."],"tags":["prompt-management","wrapper-exception","async","runtime"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}