chemFouron Stack Overflow • Recommends
On “define an output schema for a nested json in langchain”
From what I can see the recommended approach is to use the pydantic output parser as opposed to the structured output parser... python.langchain.com/docs/modules/model_io/output_parsers/… (and dealing with nesting explained here... link to this video).
e.g.
from langchain.output_parsers import PydanticOutputParser
from pydantic import BaseModel, Field, validator
from typing import List, Optional
...
class PlanItem(BaseModel):
step: str
tools: Optionalstr = []
data_sources: Optionalstr = []
sub_steps_needed: str
class Plan(BaseModel):
plan: ListPlanItem
parser = PydanticOutputParser(pydantic_object=Plan)
parser.get_format_instructions()