Code lab 11.3 – Output parsers
The file you need to access from the GitHub repository is titled CHAPTER11-3_OUTPUT_PARSERS.ipynb
.
The end result of any RAG application is going to be text, along with potentially some formatting, metadata, and some other related data. This output typically comes from the LLM itself. But there are times when you want to get a more structured format than just text. Output parsers are classes that help to structure the responses of the LLM wherever you use it in your RAG application. The output that this provides will then be provided to the next step in the chain, or in the case of all of our code labs, as the final output from the model.
We will cover two different output parsers at the same time, and use them at different times in our RAG pipeline. We start with the parser we know, the string output parser.
Under the relevance_prompt
function, add this code to a new cell:
from langchain_core.output_parsers import StrOutputParser str_output_parser...