spring-ai
spring-ai copied to clipboard
Ineffective OutputParser Implementation in PromptTemplate
Description
I have been testing the functionality of the PromptTemplate class and noticed that it includes a getter and a setter for an OutputParser variable. However, upon reviewing the code and conducting several tests, it appears that this variable is not being utilized as expected.
Issue Details
The current implementation of OutputParser in PromptTemplate does not seem to affect the template output. Setting a value to outputParser does not integrate the parser's format into the template.
According to the documentation, the correct way to use an OutputParser in a PromptTemplate is by incorporating {format} in the template string, which should reflect the value from outputParser.getFormat() in the model.
Proposals for Improvement
- Remove the
OutputParserfrom thePromptTemplatecodebase to eliminate confusion, as it currently serves no operational purpose. - Enhance
PromptTemplateby allowingOutputParserto be set either directly or through the constructor. The class should then automatically integrate the necessary format handling usingoutputParser.getFormat().
Steps to Reproduce
- Instantiate a
PromptTemplate. - Set a custom
OutputParserwith a specific format. - Generate output using the
PromptTemplate. - Observe that the format specified in
OutputParseris not reflected in the output.
I have same concern about PromptTemplate when learning how to use it. There is no reason for including outputParser property into it and maybe that property should be removed?
I would be inclined to remove it. This comes from the very early says where I was reviewing langchain and llamaindex and langchain had this design. It is a mistake in retrospect.
@markpollack it seems that it was removed in this commit 2 months ago:
https://github.com/spring-projects/spring-ai/commit/6c9c766da66546a0cb030b5c3bc55c27f481d913#diff-28e77b2c55af25449804d18e9c53cbf82a825dc09208cf9a85ce18d89e1db501