| Copyright | (c) 2025 Tushar Adhatrao |
|---|---|
| License | MIT |
| Maintainer | Tushar Adhatrao <tusharadhatrao@gmail.com> |
| Stability | experimental |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Langchain.OutputParser.Core
Description
This module provides the core types and instances for output parsers in the Langchain Haskell port. Output parsers are used to transform the raw output from language models into structured data formats, making it easier to work with the results in downstream applications.
The OutputParser typeclass defines the interface for parsing model output into specific types,
and this module provides instances for common data structures such as booleans, lists, and JSON objects.
For more information on output parsers in the original Langchain library, see: https:/python.langchain.comdocsconceptsoutput_parsers/
Synopsis
- class OutputParser a where
- newtype CommaSeparatedList = CommaSeparatedList [Text]
- newtype FromJSON a => JSONOutputStructure a = JSONOutputStructure {
- jsonValue :: a
- newtype NumberSeparatedList = NumberSeparatedList [Text]
Typeclass
class OutputParser a where Source #
Typeclass for parsing output from language models into specific types.
Instances of this class define how to convert a Text output into a value of type a.
Methods
Instances
| OutputParser ReactAgentOutputParser Source # | |
Defined in Langchain.Agents.React | |
| OutputParser CommaSeparatedList Source # | |
Defined in Langchain.OutputParser.Core | |
| OutputParser NumberSeparatedList Source # | |
Defined in Langchain.OutputParser.Core | |
| OutputParser Bool Source # | |
| FromJSON a => OutputParser (JSONOutputStructure a) Source # | Instance for parsing JSON into any type that implements FromJSON. |
Defined in Langchain.OutputParser.Core | |
Parsers
newtype CommaSeparatedList Source #
Represents a list of text items separated by commas.
Constructors
| CommaSeparatedList [Text] |
Instances
| Show CommaSeparatedList Source # | |
Defined in Langchain.OutputParser.Core Methods showsPrec :: Int -> CommaSeparatedList -> ShowS # show :: CommaSeparatedList -> String # showList :: [CommaSeparatedList] -> ShowS # | |
| Eq CommaSeparatedList Source # | |
Defined in Langchain.OutputParser.Core Methods (==) :: CommaSeparatedList -> CommaSeparatedList -> Bool # (/=) :: CommaSeparatedList -> CommaSeparatedList -> Bool # | |
| OutputParser CommaSeparatedList Source # | |
Defined in Langchain.OutputParser.Core | |
newtype FromJSON a => JSONOutputStructure a Source #
JSON parser wrapper
Requires FromJSON instance for target type. Uses Aeson for parsing.
Example data type:
data Person = Person
{ name :: Text
, age :: Int
} deriving (Show, Eq, FromJSON)
Usage:
>>>parse "{\"name\": \"Bob\", \"age\": 25}" :: Either String (JSONOutputStructure Person)Right (JSONOutputStructure {jsonValue = Person {name = "Bob", age = 25}})
Constructors
| JSONOutputStructure | |
Fields
| |
Instances
| FromJSON a => FromJSON (JSONOutputStructure a) Source # | |
Defined in Langchain.OutputParser.Core Methods parseJSON :: Value -> Parser (JSONOutputStructure a) # parseJSONList :: Value -> Parser [JSONOutputStructure a] # omittedField :: Maybe (JSONOutputStructure a) # | |
| (FromJSON a, Show a) => Show (JSONOutputStructure a) Source # | |
Defined in Langchain.OutputParser.Core Methods showsPrec :: Int -> JSONOutputStructure a -> ShowS # show :: JSONOutputStructure a -> String # showList :: [JSONOutputStructure a] -> ShowS # | |
| Eq a => Eq (JSONOutputStructure a) Source # | |
Defined in Langchain.OutputParser.Core Methods (==) :: JSONOutputStructure a -> JSONOutputStructure a -> Bool # (/=) :: JSONOutputStructure a -> JSONOutputStructure a -> Bool # | |
| FromJSON a => OutputParser (JSONOutputStructure a) Source # | Instance for parsing JSON into any type that implements FromJSON. |
Defined in Langchain.OutputParser.Core | |
newtype NumberSeparatedList Source #
Represents a list of text items separated by numbered prefixes, like "1. First item".
Constructors
| NumberSeparatedList [Text] |
Instances
| Show NumberSeparatedList Source # | |
Defined in Langchain.OutputParser.Core Methods showsPrec :: Int -> NumberSeparatedList -> ShowS # show :: NumberSeparatedList -> String # showList :: [NumberSeparatedList] -> ShowS # | |
| Eq NumberSeparatedList Source # | |
Defined in Langchain.OutputParser.Core Methods (==) :: NumberSeparatedList -> NumberSeparatedList -> Bool # (/=) :: NumberSeparatedList -> NumberSeparatedList -> Bool # | |
| OutputParser NumberSeparatedList Source # | |
Defined in Langchain.OutputParser.Core | |