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

Copy

from dotenv import load_dotenv

load_dotenv()

Copy

True

Copy

# 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")

Copy

Copy

  • ResponseSchema The class is used to define a response schema that contains answers to the user's questions and a description of the source used (website).

  • StructuredOutputParser for response_schemas Initialize using, structuring the output according to the defined response schema.

Copy

You will now receive a string containing instructions on how the response should be formatted (schemas), inserting a defined schema into the prompt.

Copy

Copy

Copy

Copy

chain.stream Using the method, "What is the achievement of the King of the Three Kingdoms?" Ra receives a stream response to the question.

Copy

Copy

Last updated