Skip to content

Fields

Fields in Argilla define the content of a record that will be reviewed by a user.

Usage Examples

To define a field, instantiate the TextField class and pass it to the fields parameter of the Settings class.

text_field = rg.TextField(name="text")
markdown_field = rg.TextField(name="text", use_markdown=True)

settings = rg.Settings(
    fields=[
        text_field,
        markdown_field,
    ],
    questions=[
        rg.TextQuestion(name="response"),
    ],
)

data = rg.Dataset(
    name="my_dataset",
    settings=settings,
)

To add records with values for fields, refer to the rg.Dataset.records documentation.


TextField

Bases: SettingsPropertyBase

Text field for use in Argilla Dataset Settings

Source code in src/argilla/settings/_field.py
class TextField(SettingsPropertyBase):
    """Text field for use in Argilla `Dataset` `Settings`"""

    _model: FieldModel
    _api: FieldsAPI

    _dataset: Optional["Dataset"]

    def __init__(
        self,
        name: str,
        title: Optional[str] = None,
        use_markdown: Optional[bool] = False,
        required: bool = True,
        description: Optional[str] = None,
        client: Optional[Argilla] = None,
    ) -> None:
        """Text field for use in Argilla `Dataset` `Settings`

        Parameters:
            name (str): The name of the field
            title (Optional[str]): The name of the field, as it will be displayed in the UI.
            use_markdown (Optional[bool]): Whether to render the markdown in the UI. When True, you will be able \
                to use all the Markdown features for text formatting, including LaTex formulas and embedding multimedia content and PDFs.
            required (bool): Whether the field is required. At least one field must be required.
            description (Optional[str]): The description of the field.
        """
        client = client or Argilla._get_default()

        super().__init__(api=client.api.fields, client=client)

        self._model = FieldModel(
            name=name,
            title=title,
            required=required,
            description=description,
            settings=TextFieldSettings(use_markdown=use_markdown),
        )

        self._dataset = None

    @classmethod
    def from_model(cls, model: FieldModel) -> "TextField":
        instance = cls(name=model.name)
        instance._model = model

        return instance

    @classmethod
    def from_dict(cls, data: dict) -> "TextField":
        model = FieldModel(**data)
        return cls.from_model(model=model)

    @property
    def use_markdown(self) -> Optional[bool]:
        return self._model.settings.use_markdown

    @use_markdown.setter
    def use_markdown(self, value: bool) -> None:
        self._model.settings.use_markdown = value

    @property
    def dataset(self) -> "Dataset":
        return self._dataset

    @dataset.setter
    def dataset(self, value: "Dataset") -> None:
        self._dataset = value
        self._model.dataset_id = self._dataset.id
        self._with_client(self._dataset._client)

    def _with_client(self, client: "Argilla") -> "Self":
        # TODO: Review and simplify. Maybe only one of them is required
        self._client = client
        self._api = self._client.api.fields

        return self

__init__(name, title=None, use_markdown=False, required=True, description=None, client=None)

Text field for use in Argilla Dataset Settings

Parameters:

Name Type Description Default
name str

The name of the field

required
title Optional[str]

The name of the field, as it will be displayed in the UI.

None
use_markdown Optional[bool]

Whether to render the markdown in the UI. When True, you will be able to use all the Markdown features for text formatting, including LaTex formulas and embedding multimedia content and PDFs.

False
required bool

Whether the field is required. At least one field must be required.

True
description Optional[str]

The description of the field.

None
Source code in src/argilla/settings/_field.py
def __init__(
    self,
    name: str,
    title: Optional[str] = None,
    use_markdown: Optional[bool] = False,
    required: bool = True,
    description: Optional[str] = None,
    client: Optional[Argilla] = None,
) -> None:
    """Text field for use in Argilla `Dataset` `Settings`

    Parameters:
        name (str): The name of the field
        title (Optional[str]): The name of the field, as it will be displayed in the UI.
        use_markdown (Optional[bool]): Whether to render the markdown in the UI. When True, you will be able \
            to use all the Markdown features for text formatting, including LaTex formulas and embedding multimedia content and PDFs.
        required (bool): Whether the field is required. At least one field must be required.
        description (Optional[str]): The description of the field.
    """
    client = client or Argilla._get_default()

    super().__init__(api=client.api.fields, client=client)

    self._model = FieldModel(
        name=name,
        title=title,
        required=required,
        description=description,
        settings=TextFieldSettings(use_markdown=use_markdown),
    )

    self._dataset = None