03. StructuredOuputParser
StructuredOutputParser
This output parser answers to LLM dict It can be used when you want to return multiple fields that are configured in format and held in pairs of key/value.
Pydantic/JSON parsers are more powerful, but this is useful for less powerful models (e.g., models with lower intelligence (low parameter count) than GPT and Claude models with intelligence like local models).
Reference
Local model Pydantic Parser often doesn't work, so as an alternative StructuredOutputParser You can use
from dotenv import load_dotenv
load_dotenv()True# LangSmith Set up tracking. https://smith.langchain.com
# !pip install langchain-teddynote
from langchain_teddynote import logging
# Enter a project name.
logging.langsmith("CH03-OutputParser")Start tracking LangSmith.
[Project name]
CH03-OutputParserResponseSchemaThe class is used to define a response schema that contains answers to the user's questions and a description of the source used (website).StructuredOutputParserforresponse_schemasInitialize using, structuring the output according to the defined response schema.
You will now receive a string containing instructions on how the response should be formatted (schemas), inserting a defined schema into the prompt.
chain.stream Using the method, "What is the achievement of the King of the Three Kingdoms?" Ra receives a stream response to the question.
Last updated