{"record":{"id":"ac61ba899ac2e495","repo":"langchain-ai/langchain","slug":"cannot-save-prompt-with-partial-variables","errorCode":null,"errorMessage":"Cannot save prompt with partial variables.","messagePattern":"Cannot save prompt with partial variables\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/prompts/base.py","lineNumber":405,"sourceCode":"    def save(self, file_path: Path | str) -> None:\n        \"\"\"Save the prompt.\n\n        Args:\n            file_path: Path to directory to save prompt to.\n\n        Raises:\n            ValueError: If the prompt has partial variables.\n            ValueError: If the file path is not json or yaml.\n            NotImplementedError: If the prompt type is not implemented.\n\n        Example:\n            ```python\n            prompt.save(file_path=\"path/prompt.yaml\")\n            ```\n        \"\"\"\n        if self.partial_variables:\n            msg = \"Cannot save prompt with partial variables.\"\n            raise ValueError(msg)\n\n        # Fetch dictionary to save. Preserve deprecated `dict()` overrides until\n        # `dict()` is removed.\n        prompt_dict = self._dict_for_compat()\n        if \"_type\" not in prompt_dict:\n            msg = f\"Prompt {self} does not support saving.\"\n            raise NotImplementedError(msg)\n\n        # Convert file to Path object.\n        save_path = Path(file_path)\n\n        directory_path = save_path.parent\n        directory_path.mkdir(parents=True, exist_ok=True)\n\n        resolved_path = save_path.resolve()\n        if resolved_path.suffix == \".json\":\n            with resolved_path.open(\"w\", encoding=\"utf-8\") as f:\n                json.dump(prompt_dict, f, indent=4)","sourceCodeStart":387,"sourceCodeEnd":423,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/prompts/base.py#L387-L423","documentation":"BasePromptTemplate.save() refuses to serialize a prompt that has partial_variables, raising ValueError. Serialization writes the template and its input variables; a partially substituted variable has no serializable representation in the saved prompt format, so saving is blocked up front.","triggerScenarios":"Calling prompt.save('prompt.yaml') (or .json) after using .partial(...) or constructing with partial_variables={'k': v} where the dict is non-empty.","commonSituations":"Teams building prompts with runtime partials (e.g. today's date) and then trying to snapshot them to disk for versioning or deployment; LangHub-style workflows that export prompts to YAML.","solutions":["Remove the partial before saving: serialize the underlying template without .partial(), then re-apply partials at load time","Save a separate config file that records the partial values, and reconstruct with partial after loading","Replace the partial with a static value in the saved copy if the partial is effectively constant"],"exampleFix":"# before\nprompt = PromptTemplate.from_template(\"News for {date}: {topic}\").partial(date=today)\nprompt.save(\"prompt.yaml\")  # ValueError\n\n# after\nPromptTemplate.from_template(\"News for {date}: {topic}\").save(\"prompt.yaml\")\nloaded = load_prompt(\"prompt.yaml\").partial(date=today)","handlingStrategy":"fallback","validationCode":"def can_save(prompt) -> bool:\n    return not prompt.partial_variables","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Save the un-partialed template and re-apply partials after load_prompt","Keep partial values in a separate config artifact next to the saved prompt"],"tags":["prompts","serialization","partial-variables","core"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}