04. JSON output parser (JsonOutputParser)
JsonOutputParser
This output parser allows the user to specify the desired JSON schema, which results in by viewing data from the LLM to suit that schema.
In order for LLM to process data accurately and efficiently to generate the desired form of JSON, the capacity of the model (meaning intelligence here). Yes. Please note that llama-70B is larger than llama-8B) and this should be enough.
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-OutputParser from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import JsonOutputParser
from pydantic import BaseModel, Field
from langchain_openai import ChatOpenAIDefine the desired output structure.
JsonOutputParser Set the parser using, and inject the instruction clause into the prompt template.
Pydantic use
You can use this feature without Pydantic. In this case, I request to return JSON, but it does not provide specific information on how the schema should be.
Last updated