langchain-hs-0.0.2.0: Haskell implementation of Langchain
Copyright(c) 2025 Tushar Adhatrao
LicenseMIT
MaintainerTushar Adhatrao <[email protected]>
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

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

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

parse :: Text -> Either String a Source #

Parse the given text into a value of type a. Returns Left with an error message if parsing fails, or Right with the parsed value.

Instances

Instances details
OutputParser CommaSeparatedList Source # 
Instance details

Defined in Langchain.OutputParser.Core

OutputParser NumberSeparatedList Source # 
Instance details

Defined in Langchain.OutputParser.Core

OutputParser Bool Source # 
Instance details

Defined in Langchain.OutputParser.Core

FromJSON a => OutputParser (JSONOutputStructure a) Source #

Instance for parsing JSON into any type that implements FromJSON.

Instance details

Defined in Langchain.OutputParser.Core

Parsers

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

Instances details
FromJSON a => FromJSON (JSONOutputStructure a) Source # 
Instance details

Defined in Langchain.OutputParser.Core

(FromJSON a, Show a) => Show (JSONOutputStructure a) Source # 
Instance details

Defined in Langchain.OutputParser.Core

Eq a => Eq (JSONOutputStructure a) Source # 
Instance details

Defined in Langchain.OutputParser.Core

FromJSON a => OutputParser (JSONOutputStructure a) Source #

Instance for parsing JSON into any type that implements FromJSON.

Instance details

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]