---
sidebar:
  hidden: true
title: roboto.domain.custom_fields.custom_field
---
## Module Contents

### CustomField

```python
class roboto.domain.custom_fields.custom_field.CustomField(
    record: roboto.domain.custom_fields.record.CustomFieldRecord,
    roboto_client: roboto.http.RobotoClient,
)
```

`from roboto.domain.custom_fields import CustomField`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/custom_fields/custom_field.py#L35-L616)

A custom field: a typed field an organization defines for one entity type, such as datasets.

Each entity of that type can hold a value for the field, set with the entity's own methods, such as [`set_custom_field()`](/docs/reference/python-sdk/roboto/domain/datasets/dataset#roboto.domain.datasets.dataset.Dataset.set_custom_field), and search can filter and sort by it. The field's `field_type` determines the values it accepts and how search can filter by it.

A field's `status` determines what can be done with it, and [`CustomFieldStatus`](/docs/reference/python-sdk/roboto/domain/custom_fields/record#roboto.domain.custom_fields.record.CustomFieldStatus) describes each status. A new field is `Creating` while Roboto sets it up, and cannot hold values or be searched until it is `Ready`. A deleted field is `Deleting` until Roboto removes it. `create` and `delete` return before Roboto finishes; `wait_to_be_ready` and `wait_to_be_deleted` wait until it has.

A field's name is unique among its organization's fields for its entity type. Each organization can define a limited number of custom fields for each entity type; fields being deleted do not count toward the limit.

Get a `CustomField` from `create`, `from_id`, `from_name_and_entity_type`, or `list`. To wrap a [`CustomFieldRecord`](/docs/reference/python-sdk/roboto/domain/custom_fields/record#roboto.domain.custom_fields.record.CustomFieldRecord) already fetched from Roboto, build a `CustomField` from it directly. Each instance holds a copy of the field's record: methods that change the field update that copy from Roboto's response, and `refresh` fetches changes made elsewhere.

**Parameters**

- **record** (`roboto.domain.custom_fields.record.CustomFieldRecord`): Record of the custom field.
- **roboto_client** (`roboto.http.RobotoClient`): Client to make requests to Roboto with.

**Properties**

- **CustomField.created** (`datetime.datetime`): Time the custom field was created.

- **CustomField.created_by** (`str`): Principal that created the custom field, as `<type>:<id>`, such as `user:<user_id>`.

- **CustomField.description** (`str | None`): Human-readable description of the custom field, or `None` if it has none.

  Return type: `Optional[str]`

- **CustomField.display_name** (`str | None`): Human-readable label of the custom field, or `None` if it has none.

  Return type: `Optional[str]`

- **CustomField.entity_type** (`roboto.domain.custom_fields.record.TargetEntityType`): Kind of entity the custom field applies to. Fixed when the field is created.

- **CustomField.field_id** (`str`): Unique ID of the custom field, beginning with `cf_`.

- **CustomField.field_name** (`str`): Name of the custom field, unique among its organization's fields for its entity type.

  Fixed when the field is created.

- **CustomField.field_type** (`roboto.domain.custom_fields.record.CustomFieldType`): Value type of the custom field. Fixed when the field is created.

- **CustomField.last_error** (`str | None`): Human-readable reason the custom field's most recent create or delete failed, or `None`.

  Set when `status` becomes [`Failed`](/docs/reference/python-sdk/roboto/domain/custom_fields/record#roboto.domain.custom_fields.record.CustomFieldStatus.Failed), and cleared when the field is deleted. Roboto sets it; no request does.

  Return type: `Optional[str]`

- **CustomField.metadata_path** (`str | None`): Unused.

  [`metadata_path`](/docs/reference/python-sdk/roboto/domain/custom_fields/record#roboto.domain.custom_fields.record.CustomFieldRecord.metadata_path) says why it is always `None`.

  Return type: `Optional[str]`

- **CustomField.modified** (`datetime.datetime`): Time the custom field was last modified.

- **CustomField.modified_by** (`str`): Principal that last modified the custom field, in the same `<type>:<id>` form as `created_by`.

  [`modified_by`](/docs/reference/python-sdk/roboto/domain/custom_fields/record#roboto.domain.custom_fields.record.CustomFieldRecord.modified_by) says when it is Roboto's own system user.

- **CustomField.options** (`roboto.domain.custom_fields.record.CustomFieldOptions | None`): Type-specific configuration of the custom field.

  [`options`](/docs/reference/python-sdk/roboto/domain/custom_fields/record#roboto.domain.custom_fields.record.CustomFieldRecord.options) says which field types set it.

  Return type: `Optional[roboto.domain.custom_fields.record.CustomFieldOptions]`

- **CustomField.org_id** (`str`): ID of the organization that owns the custom field.

- **CustomField.status** (`roboto.domain.custom_fields.record.CustomFieldStatus`): Lifecycle state of the custom field, which determines what can be done with it.

#### CustomField.add_enum_values()

```python
def add_enum_values(*values: str) -> CustomField
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/custom_fields/custom_field.py#L485-L523)

Add values to the set this enum field accepts.

Fetches the field's current values first, so that the update lists every value the field has, including any added since this instance was loaded: `update` rejects options that leave one out. Called with no values, it returns without making a request. The failures of `refresh` and `update` also apply.

**Parameters**

- **`\*values`**: Values to accept, in addition to the field's current ones. Each is normalized as [`options`](/docs/reference/python-sdk/roboto/domain/custom_fields/operations#roboto.domain.custom_fields.operations.CreateCustomFieldRequest.options) describes, and one that the field already has, once normalized, changes nothing. A field may hold at most 250 values.
- **values** (`str`)

**Returns**

- `CustomField`: This instance, with its record updated from Roboto's response.

**Raises**

- [`RobotoConflictException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoConflictException): Another update changed the field's options between this method's fetch and its update.
- [`RobotoInvalidRequestException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInvalidRequestException): This field is not an enum field.

**Usage**

```python
field.options.enum_values
# ['low', 'medium', 'high']
field.add_enum_values("critical").options.enum_values
# ['low', 'medium', 'high', 'critical']
```

#### CustomField.create()

```python
@classmethod
def create(
    field_name: str,
    field_type: roboto.domain.custom_fields.record.CustomFieldType,
    entity_type: roboto.domain.custom_fields.record.TargetEntityType,
    display_name: Optional[str] = None,
    description: Optional[str] = None,
    options: Optional[roboto.domain.custom_fields.record.CustomFieldOptions] = None,
    metadata_path: Optional[str] = None,
    caller_org_id: Optional[str] = None,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
) -> CustomField
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/custom_fields/custom_field.py#L65-L154)

Create a custom field for one entity type.

Returns while the field is still [`Creating`](/docs/reference/python-sdk/roboto/domain/custom_fields/record#roboto.domain.custom_fields.record.CustomFieldStatus.Creating): it cannot hold values or be searched until Roboto finishes setting it up, which `wait_to_be_ready` waits for. Only an administrator of the organization can create a custom field.

**Parameters**

- **field_name** (`str`): Name of the custom field, unique among the organization's fields for `entity_type` and fixed once the field is created. Must match `^[a-z][a-z0-9_]{0,62}$` ([`CUSTOM_FIELD_NAME_PATTERN`](/docs/reference/python-sdk/roboto/domain/custom_fields/record#roboto.domain.custom_fields.record.CUSTOM_FIELD_NAME_PATTERN)): a lowercase ASCII letter, then up to 62 lowercase ASCII letters, digits, or underscores.
- **field_type** (`roboto.domain.custom_fields.record.CustomFieldType`): Value type of the custom field, which determines the values it accepts and how search can filter by it.
- **entity_type** (`roboto.domain.custom_fields.record.TargetEntityType`): Kind of entity the custom field applies to.
- **display_name** (`Optional[str]`): Human-readable label for the custom field, shown in the Roboto web app, at most 128 characters. `None` sets none.
- **description** (`Optional[str]`): Human-readable description of the custom field, at most 256 characters. `None` sets none.
- **options** (`Optional[roboto.domain.custom_fields.record.CustomFieldOptions]`): Type-specific configuration. Required for an enum field, to declare its allowed values, which are normalized as [`options`](/docs/reference/python-sdk/roboto/domain/custom_fields/operations#roboto.domain.custom_fields.operations.CreateCustomFieldRequest.options) describes. `None` for every other field type.
- **metadata_path** (`Optional[str]`): Reserved for future use. Leave it `None`: Roboto rejects any other value.
- **caller_org_id** (`Optional[str]`): Organization to create the custom field in. Required when the caller belongs to more than one organization; otherwise the caller's only organization.
- **roboto_client** (`Optional[roboto.http.RobotoClient]`): Client to make requests to Roboto with. Defaults to one configured from the environment, by [`from_env()`](/docs/reference/python-sdk/roboto/http/roboto_client#roboto.http.roboto_client.RobotoClient.from_env).

**Returns**

- `CustomField`: The new custom field, with status `Creating`.

**Raises**

- [`RobotoConflictException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoConflictException): The organization already has a custom field with this name for `entity_type`.
- [`RobotoInvalidRequestException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInvalidRequestException): `field_name` is a name Roboto reserves, or `metadata_path` is set.
- [`RobotoLimitExceededException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoLimitExceededException): The organization already has as many custom fields for `entity_type` as it is allowed.
- [`RobotoUnauthorizedException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoUnauthorizedException): The caller is not an administrator of the organization.
- `pydantic.ValidationError`: `field_name` does not match the pattern, an enum field has no `options`, `options` are for a different field type, or a value breaks a rule that [`CreateCustomFieldRequest`](/docs/reference/python-sdk/roboto/domain/custom_fields/operations#roboto.domain.custom_fields.operations.CreateCustomFieldRequest) states. Raised before the request is sent.

**Usage**

Create a string field on datasets:

```python
field = CustomField.create(
    field_name="flight_id",
    field_type=CustomFieldType.String,
    entity_type=TargetEntityType.Dataset,
    display_name="Flight ID",
)
field.wait_to_be_ready()
```

Create an enum field with a fixed set of allowed values:

```python
from roboto.domain.custom_fields import EnumFieldOptions
field = CustomField.create(
    field_name="severity",
    field_type=CustomFieldType.Enum,
    entity_type=TargetEntityType.Event,
    options=EnumFieldOptions(enum_values=["low", "medium", "high"]),
)
```

#### CustomField.delete()

```python
def delete() -> None
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/custom_fields/custom_field.py#L375-L394)

Delete this custom field.

Returns once Roboto has moved the field to [`Deleting`](/docs/reference/python-sdk/roboto/domain/custom_fields/record#roboto.domain.custom_fields.record.CustomFieldStatus.Deleting): from then on, values can no longer be set on it, and `list` leaves it out by default. Roboto then removes the field; `wait_to_be_deleted` waits until it has. Deleting a custom field that is already being deleted, or that no longer exists, succeeds and changes nothing. Only an administrator of the field's organization can delete it.

This instance's `status` is not updated; `refresh` fetches it.

**Raises**

- [`RobotoUnauthorizedException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoUnauthorizedException): The caller is not an administrator of the field's organization.

**Returns**

- `None`

**Usage**

```python
field = CustomField.from_name_and_entity_type("flight_id", TargetEntityType.Dataset)
field.delete()
field.wait_to_be_deleted()
```

#### CustomField.from_id()

```python
@classmethod
def from_id(
    field_id: str,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
) -> CustomField
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/custom_fields/custom_field.py#L157-L176)

Fetch a custom field by its ID.

**Parameters**

- **field_id** (`str`): ID of the custom field, beginning with `cf_`.
- **roboto_client** (`Optional[roboto.http.RobotoClient]`): Client to make requests to Roboto with. Defaults to one configured from the environment, by [`from_env()`](/docs/reference/python-sdk/roboto/http/roboto_client#roboto.http.roboto_client.RobotoClient.from_env).

**Raises**

- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): No custom field has this ID.

**Returns**

- `CustomField`

**Usage**

```python
field = CustomField.from_id("cf_12345")
print(field.field_name)
```

#### CustomField.from_name_and_entity_type()

```python
@classmethod
def from_name_and_entity_type(
    field_name: str,
    entity_type: roboto.domain.custom_fields.record.TargetEntityType,
    owner_org_id: Optional[str] = None,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
) -> CustomField
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/custom_fields/custom_field.py#L179-L216)

Fetch a custom field by its name and entity type.

A name is unique among an organization's fields for one entity type, so the name, the entity type, and the organization identify one field.

**Parameters**

- **field_name** (`str`): Name of the custom field.
- **entity_type** (`roboto.domain.custom_fields.record.TargetEntityType`): Kind of entity the custom field applies to.
- **owner_org_id** (`Optional[str]`): Organization that owns the custom field. Defaults to the organization the caller acts in.
- **roboto_client** (`Optional[roboto.http.RobotoClient]`): Client to make requests to Roboto with. Defaults to one configured from the environment, by [`from_env()`](/docs/reference/python-sdk/roboto/http/roboto_client#roboto.http.roboto_client.RobotoClient.from_env).

**Raises**

- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): The organization has no custom field with this name for `entity_type`.

**Returns**

- `CustomField`

**Usage**

```python
field = CustomField.from_name_and_entity_type(
    field_name="flight_id",
    entity_type=TargetEntityType.Dataset,
)
```

#### CustomField.list()

```python
@classmethod
def list(
    entity_type: Optional[roboto.domain.custom_fields.record.TargetEntityType] = None,
    statuses: Optional[collections.abc.Sequence[roboto.domain.custom_fields.record.CustomFieldStatus]] = None,
    owner_org_id: Optional[str] = None,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
) -> collections.abc.Generator[CustomField, None, None]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/custom_fields/custom_field.py#L219-L275)

List an organization's custom fields, optionally limited to one entity type and some statuses.

Fetches the fields a page at a time as the generator is consumed.

**Parameters**

- **entity_type** (`Optional[roboto.domain.custom_fields.record.TargetEntityType]`): Kind of entity to list custom fields for. `None` lists the fields for every entity type.
- **statuses** (`Optional[collections.abc.Sequence[roboto.domain.custom_fields.record.CustomFieldStatus]]`): Statuses of the custom fields to list. `None` or an empty sequence lists the fields whose [`CustomFieldStatus`](/docs/reference/python-sdk/roboto/domain/custom_fields/record#roboto.domain.custom_fields.record.CustomFieldStatus) is `Creating`, `Ready`, or `Failed`, leaving out those being deleted.
- **owner_org_id** (`Optional[str]`): Organization whose custom fields to list. Defaults to the organization the caller acts in.
- **roboto_client** (`Optional[roboto.http.RobotoClient]`): Client to make requests to Roboto with. Defaults to one configured from the environment, by [`from_env()`](/docs/reference/python-sdk/roboto/http/roboto_client#roboto.http.roboto_client.RobotoClient.from_env).

**Yields**

- Custom fields that match `entity_type` and `statuses`.

**Returns**

- `collections.abc.Generator[CustomField, None, None]`

**Usage**

List the ready custom fields on datasets:

```python
for field in CustomField.list(
    entity_type=TargetEntityType.Dataset,
    statuses=[CustomFieldStatus.Ready],
):
    print(field.field_name, field.field_type)
```

#### CustomField.refresh()

```python
def refresh() -> CustomField
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/custom_fields/custom_field.py#L396-L411)

Replace this instance's record with the custom field's current record from Roboto.

Use it to see the status changes Roboto makes after the field is created or deleted.

**Returns**

- `CustomField`: This instance, with its record updated from Roboto's response.

**Raises**

- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): Roboto has finished deleting the field.

**Usage**

```python
print(field.refresh().status)
```

#### CustomField.update()

```python
def update(
    display_name: Union[str, None, roboto.sentinels.NotSetType] = NotSet,
    description: Union[str, None, roboto.sentinels.NotSetType] = NotSet,
    options: Union[roboto.domain.custom_fields.record.CustomFieldOptions, roboto.sentinels.NotSetType] = NotSet,
) -> CustomField
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/custom_fields/custom_field.py#L413-L483)

Update this custom field's display name, description, or options.

An argument left unset (`NotSet`, the default) leaves that value unchanged. Roboto updates only a field whose status is [`Ready`](/docs/reference/python-sdk/roboto/domain/custom_fields/record#roboto.domain.custom_fields.record.CustomFieldStatus.Ready). Only an administrator of the field's organization can update it.

**Parameters**

- **display_name** (`Union[str, None, roboto.sentinels.NotSetType]`): Human-readable label for the custom field, shown in the Roboto web app, at most 128 characters. `None` clears it, as does text that is blank once surrounding whitespace is stripped.
- **description** (`Union[str, None, roboto.sentinels.NotSetType]`): Human-readable description of the custom field, at most 256 characters. `None` clears it, as does text that is blank once surrounding whitespace is stripped.
- **options** (`Union[roboto.domain.custom_fields.record.CustomFieldOptions, roboto.sentinels.NotSetType]`): Type-specific configuration to replace the field's own, for this field's `field_type`. For an enum field, `enum_values` must include every value the field already has: values can be added but not removed. Values are normalized as [`options`](/docs/reference/python-sdk/roboto/domain/custom_fields/operations#roboto.domain.custom_fields.operations.CreateCustomFieldRequest.options) describes, and a value that repeats one the field already has is dropped rather than rejected. `add_enum_values` adds values without listing the existing ones.

**Returns**

- `CustomField`: This instance, with its record updated from Roboto's response.

**Raises**

- [`RobotoConflictException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoConflictException): `options` is set, and another update changed the field's options while this one was in progress. Refresh the field and try again.
- [`RobotoInvalidRequestException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInvalidRequestException): The field is not `Ready`, `options` are for a different field type, or `options` would remove an existing enum value.
- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): The field no longer exists.
- [`RobotoUnauthorizedException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoUnauthorizedException): The caller is not an administrator of the field's organization.
- `pydantic.ValidationError`: `display_name` or `description` is too long, an enum value cannot be stored, or `enum_values` holds more than 250 distinct values. Raised before the request is sent.

**Usage**

Change the field's display name:

```python
field.update(display_name="Flight identifier")
```

Add a value to an enum field:

```python
from roboto.domain.custom_fields import EnumFieldOptions
field.update(options=EnumFieldOptions(enum_values=[*field.options.enum_values, "critical"]))
```

Re-send a value the field already has: it keeps its place, and only the new value is appended:

```python
field.options.enum_values
# ['low', 'medium', 'high']
updated = field.update(
    options=EnumFieldOptions(enum_values=[*field.options.enum_values, "medium", "critical"])
)
updated.options.enum_values
# ['low', 'medium', 'high', 'critical']
```

Clear the description:

```python
field.update(description=None)
```

#### CustomField.wait_to_be_deleted()

```python
def wait_to_be_deleted(timeout: float = 5 * 60, poll_interval: int = 2) -> None
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/custom_fields/custom_field.py#L576-L616)

Wait until Roboto has finished deleting this custom field, refreshing this instance's record as it polls.

Call it after `delete`.

**Parameters**

- **timeout** (`float`): Maximum time to wait, in seconds.
- **poll_interval** (`int`): Seconds to wait between polls.

**Raises**

- [`RobotoInvalidStateTransitionException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInvalidStateTransitionException): The field's [`CustomFieldStatus`](/docs/reference/python-sdk/roboto/domain/custom_fields/record#roboto.domain.custom_fields.record.CustomFieldStatus) is `Creating`, `Ready`, or `Failed`: either it was never deleted, or its deletion failed.
- [`roboto.waiters.TimeoutError`](/docs/reference/python-sdk/roboto/waiters#roboto.waiters.TimeoutError): The field was still `Deleting` after `timeout` seconds. It subclasses the built-in `TimeoutError`.

**Returns**

- `None`

**Usage**

```python
field.delete()
field.wait_to_be_deleted()
```

#### CustomField.wait_to_be_ready()

```python
def wait_to_be_ready(timeout: float = 5 * 60, poll_interval: int = 2) -> None
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/custom_fields/custom_field.py#L525-L574)

Wait until this custom field is `Ready`, refreshing this instance's record as it polls.

Call it after `create`: a field can hold values and be searched once its [`CustomFieldStatus`](/docs/reference/python-sdk/roboto/domain/custom_fields/record#roboto.domain.custom_fields.record.CustomFieldStatus) is `Ready`.

**Parameters**

- **timeout** (`float`): Maximum time to wait, in seconds.
- **poll_interval** (`int`): Seconds to wait between polls.

**Raises**

- [`RobotoInvalidStateTransitionException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInvalidStateTransitionException): The field is or becomes `Failed` or `Deleting`, or is deleted, so it will not become `Ready`.
- [`roboto.waiters.TimeoutError`](/docs/reference/python-sdk/roboto/waiters#roboto.waiters.TimeoutError): The field was still `Creating` after `timeout` seconds. It subclasses the built-in `TimeoutError`.

**Returns**

- `None`

**Usage**

```python
field = CustomField.create(
    field_name="flight_id",
    field_type=CustomFieldType.String,
    entity_type=TargetEntityType.Dataset,
)
field.wait_to_be_ready()
field.status
# <CustomFieldStatus.Ready: 'ready'>
```
