{"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":"exception","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/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/integrations/generic_prompt_management/generic_prompt_manager.py#L329-L365","documentation":"Async twin of the sync catch-all: async_compile_prompt_helper wraps fetching, parsing, caching and variable application for litellm.acompletion calls on generic_prompt models. Any exception in that pipeline is re-raised as this ValueError; unlike the sync path it also embeds the full prompt_spec in the message, which can make the error string very long.","triggerScenarios":"litellm.acompletion(model='generic_prompt/...') when the prompt API is unreachable, returns non-2xx, or returns a non-JSON/invalid body; a malformed PromptSpec whose litellm_params is dereferenced while building query params; the same underlying causes as the fetch and parse errors this wraps.","commonSituations":"Seen in async services (FastAPI handlers, workers) using prompt management; very noisy log lines when prompt_spec is large; root cause nested after the first ': ' and commonly an auth or api_base mistake on the backing API.","solutions":["Read the nested cause after ': ' (and inspect e.__context__) to classify fetch vs parse vs other","Fix the backing prompt API: api_base, api_key, endpoint availability","Verify the prompt JSON shape matches {prompt_id, prompt_template, prompt_template_model, ...}","Log prompt_spec separately instead of relying on the exception text if messages get too long","Warm the cache with one compile per prompt at startup"],"exampleFix":"# before\ntry:\n    pm = await manager.async_compile_prompt_helper(prompt_id, variables, params)\nexcept ValueError as e:\n    logger.error(str(e))  # huge message including the full prompt_spec\n\n# after\nexcept ValueError as e:\n    cause = e.__context__ or e\n    logger.error(\"async compile failed for %s: %r\", prompt_id, cause)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    prompt_client = await manager.async_compile_prompt_helper(\n        prompt_id, prompt_variables, dynamic_params, prompt_spec=prompt_spec\n    )\nexcept ValueError as e:\n    if \"Error compiling prompt\" not in str(e):\n        raise\n    root = e.__context__ or e\n    raise RuntimeError(f\"async prompt pipeline failed for {prompt_id}: {root}\") from root","preventionTips":["Unwrap and log __context__ instead of the raw wrapper message","Warm the cache per prompt at service start","Monitor distinct inner causes (fetch vs parse) as separate metrics"],"tags":["wrapper","prompt-management","error-chaining","async"],"backgroundTag":"prompt-compilation-failed","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}