spring-ai icon indicating copy to clipboard operation
spring-ai copied to clipboard

Ineffective OutputParser Implementation in PromptTemplate

Open alvaroblazmon opened this issue 9 months ago • 1 comments

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

  1. Remove the OutputParser from the PromptTemplate codebase to eliminate confusion, as it currently serves no operational purpose.
  2. Enhance PromptTemplate by allowing OutputParser to be set either directly or through the constructor. The class should then automatically integrate the necessary format handling using outputParser.getFormat().

Steps to Reproduce

  1. Instantiate a PromptTemplate.
  2. Set a custom OutputParser with a specific format.
  3. Generate output using the PromptTemplate.
  4. Observe that the format specified in OutputParser is not reflected in the output.

alvaroblazmon avatar Apr 30 '24 16:04 alvaroblazmon

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?

tha2015 avatar May 04 '24 21:05 tha2015

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 avatar Jul 22 '24 21:07 markpollack

@markpollack it seems that it was removed in this commit 2 months ago:

https://github.com/spring-projects/spring-ai/commit/6c9c766da66546a0cb030b5c3bc55c27f481d913#diff-28e77b2c55af25449804d18e9c53cbf82a825dc09208cf9a85ce18d89e1db501

alvaroblazmon avatar Jul 23 '24 13:07 alvaroblazmon