Skip to content
Judgment Labs
Esc
↑↓navigate↵open⌘Jpreview
On this page

CategoricalResponse

Response for classification-style scorers.

Subclass this and define a categories class variable listing every allowed category. The value is validated against this list.

class SentimentResponse(CategoricalResponse):
    categories = [
        Category(value="positive", description="Positive sentiment"),
        Category(value="neutral", description="Neutral sentiment"),
        Category(value="negative", description="Negative sentiment"),
    ]

class SentimentJudge(Judge[SentimentResponse]):
    async def score(self, data: Example) -> SentimentResponse:
        return SentimentResponse(
            value="positive",
            reason="The output has an enthusiastic tone.",
        )

Attributes

PropType
value?str

The selected category label.

Typestr
categories?List[Category]

Class-level list of allowed Category objects.

TypeList[Category]
reason?str
Typestr
citations?Optional[List[Citation]]
TypeOptional[List[Citation]]
DefaultNone

validate_value_in_categories()

def validate_value_in_categories():

Was this page helpful?