Launch Week 3: Five days of launches

Labels

Overview

The Confident AI SDK exposes every Label method on the platform. This page documents how to call these methods in all supported languages. See the introduction to install the SDK and set your API key.

Methods

List Labels

Lists a classifier's labels one page at a time, ordered by name. This is also how you read the results of a generation run — generated suggestions arrive with status RECOMMENDED. Each label is returned as a summary row; retrieve one by id for its description and polarity. Requires the Starter plan or above.

from confident_ai import ConfidentAI

client = ConfidentAI()

result = client.classifiers.list_labels(
    classifier_id="<CLASSIFIER-ID>",
    page=1,
    page_size=25,
)

For async mode, call a_list_labels and await it as shown below:

result = await client.classifiers.a_list_labels(...)

Parameters

ParameterTypeDescription
classifier_idstrRequired. The id of the classifier.
pageOptional[int]The page to return. Defaults to 1.
page_sizeOptional[int]The number of results per page, at most 100. Defaults to 25.

Returns

This method returns an object of type ClassifierLabelList.

Create Label

Adds a label to a classifier and returns its id. The description is what the classifying model matches against, so write it as a clear statement of when the label applies rather than a restatement of the name. Label names are unique within a classifier. Requires the Starter plan or above.

from confident_ai import ConfidentAI
from confident_ai.classifiers import ClassifierLabelStatus
from confident_ai.classifiers import SignalPolarity

client = ConfidentAI()

result = client.classifiers.create_label(
    classifier_id="<CLASSIFIER-ID>",
    name="Positive",
    description="User expresses satisfaction, gratitude, or positive sentiment.",
    enabled=True,
    status=ClassifierLabelStatus.RECOMMENDED,
    polarity=SignalPolarity.HIGHER_IS_BETTER,
)

For async mode, call a_create_label and await it as shown below:

result = await client.classifiers.a_create_label(...)

Parameters

ParameterTypeDescription
classifier_idstrRequired. The id of the classifier.
namestrRequired. The name of the label, unique within the classifier.
descriptionstrRequired. When this label applies. It is the instruction the classifying model reads, so state the condition rather than restating the name.
enabledOptional[bool]Whether the label can be applied. Defaults to true.
statusOptional[ClassifierLabelStatus]See ClassifierLabelStatus.
polarityOptional[SignalPolarity]See SignalPolarity.

Returns

This method returns an object of type ClassifierLabelRef.

Get Label

Retrieves a single label on a classifier, with the description the classifying model matches against and the polarity trend reporting uses. Requires the Starter plan or above.

from confident_ai import ConfidentAI

client = ConfidentAI()

result = client.classifiers.get_label(
    classifier_id="<CLASSIFIER-ID>",
    label_id="<CLASSIFIER-LABEL-ID>",
)

For async mode, call a_get_label and await it as shown below:

result = await client.classifiers.a_get_label(...)

Parameters

ParameterTypeDescription
classifier_idstrRequired. The id of the classifier the label belongs to.
label_idstrRequired. The id of the label.

Returns

This method returns an object of type ClassifierLabel.

Update Label

Updates a label on a classifier and returns it. Only the fields you send are changed. Promoting a generated suggestion is an update to status ACTIVE, which also enables the label. Requires the Starter plan or above.

from confident_ai import ConfidentAI
from confident_ai.classifiers import ClassifierLabelStatus
from confident_ai.classifiers import SignalPolarity

client = ConfidentAI()

result = client.classifiers.update_label(
    classifier_id="<CLASSIFIER-ID>",
    label_id="<CLASSIFIER-LABEL-ID>",
    name="Positive",
    description="User expresses satisfaction, gratitude, or positive sentiment.",
    enabled=True,
    status=ClassifierLabelStatus.RECOMMENDED,
    polarity=SignalPolarity.HIGHER_IS_BETTER,
)

For async mode, call a_update_label and await it as shown below:

result = await client.classifiers.a_update_label(...)

Parameters

ParameterTypeDescription
classifier_idstrRequired. The id of the classifier the label belongs to.
label_idstrRequired. The id of the label.
nameOptional[str]The name of the label, unique within the classifier.
descriptionOptional[str]When this label applies. It cannot be cleared.
enabledOptional[bool]Whether the label can be applied. Defaults to true.
statusOptional[ClassifierLabelStatus]See ClassifierLabelStatus.
polarityOptional[SignalPolarity]See SignalPolarity.

Returns

This method returns an object of type ClassifierLabel.

Delete Label

Permanently deletes a label from a classifier and returns its id. Classifications already applied with it are not removed. This action cannot be undone. Requires the Starter plan or above.

from confident_ai import ConfidentAI

client = ConfidentAI()

result = client.classifiers.delete_label(
    classifier_id="<CLASSIFIER-ID>",
    label_id="<CLASSIFIER-LABEL-ID>",
)

For async mode, call a_delete_label and await it as shown below:

result = await client.classifiers.a_delete_label(...)

Parameters

ParameterTypeDescription
classifier_idstrRequired. The id of the classifier the label belongs to.
label_idstrRequired. The id of the label.

Returns

This method returns an object of type ClassifierLabelRef.

Types

ClassifierLabel

One label a classifier can apply to what it classifies.

class ClassifierLabel:
    id: str
    name: str
    description: str
    enabled: bool
    status: ClassifierLabelStatus
    polarity: SignalPolarity

idstrRequired

The id of the label, generated by Confident AI.

Example: "<CLASSIFIER-LABEL-ID>"

namestrRequired

The name of the label, unique within the classifier.

Example: "Positive"

descriptionstrRequired

When this label applies. This is the instruction the classifying model reads, so it states the condition rather than restating the name.

Example: "User expresses satisfaction, gratitude, or positive sentiment."

enabledboolRequired

Whether the label can be applied.

Example: true

statusClassifierLabelStatusRequired

polaritySignalPolarityRequired

ClassifierLabelList

One page of labels, with the total across all pages.

class ClassifierLabelList:
    labels: List[ClassifierLabelSummary]
    total_labels: int = Field(alias="totalLabels")
    page: int
    page_size: int = Field(alias="pageSize")

labelsList[ClassifierLabelSummary]Required

The labels for the current page, ordered by name.

See ClassifierLabelSummary.

total_labelsintRequired

The total number of labels on this classifier across all pages.

Example: 3

pageintRequired

The page this response covers.

Example: 1

page_sizeintRequired

The number of labels per page.

Example: 25

ClassifierLabelRef

A reference to a classifier label by its id.

class ClassifierLabelRef:
    id: str

idstrRequired

The id of the label, generated by Confident AI.

Example: "<CLASSIFIER-LABEL-ID>"

ClassifierLabelStatus

ACTIVE labels are in use; RECOMMENDED ones are generated suggestions awaiting review.

class ClassifierLabelStatus(Enum):
    RECOMMENDED = "RECOMMENDED"
    ACTIVE = "ACTIVE"

RECOMMENDED · ACTIVE

ClassifierLabelSummary

A label as it appears in a list: enough to triage a generated suggestion, without its description or polarity.

class ClassifierLabelSummary:
    id: str
    name: str
    enabled: bool
    status: ClassifierLabelStatus

idstrRequired

The id of the label, generated by Confident AI.

Example: "<CLASSIFIER-LABEL-ID>"

namestrRequired

The name of the label.

Example: "Positive"

enabledboolRequired

Whether the label can be applied.

Example: true

statusClassifierLabelStatusRequired

SignalPolarity

Whether more of a signal is good, bad, or neither, for trend reporting.

class SignalPolarity(Enum):
    HIGHER_IS_BETTER = "HIGHER_IS_BETTER"
    LOWER_IS_BETTER = "LOWER_IS_BETTER"
    NEUTRAL = "NEUTRAL"

HIGHER_IS_BETTER · LOWER_IS_BETTER · NEUTRAL

Building a production pipeline?Design a scalable API workflow for evals, datasets, traces, and promptsTalk to an engineer

Last updated on

Built byConfident AI