janus.parsers.code_parser#

Attributes#

log

Classes#

CodeParser

Base class to parse the output of an LLM call.

Module Contents#

janus.parsers.code_parser.log#
class janus.parsers.code_parser.CodeParser#

Bases: janus.parsers.parser.JanusParser

Base class to parse the output of an LLM call.

Output parsers help structure language model responses.

Example

class BooleanOutputParser(BaseOutputParser[bool]):
    true_val: str = "YES"
    false_val: str = "NO"

    def parse(self, text: str) -> bool:
        cleaned_text = text.strip().upper()
        if cleaned_text not in (self.true_val.upper(), self.false_val.upper()):
            raise OutputParserException(
                f"BooleanOutputParser expected output value to either be "
                f"{self.true_val} or {self.false_val} (case-insensitive). "
                f"Received {cleaned_text}."
            )
        return cleaned_text == self.true_val.upper()

    @property
    def _type(self) -> str:
        return "boolean_output_parser"
language: str#
parse(text)#

Parse a single string model output into some structure.

Parameters:

text (str | langchain_core.messages.BaseMessage) – String output of a language model.

Returns:

Structured output.

Return type:

str

get_format_instructions()#

Instructions on how the LLM output should be formatted.

Return type:

str