Welcome to Starfishdata.ai Structured Outputs
StructuredLLM
class is central to generating structured outputs. It takes a model name, a prompt, and an output schema as input. The output schema can be defined using Pydantic models or JSON schemas. The run
method of this class executes the LLM with the given prompt and parses the output into the specified structure. src/starfish/llm/structured_llm.py:16-41
JSONParser
includes functionality to convert a simplified field list to a JSON schema. src/starfish/llm/parser/json_parser.py:31-60 This allows for a more concise way to define schemas programmatically.
PydanticParser
and JSONParser
classes are responsible for parsing the output from LLMs and converting it into the specified structured format.
PydanticParser
uses the Pydantic model to parse the LLM output. It handles various scenarios, including markdown code blocks. src/starfish/llm/parser/pydantic_parser.py:44-61
StructuredLLM
with a Pydantic model: