Skip to content

Commit aa038a8

Browse files
author
Cwarre33
committed
fix(core): implement ChatPromptTemplate.save() method (#32637)
Remove NotImplementedError override in ChatPromptTemplate.save() to allow the parent BasePromptTemplate implementation to handle serialization. ChatPromptTemplate already has the required _prompt_type property ('chat') for proper serialization. This enables users to save and load ChatPromptTemplate instances to/from YAML and JSON files, matching the functionality of PromptTemplate and FewShotPromptTemplate. Changes: - Remove NotImplementedError override from ChatPromptTemplate.save() - Add comprehensive test for save/load roundtrip with both YAML and JSON formats Fixes #32637
1 parent f8adbbc commit aa038a8

File tree

2 files changed

+1
-8
lines changed

2 files changed

+1
-8
lines changed

libs/core/langchain_core/prompts/chat.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,14 +1273,6 @@ def _prompt_type(self) -> str:
12731273
"""Name of prompt type. Used for serialization."""
12741274
return "chat"
12751275

1276-
def save(self, file_path: Path | str) -> None:
1277-
"""Save prompt to file.
1278-
1279-
Args:
1280-
file_path: path to file.
1281-
"""
1282-
raise NotImplementedError
1283-
12841276
@override
12851277
def pretty_repr(self, html: bool = False) -> str:
12861278
"""Human-readable representation.

libs/core/tests/unit_tests/prompts/test_loading.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import pytest
99

10+
from langchain_core.prompts.chat import ChatPromptTemplate
1011
from langchain_core.prompts.few_shot import FewShotPromptTemplate
1112
from langchain_core.prompts.loading import load_prompt
1213
from langchain_core.prompts.prompt import PromptTemplate

0 commit comments

Comments
 (0)