{"record":{"id":"d44ecf38d45adfdf","repo":"BerriAI/litellm","slug":"cannot-set-prompt-directory-when-working-with-prom","errorCode":null,"errorMessage":"Cannot set prompt_directory when working with prompt_initializer. Needs to be a specific dotprompt file","messagePattern":"Cannot set prompt_directory when working with prompt_initializer\\. Needs to be a specific dotprompt file","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/integrations/dotprompt/__init__.py","lineNumber":54,"sourceCode":"    from .prompt_manager import PromptManager\n\n    # Parse the dotprompt content to extract frontmatter and content\n    temp_manager: Final = PromptManager()\n    metadata, content = temp_manager._parse_frontmatter(dotprompt_content)\n\n    # Convert to prompt_data format\n    return {\"content\": content.strip(), \"metadata\": metadata}\n\n\ndef prompt_initializer(litellm_params: \"PromptLiteLLMParams\", prompt_spec: \"PromptSpec\") -> \"CustomPromptManagement\":\n    \"\"\"\n    Initialize a prompt from a .prompt file.\n    \"\"\"\n    prompt_directory: Final = getattr(litellm_params, \"prompt_directory\", None)\n    prompt_data = getattr(litellm_params, \"prompt_data\", None)\n    prompt_id: Final = getattr(litellm_params, \"prompt_id\", None)\n    if prompt_directory:\n        raise ValueError(\n            \"Cannot set prompt_directory when working with prompt_initializer. Needs to be a specific dotprompt file\"\n        )\n\n    prompt_file: Final = getattr(litellm_params, \"prompt_file\", None)\n\n    # Handle dotprompt_content from database\n    dotprompt_content: Final = getattr(litellm_params, \"dotprompt_content\", None)\n    if dotprompt_content and not prompt_data and not prompt_file:\n        prompt_data = _get_prompt_data_from_dotprompt_content(dotprompt_content)\n\n    try:\n        dot_prompt_manager: Final = DotpromptManager(\n            prompt_directory=prompt_directory,\n            prompt_data=prompt_data,\n            prompt_file=prompt_file,\n            prompt_id=prompt_id,\n        )\n","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/integrations/dotprompt/__init__.py#L36-L72","documentation":"prompt_initializer (litellm/integrations/dotprompt/__init__.py) resolves exactly one prompt source: prompt_file, prompt_data, or dotprompt_content (DB-fetched), identified by prompt_id. If litellm_params also carries prompt_directory — the directory-mode setting used by the dotprompt manager — it raises this ValueError to remove ambiguity about which source should win.","triggerScenarios":"Copy-pasting directory-mode config (prompt_directory=\"/prompts\") into a request that also specifies prompt_file=\"greeting.prompt\" or prompt_id with dotprompt_content; reusing one PromptLiteLLMParams object across both usage styles.","commonSituations":"Migrating a project from directory-based dotprompt usage to per-file prompts and leaving the old field in shared config; templated litellm_params that defaults prompt_directory for every call.","solutions":["Remove prompt_directory from litellm_params when invoking a specific prompt file/data/ID","Or keep prompt_directory and drop prompt_file/dotprompt_content, letting the dotprompt manager resolve prompts from the directory by ID","Centralize the two configurations separately so they are never merged"],"exampleFix":"# before\nlitellm.completion(\n    model=\"gpt-4\",\n    prompt_file=\"greeting.prompt\",\n    prompt_directory=\"/prompts\",   # ValueError: ambiguous source\n)\n\n# after\nlitellm.completion(\n    model=\"gpt-4\",\n    prompt_file=\"greeting.prompt\",\n)","handlingStrategy":"validation","validationCode":"def prompt_params_unambiguous(litellm_params) -> None:\n    has_specific = any(\n        getattr(litellm_params, f, None)\n        for f in (\"prompt_file\", \"prompt_data\", \"dotprompt_content\")\n    )\n    has_directory = bool(getattr(litellm_params, \"prompt_directory\", None))\n    if has_specific and has_directory:\n        raise ValueError(\"pass either prompt_directory OR a specific prompt source, not both\")","typeGuard":"from typing import Any\n\ndef is_single_prompt_request(litellm_params: Any) -> bool:\n    \"\"\"True when params address one specific prompt and must not carry a directory.\"\"\"\n    return bool(getattr(litellm_params, \"prompt_id\", None) or getattr(litellm_params, \"prompt_file\", None))","tryCatchPattern":null,"preventionTips":["Keep two config presets: directory-mode and per-file-mode; never merge them","Strip prompt_directory in the code path that resolves a specific prompt file","Assert the exclusive-fields invariant in a config unit test"],"tags":["dotprompt","prompt-management","configuration","conflicting-options","validation"],"backgroundTag":"conflicting-configuration","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}