# Label Sets / Question Sets

## Span-based Labeling

For span-based labeling, a label set is a single-column `.csv` following the structure below:

| Column 1 |
| -------- |
| Label 1  |
| Label 2  |
| Label 3  |
| etc...   |

{% file src="<https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-69124721502441b1244dbef01211a7bb1df85388%2FDatasaur%20sample%20-%20Span%20label%20set.csv?alt=media>" %}
NER label set
{% endfile %}

We provide twelve colors you can configure manually from the [Labels](https://datasaurai.gitbook.io/datasaur/advanced/extensions/labels) extension. You can also create a label set with your desired label colors in it. A sample file is provided below. Note: we do support any HTML color codes (as seen below).

* Note: `label,color` is the header. This will always be the first row in the .csv.

{% file src="<https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-9e041c496fc020e975a00cec69b094111c749092%2FDatasaur%20sample%20-%20Colored%20label%20set.csv?alt=media>" %}
Colored label set
{% endfile %}

```
label,color
Annabeth Chase,#df3920
Harry Potter,#ff8000
Hermione Granger,#4db34d
John Watson,#3399cc
Percy Jackson,#cc3399
Sherlock Holmes,#9933cc
```

*Note: colored label sets only work for the `.csv` format.*

### Color-coded Labels

Datasaur supports HTML color codes. For your reference, below are the default colors provided by Datasaur for better viewing clarity in your project.

![Label Color Palette](https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-f4a0ae6eaea476844cd0abad402d5fbdd01a96f2%2FLabel%20set%20question%20set%20-%20Color-coded%20Labels.png?alt=media)

### Limit Selection to Bottom-level Labels Only

In projects with hierarchical label structures, some labels serve as broad categories while others act as bottom-level classifications. This setting ensures precise data annotation by restricting selection to only bottom-level labels—those without child labels. It prevents the use of broad categories, reducing ambiguity and improving consistency in labeled data.

#### When to Use?

This setting is particularly useful for projects that require detailed and specific classification, ensuring that only the most precise labels are applied.

Here are the example use cases for the food categorization:

* **Fruit**
  * Apple
  * Banana
* **Vegetable**
  * Carrot
  * Spinach

With this setting enabled, labelers can only select **Apple, Banana, Carrot, and Spinach**, but not the broader categories **Fruit** or **Vegetable**.

#### How to Configure the Setting

This setting can be enabled when creating a new project, modifying an existing one, or managing label set templates.

**Project Creation Wizard**

1. Create new project.
2. Go to Step 3 and select Span labeling.
3. In the Label Set section, click the triple-dot menu on the label set you want to modify and enable the setting.

![](https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-03758bd51da541aeb43d5ce0e4d62f484e4f68da%2FPCW%20-%20step%203%20-%20span%20labeling%20-%20limit%20selection%20to%20bottom-level%20labels%20only.png?alt=media)

**Within the Project**

1. Open Labels extension and select the label set.
2. Click the triple-dot menu and choose one of the following:
   1. Add new label set.
   2. Replace existing label set.
   3. Edit label set.
3. Expand the Label set settings accordion and enable the setting.

![](https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-48d8bdd02bd0e15d2d8e67635ee17d31e1c5e720%2FLabel%20management%20-%20label%20sets%20-%20edit%20label%20set%20-%20label%20set%20settings.png?alt=media)

**Label Management**

1. Navigate to Label management page.
2. Select Add label set or update the existing label set.
3. Expand Label set settings accordion and enable the setting.

![](https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-b3b91399fec8ce2d54f7e177f6fad80aa7d6b2d5%2FLabel%20management%20-%20label%20sets%20-%20create%20new%20-%20label%20set%20settings.png?alt=media)

#### Labeling Behavior

Once this setting is enabled, label selection will be limited to bottom-level labels. This means:

* Only bottom-level labels can be selected.
* Parent labels with child labels will no longer be selectable.
* Keyboard shortcuts (numbers, arrow keys, Enter) will apply only to bottom-level labels.

## Bounding Box Labeling

### **Label Sets**

You can utilize `.csv`, `.tsv`, or `.json` formats for the bounding box label set.

* For `.csv/.tsv`, we support **color names** (e.g., red), **hex values** (e.g., #00FF00), and **RGB** (e.g., rgb(0,0,255)). You can also utilize the label set with just names, as shown in the *Datasaur sample - Bbox only name.csv* below. Other values such as captionAllowed and captionRequired will use default settings.
* For `.json`, we support **hex** and **RGB** only.

{% file src="<https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-a4f20524f984c1d79ba74fc5d8dd80507b67c806%2FDatasaur%20sample%20-%20Bbox.json?alt=media&token=7ebe275b-400c-47bc-817a-4d33cf0f4233>" %}

{% file src="<https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-f2d0f1560204e0a4465263cc363345aa1ad43228%2FDatasaur%20sample%20-%20Bbox%20only%20name.csv?alt=media>" %}

{% file src="<https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-4d1867e1a67107203d6698742a5f4b0c293993b2%2FDatasaur%20sample%20-%20Bbox%20with%20header%20(1).csv?alt=media>" %}

{% file src="<https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-0b470732bcb221c303aaa67947b6fe7aa0cc6e11%2FDatasaur%20sample%20-%20Bbox%20(without%20header).csv?alt=media>" %}

{% file src="<https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-69ba05b9efc1777d55913df7b0573e7a26e97e43%2FDatasaur%20sample%20-%20Bbox%20(with%20custom%20attributes).json?alt=media&token=90cc68ec-fe43-46be-bba1-7908bef08849>" %}

### **Text Transcription**

The **Text Transcription setting** allows the labeler to add corresponding text to a bounding box. Disabling this setting means the labeler could not add the text.

<figure><img src="https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-0bc6659b0291bc95c1e2926695a7ff0040afb33a%2Fimage%20(1).png?alt=media&#x26;token=55687192-c85a-4bf4-aa44-ad0d24ca4fa2" alt=""><figcaption></figcaption></figure>

### **Require caption**

By turning on the Text Transcription setting, the labeler can add text to a bounding box. You can choose whether a specific label must have a text by disabling or enabling the **Require caption** checkbox.

<figure><img src="https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-2ca83c3ddf4931800685755dd270de301f00300c%2FPCW%20-%20step%203%20-%20bounding%20box%20labeling%20-%20labels%20added.png?alt=media" alt=""><figcaption></figcaption></figure>

## Row-based/Document-based Labeling

For row-based or document-based projects, a label set is a `.csv` with questions in the first column and answers in subsequent columns:

| Column 1   | Column 2 | Column 3 | Column 4. |          |          |
| ---------- | -------- | -------- | --------- | -------- | -------- |
| Question 1 | Answer 1 | Answer 2 | Answer 3  |          |          |
| Question 2 | Answer 1 | Answer 2 |           |          |          |
| Question 3 | Answer 1 | Answer 2 | Answer 3  | Answer 4 | Answer 5 |

{% file src="<https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-c17d31fe5ff64883ffb1b68cb2237c8a8b878a4e%2FDatasaur%20sample%20-%20Question%20set%20(simple).csv?alt=media>" %}
Question set that only contain dropdown question type
{% endfile %}

You can also create a `.json` for a label set that has multiple question types.

{% file src="<https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-885450111e49d9aa67aa4e8bb5da61029f4ebf21%2FAccepted%20Format%20Question%20Set%20(1).json?alt=media>" %}
Complex question set
{% endfile %}

### Question Hint

![](https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-09396e7516f8ce1240a0e4c3e7cbbe54053dfe77%2FExtension%20-%20document%20labeling%20-%20question%20hint.png?alt=media)

You can optionally set hints for each question. You can include additional instructions or explanations in the questions’ hint, which can help labelers in submitting answers most relevant to the task. You can set a text of up to around 65,000 characters for a single question’s hint.

Question hints can be set during project creation or when configuring a question set on [**Label management**](https://docs.datasaur.ai/workspace-management/label-management/question-set-management) page.

![Setting question hint in project creation](https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-c25e09339e05778a1c8a3ebdcb3cb3a0a4524bb4%2FPCW%20-%20step%203%20-%20Document%20labeling%20-%20question%20hint.png?alt=media)

![Setting question hint from Label management](https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-1006e42bf966ca85e19d9fb67ad909658397a46e%2FLabel%20management%20-%20question%20set%20-%20text%20field%20-%20question%20hint.png?alt=media)

#### Supported Format

The [Document and Row Labeling](https://docs.datasaur.ai/advanced/extensions/document-and-row-labeling) extensions are able to parse markdown syntaxes in question hints. This gives you flexibility in formatting the text; enabling you to present lists, attach links to external sites, or emphasize certain parts of the hint, all using a familiar set of syntaxes. The following are examples of the supported formatting.

| Formatting                   | Syntax                               |
| ---------------------------- | ------------------------------------ |
| **Bold**                     | **your text**                        |
| *Italic*                     | *your text*                          |
| Underline                    | \<u>your text\</u>                   |
| • Bullet                     | dashes (-) or asterisks (\*)         |
| 1. Numbering                 | 1., 2., 3., etc.                     |
| [Link](https://example.com/) | \[your text] (<https://example.com>) |

{% hint style="info" %}
Keep in mind, the markdown symbols will count towards the character limit.
{% endhint %}

#### Best Practices

We recommend keeping hints brief and focused on the relevant information for the labelers’ task. Longer hints may appear as large text blocks, which can clutter the UI. For more complex information or media, consider including links that labelers can easily click on.

![Setting the hint with link markdown syntax](https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-8aa6e31a2f027dc0b1bb6747431116d22eb4f11e%2FLabel%20management%20-%20question%20set%20-%20dropdown%20-%20question%20hint%20-%20best%20practice.png?alt=media)

![How the link will be shown in the labeling extension UI](https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-8e063004144b602150ab5cd4bc93d1ccc7c02fd9%2FExtension%20-%20Document%20labeling%20-%20dropdown%20-%20question%20hint%20-%20best%20practice.png?alt=media)

### Question Types

As mentioned before, label sets for row-based and document-based projects are sets of questions. Let's take a look at the question types available below.

#### **1.** Text Field

**Text Field** allows the labeler to answer questions by typing in free-form text, up to a single line at a time.

<figure><img src="https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-a701d236ab16fe7c45df5ce464d9b1278dc28fbb%2FQuestion%20set%20-%20question%20type%20-%20text%20field.png?alt=media" alt=""><figcaption></figcaption></figure>

Users also can add some validation by expanding the Advanced Settings.

<figure><img src="https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-489ad19758f0fdcefee606376bf70c1e061b075a%2FQuestion%20set%20-%20editor%20-%20text%20field.png?alt=media" alt=""><figcaption></figcaption></figure>

#### **2. Text Area**

**Text Area** allows the labeler to answer questions by typing in free-form text. In contrast to Text Fields, this allows for multiple-line answers.

<figure><img src="https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-6b8122f47aacbfe297cf3afe3f56081cb66b64d7%2FQuestion%20set%20-%20question%20type%20-%20text%20area.png?alt=media" alt=""><figcaption></figcaption></figure>

#### **3. Dropdown**

**Dropdown** requires labelers to answer questions by picking one of several multiple-choice answers.

<figure><img src="https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-d803204279fa89163093a56a72e98b119870b1e8%2FQuestion%20set%20-%20question%20type%20-%20dropdown.png?alt=media" alt=""><figcaption></figcaption></figure>

* If you have a .csv with a pre-set list of answers, you can upload the `.csv` as an **answer set**.

<figure><img src="https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-f81c8f2ad65295628d4d7ca81530f2a7b43ee710%2FQuestion%20set%20-%20editor%20-%20dropdown.png?alt=media" alt=""><figcaption></figcaption></figure>

{% file src="<https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-3be115773ecc4a4cca33c1203217fef30233c927%2FDatasaur%20sample%20-%20Question%20set%20(book%20genre).csv?alt=media>" %}
Book genre question set
{% endfile %}

* You can also allow the labelers to select multiple answers by checking the box for **Allow multiple choices.**

<figure><img src="https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-3555ad79ca756f4b7a05e70d1b938ec2a6766f69%2FQuestion%20set%20-%20editor%20-%20dropdown%20-%20options%20added.png?alt=media" alt=""><figcaption><p>In Step 3</p></figcaption></figure>

#### **4. Hierarchical Dropdown**

**Hierarchical dropdown** allows the labeler to answer questions with hierarchically organized options.

<figure><img src="https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-de88da90bf18f8024e41640c1ba44d8fd4369e19%2FQuestion%20set%20-%20question%20type%20-%20hierarchical%20dropdown.png?alt=media" alt=""><figcaption></figcaption></figure>

* Just like with the Dropdown type, you can also upload an answer set once you have created the hierarchical question. The format for hierarchical label sets can be [found below](https://datasaurai.gitbook.io/datasaur/nlp-projects/lets-get-labeling/label-sets#hierarchical-label-sets).

#### 5. True/False

{% hint style="info" %}
Previously known as the **Yes/No**, this question type has now been renamed to **True/False.**
{% endhint %}

**True/False** allows the labelers to answer the question by checking it. You can also put a description.

<figure><img src="https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-8841d51277995ffabd9ad8401ca0577ad1a87c03%2FQuestion%20set%20-%20question%20type%20-%20True%20or%20false.png?alt=media" alt=""><figcaption></figcaption></figure>

#### 6. Single Choice

{% hint style="info" %}
Previously known as the **Radio Button**, this question type has now been renamed to **Single Choice**.
{% endhint %}

**Single Choice** allows the labeler to answer questions by selecting one answer.

<figure><img src="https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-f305e0e5f8c40b99734c7b303ce131a1cb7b548f%2FQuestion%20set%20-%20question%20type%20-%20%20Single%20choice.png?alt=media" alt=""><figcaption></figcaption></figure>

You can configure up to 25 answer options for this question type. You can also insert a **hint** to give a description of the Single Choice.

<figure><img src="https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-e279528884e3524175c1852f8b4292b6dd69580d%2FQuestion%20set%20-%20editor%20-%20Single%20choice.png?alt=media" alt=""><figcaption><p>Single Choice Question Type</p></figcaption></figure>

#### 7. Multiple Choice

**Multiple Choice** allows the labeler to submit multiple answers by selecting more than one option from a list, or they can choose just one option if necessary.

![A multiple choice question](https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-7002ac063dee3c5087480743dbaa502bd0eccb78%2FQuestion%20set%20-%20question%20type%20-%20Multiple%20choice.png?alt=media)

The options are displayed as a staggered grid of checkboxes, making it more suitable for a smaller and simpler set of options. You can configure up to 25 answer options for this question type.

#### **8. Date**

**Date** allows the labeler to answer the question in two ways. The key benefit of selecting **Date** is that this format validates that a correct date has been filled in.

* Typing the date in manually.
* Clicking on the calendar symbol, then selecting the date.

<figure><img src="https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-149b1accf391c57acb739855653ba2cf727302a0%2FQuestion%20set%20-%20question%20type%20-%20Date.png?alt=media" alt=""><figcaption></figcaption></figure>

If you want to fill date questions with the current timestamp at the time the labeler opens the project, you can check the **Use current date as default value** box on Step 3.

<figure><img src="https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-8b8ec07d3400af84aaaf8491b088496ff4afdf86%2FQuestion%20set%20-%20editor%20-%20Date.png?alt=media" alt=""><figcaption></figcaption></figure>

#### **9. Time**

**Time** allows the labeler to answer the question in two ways. The key benefit of selecting **Time** is that this format validates that a correct time has been filled in.

* Typing it manually.
* Clicking on the clock symbol, then selecting the time.

<figure><img src="https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-f5c7c08644a0193b177c5a60a0c5af430d392147%2FQuestion%20set%20-%20question%20type%20-%20Time.png?alt=media" alt=""><figcaption></figcaption></figure>

If you want to fill time questions with the current timestamp at the time the labeler opens the project, you can check the **Use current time as default value** box on Step 3.

<figure><img src="https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-6fbaf99ec1f3d6410dd98a37a01d9d7cac2f68de%2FQuestion%20set%20-%20editor%20-%20Time.png?alt=media" alt=""><figcaption></figcaption></figure>

#### **10. Slider**

**Slider** allows the labeler to answer the question by moving the sliding bar (ex: from 1 to 10).

<figure><img src="https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-28efe78df636f669ce8df23f5d60f31b83d0bda1%2FQuestion%20set%20-%20question%20type%20-%20Slider.png?alt=media" alt=""><figcaption></figcaption></figure>

To avoid subjective measurement, you can also hide the value from labelers in Step 3. Please note that the value will be visible in the reviewer mode.

<figure><img src="https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-0f6e3b6c7192d5b8e599e34938c1a6713f2e833c%2FQuestion%20set%20-%20editor%20-%20Slider.png?alt=media" alt=""><figcaption></figcaption></figure>

You have the flexibility to personalize the slider color according to your preferences. While the default color for “Start at” and “End to” is blue, we provide 11 alternative default color options for you to select from.

<figure><img src="https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-415eb99e3017628b3310ecb8b33e0db590750113%2FQuestion%20set%20-%20editor%20-%20slider%20-%20color%20menu.png?alt=media" alt=""><figcaption></figcaption></figure>

When it comes to colors, you have the choice of using [hex codes, color names, or RGB values](https://developer.mozilla.org/en-US/docs/Web/CSS/named-color). If you opt for any of these choices, the dropdown will be labeled as “Custom”.

To get a glimpse of how the color will appear, simply drag the slider thumb on the Preview.

<figure><img src="https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-47ea5ea651f5d17fd079ccab24a9aae30172cda2%2FQuestion%20set%20-%20editor%20-%20slider%20-%20color%20preview.png?alt=media" alt=""><figcaption></figcaption></figure>

When you change the **minimum** or **maximum value** of a slider question, any existing answers outside the new range will trigger a message in the Row/Document Labeling extension. This message appears automatically when users open the affected row or document, ensuring answers stay within the updated range.

{% file src="<https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-29566e24acb0195136786cdb846390355dcedd3b%2FDatasaur%20sample%20-%20Question%20set%20(custom%20slider%20color).json?alt=media>" %}

{% hint style="info" %}
Please note that we only allow **numbers** as the slider value.
{% endhint %}

#### **11. URL**

**URL** allows you to put the URL links and apply validation on it.

<figure><img src="https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-4621c580952429d32612fa3435d32e2cbe193270%2FQuestion%20set%20-%20question%20type%20-%20URL.png?alt=media" alt=""><figcaption></figcaption></figure>

#### 12. Grouped Attributes

**Grouped Attributes** allows the labeler to combine multiple questions that pertain to a single group.

<figure><img src="https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-ea80343d4be92c8d1ed8e9d371bd4005959052c7%2FQuestion%20set%20-%20question%20type%20-%20Grouped%20attributes.png?alt=media" alt=""><figcaption></figcaption></figure>

#### **13. Script-Generated Questions**

{% hint style="info" %}
Only supported in **Row Labeling** project.
{% endhint %}

**Script-Generated Questions** is an advanced question type that dynamically generates different questions for each row based on its data. Unlike predefined question sets, this approach allows for flexible, on-the-fly question generation, making it ideal for scenarios where static question lists are insufficient. For more details, see this page [here](https://docs.datasaur.ai/advanced/script-generated-question).

<figure><img src="https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-5999903bef0a7da75d2f749682d64cd282673e11%2FRow%20labeling%20-%20script-generated%20question%20-%20project%201%20-%20question%202.png?alt=media" alt=""><figcaption></figcaption></figure>

### **Advanced Settings**

In Row Labeling projects, you can use the **'Refer answer to table column'** option in Advanced Settings to pre-fill answers based on your dataset. For more details, please refer to the full guide on [this page](https://docs.datasaur.ai/data-studio-projects/lets-get-labeling/label-sets/refer-answer-to-table-column).

### **Answer Validation Script**

{% hint style="info" %}
This feature is only available in **Row Labeling** projects and is disabled by default. Please reach out to [**support@datasaur.ai**](mailto:support@datasaur.ai) if your team needs this feature, and we'll assist you!
{% endhint %}

The **Answer Validation Script** is a highly flexible feature powered by TypeScript, designed to help validate the logic of answering a row in Row labeling tasks. With this feature, you can write validation scripts to handle complex scenarios, such as verifying labeled data using other answers, comparing data across questions, or using external APIs for dynamic validation. Once the script is configured, if labelers or reviewers attempt to submit a row that fails validation, an error message will be displayed.

This functionality enables better control, accuracy, and consistency in the labeling process.

![](https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-646f9b3048e9dd1caafdd5390c48bd125655903f%2FProject%20-%20Row%20labeling%20-%20answer%20validation%20script.png?alt=media)

#### **Key Capabilities**

1. **Row-Specific Validation**: Validates data based on the content of the current row.
2. **Cross-Question Validation**: Checks answers by comparing them with answers from other questions.
3. **API-based Validation**: Incorporates validations that rely on external APIs or external business logic.

#### How to Configure the Validation Script

{% hint style="info" %}
**Note**

* The validation cannot be configured if the questions have not been set up yet.
* Only accessible by Admins in Reviewer mode.
  {% endhint %}

1. Go to the **Row Labeling Extension** inside the project.
2. Click on the **three-dot menu**.
3. Select **"Configure answer validation script…"**.

   ![](https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-3ce68d0b96e3f45eec245ea0cb90a1aa2bf1e2c7%2FExtension%20%20-%20row%20doc%20labeling%20-%20row%20-%20more%20menu.png?alt=media)

   ![](https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-1fa0b10cc90117c3203fd2397f71222bafe98be1%2FExtension%20%20-%20row%20doc%20labeling%20-%20Configure%20answer%20validation%20script.png?alt=media)

#### Configuring the Script

When opening the Answer Validation Script dialog for the first time, you will be prompted with this template:

<details>

<summary>View Template</summary>

```tsx
/**
 * This function should return a ValidationResult object.
 *
 * @param {ValidationArgs} args - The arguments for the validation.
 * @returns {ValidationResult} The result of the validation.
 * @example
 * To return an error:
 *   return { errorMessage: "This is a sample error message." };
 * To return no error:
 * return {}
 */
async ({ columns, row, questions, answers }: ValidationArgs): Promise<ValidationResult> => {
  **// TODO: Implement your validation logic here.**

  return {};

  /** Helper functions with access to the validation args */

  /**
   * Get the answer for a question by its label.
   * For grouped attributes, pass in the questions array from the grouped attribute.
   * @param label - The label of the question.
   * @param searchQuestions - Optional. The questions to search through. Defaults to the questions in the validation args.
   * @returns The answer for the question.
   */
  function getAnswerByQuestionLabel(label: string, searchQuestions: Question[] = questions) {
    const question = searchQuestions.find((q) => q.label === label);
    if (!question) throw new Error(`Could not find question with label: "${label}".`);
    return answers[`Q${question.id}`];
  }

  /**
   * Get the value of a cell by its column label.
   * @param label - The label of the column.
   * @returns The value of the cell.
   */
  function getCellValueByColumnLabel(label: string) {
    const column = columns.find((column) => column.name === label);
    if (!column) {
      throw new Error(`Couldn't find column with label: "${label}".`);
    }

    const cell = row.find((row) => row.index === column.id);
    if (!cell) {
      throw new Error(`Couldn't find cell with index: ${column.id}. Column: "${column.name}"`);
    }

    return cell.content;
  }
};
```

</details>

To decide whether to pass or fail the submission, you can return an object with or without `errorMessage` as the property:

{% tabs %}
{% tab title="🔴 Failing the submission" %}

```tsx
async ({ columns, row, questions, answers }: ValidationArgs): Promise<ValidationResult> => {
  // this script will always prevent the labeler to submit the answer.
  return { errorMessage: 'Please double-check your answers.' };
}
```

{% endtab %}

{% tab title="🟢 Passing the submission" %}

```tsx
async ({ columns, row, questions, answers }: ValidationArgs): Promise<ValidationResult> => {
  // this script will always allow the labelers to submit the answer.
  return {};
}
```

{% endtab %}
{% endtabs %}

When validating, you will likely need to access certain information to determine whether the answer is valid or requires adjustment before submission. You can access all information provided from the function argument, as demonstrated in the function to write the desired validation behavior.

* <mark style="color:red;">`columns: TableColumn[]`</mark> holds information about the column structure of the data being labeled.

<details>

<summary>View Structure</summary>

```tsx
interface TableColumn {
  id: number;
  name: string;
  displayed: boolean;
  labelerRestricted: boolean;
  rowQuestionId?: number;
}
```

</details>

* <mark style="color:red;">`row: Cell[]`</mark> is an array of cells containing data that is being labeled.

<details>

<summary>View Structure</summary>

<pre class="language-tsx"><code class="lang-tsx"><strong>interface Cell {
</strong>  line: number;
  index: number;
  content: string;
  tokens: string[];
  metadata?: CellMetadata[];
}

interface CellMetadata {
  key: string;
  value: string;
  type?: string;
  pinned?: boolean;
  config?: TextMetadataConfig;
}

interface TextMetadataConfig {
  backgroundColor: string;
  color: string;
  borderColor: string;
}
</code></pre>

</details>

* <mark style="color:red;">`questions: Question[]`</mark> is an array of questions of the project.

<details>

<summary>View Structure</summary>

```tsx
enum QuestionType {
  DROPDOWN = 'DROPDOWN',
  HIERARCHICAL_DROPDOWN = 'HIERARCHICAL_DROPDOWN',
  NESTED = 'NESTED',
  TEXT = 'TEXT',
  SLIDER = 'SLIDER',
  DATA = 'DATA',
  DATE = 'DATE',
  TIME = 'TIME',
  CHECKBOX = 'CHECKBOX',
  URL = 'URL',
}

enum SliderTheme {
  PLAIN = 'PLAIN',
  GRADIENT = 'GRADIENT',
}

interface Question {
  id: number;
  label: string;
  type: QuestionType;
  required: boolean;

  activationConditionLogic?: string;
  bindToColumn?: string;

  config: QuestionConfig;
}

interface QuestionConfig {
  multiple?: boolean;

  // TEXT
  maxLength?: number;
  minLength?: number;
  pattern?: string;
  multiline?: boolean;

  // SLIDER
  theme?: SliderTheme;
  min?: number;
  max?: number;
  step?: number;

  // DATE TIME
  format: string;
  defaultValue?: string;

  // DROPDOWN HIERARCHICAL
  options?: Array<{ id: string; label: string; parentId?: string | null }>;

  // GROUPED
  questions?: Array<Question>;

  // CHECKBOX
  hint?: string;
}
```

</details>

* <mark style="color:red;">`answers`</mark> is an object containing answers with question’s id as the key. Depending on the question, it can be in four different types based on the question type:

  |                    | multiple: false | multiple: true |
  | ------------------ | --------------- | -------------- |
  | normal question    | string          | string\[]      |
  | grouped attributes | Answer          | Answer\[]      |

<details>

<summary>View Structure</summary>

<pre><code><strong>type Answer = string | string[] | Answers[];
</strong>
interface Answers {
  [questionId: string]: Answer;
}
</code></pre>

</details>

We also provided some helper functions in the template to help with the most basic data access, such as:

* <mark style="color:red;">`function getCellValueByColumnLabel(label: string): string;`</mark>

  This function helps you obtain data based on the column’s label.
* <mark style="color:red;">`function getAnswerByQuestionLabel(label: string, searchQuestions: Question[] = questions): Answers;`</mark>

  This function helps you obtain the answer value based on the question’s label.

#### Validating Answer Through an API Call

You can include API requests in your validation, enabling dynamic or third-party validations by using the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).

{% hint style="warning" %}
**Disclaimer**

* We do not accept any responsibility for any API calls that are misrouted, improperly configured, or sent to unintended parties, which may lead to the exposure, leakage, or compromise of data confidentiality.
* Users are fully responsible for ensuring the accuracy, security, and integrity of API configurations and transmissions. By using our services, you acknowledge and accept these responsibilities.
  {% endhint %}

#### Examples

<details>

<summary>Validating answers between two questions</summary>

```tsx
async ({ questions, answers }: ValidationArgs): Promise<ValidationResult> => {
  const questionAAnswer = getAnswerByQuestionLabel("Question A");
  const questionBAnswer = getAnswerByQuestionLabel("Question B");

  if (questionAAnswer !== questionBAnswer) {
    return { errorMessage: "The answer to Question A must match Question B." };
  }

  return {}; // Pass the validation
  
  // ...existing helpers provided by template
};
```

</details>

<details>

<summary>Validating an answer based on a cell value</summary>

```tsx
async ({ columns, row, questions, answers }: ValidationArgs): Promise<ValidationResult> => {
  const statusColumnValue = getCellValueByColumnLabel("Status");
  const approvalStatusAnswer = getAnswerByQuestionLabel("Approval Status");

  if (statusColumnValue === "Complete" && approvalStatusAnswer !== "Approved") {
    return { errorMessage: "If 'Status' is 'Complete', 'Approval Status' must be 'Approved'." };
  }

  return {};
  
  // ...existing helpers provided by template
};
```

</details>

<details>

<summary>Validating an answer through an API request using the Fetch API</summary>

```tsx
async ({ columns, row, questions, answers }: ValidationArgs): Promise<ValidationResult> => {
	const response = await fetch('<https://some.api.net/validate>', ...);
	const data = await response.json(); // assume the API returns a JSON object: { result: 'valid|invalid', message: 'the error message' };
	
	if (data.result === 'invalid') {
	  return { errorMessage: data.message };
	}

  return {};
  
  // ...existing helpers provided by template
}
```

</details>

#### **FAQs**

1. **Can I validate across multiple rows?**

   No, the validation script is row-specific. It operates on individual rows being labeled.
2. **What happens if there's an error in the script?**

   Unhandled exceptions or errors in the script will result in validation errors being shown and prevent the labeler from submitting their answers. You may choose to catch the error inside the script and let the submission continue if needed.

## **Hierarchical Label Sets or Dropdown Options**

Users can upload multi-level hierarchical label sets for **Span Labeling** projects and hierarchical dropdown options for **Row** or **Document** **Labeling** projects.

Here’s a sample that can be used for both hierarchical label set and dropdown options in CSV format:

{% file src="<https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-3a2c677bd22f2da5ccad8de525a650b02bb7dc67%2FDatasaur%20sample%20-%20Hierarchical%20label%20set%20(dropdown%20options).csv?alt=media&token=4d01e97e-22ef-4bef-8fe3-9dc30d66aae8>" %}

```
id,label
1,Novel
1.1,Author
1.1.1,Name
1.1.2,Works
1.2,Title
1.2.1,Main Title
1.2.2,Subtitle
2,Characters
2.1,Antagonist
2.2,Protagonist
```

### **Components of this file**

#### **1. Header**

The header <mark style="color:red;">**`id,label`**</mark> will always be the first row in the CSV file. The first label/option should have **1** as the ID, just like in the example above.

#### **2. ID format**

The ID format follows a structure similar to Microsoft Word's numbering format. In the example above:

* **Novel** is the root level.
  * **1** is the ID for the root level.
* **Author** is a second-level category under **Novel**.
  * **1.1** is the ID for the second level.

{% hint style="info" %}
**Important Notes**

When importing data, the CSV format allows dots (.) to represent hierarchical relationships. However, these dots are automatically converted into a different ID structure in the JSON structure because dots are reserved for path traversal operations in the system. This means dots **must not** be \*\*\*\*used in JSON IDs. Here's how it works:

* CSV Input:

  ```typescript
  id,label
  1,Novel
  1.1,Author
  ```
* Will be converted to JSON as:

  ```json
  [  
    {    
      "label": "Novel",    
      "id": "1"  
    },  
    {    
      "label": "Author",    
      "id": "2",    
      "parentId": "1"  
    }
  ]
  ```

  In JSON format:

  * ✅ Correct: <mark style="color:red;">`"id": "2"`</mark>
  * ❌ Incorrect: <mark style="color:red;">`"id": "1.1"`</mark>

  Using dots in JSON IDs will cause incorrect path resolution when selecting items in the hierarchy.
  {% endhint %}

#### 3. Hierarchical Label Set in Span Labeling Projects

The hierarchy will be visible in the **Labels extension** and the **label dropdown**.

You can also **use the same label name** **under** **different parent labels**.

```
id,label
1,Software
1.1,Java
2,Geography
2.1,Java
```

Even though "Java" appears two times, each belongs to a different parent, making it contextually unique.

<figure><img src="https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-2f18d85fc5a0c0732c9b828a62fe73642449bf2e%2FProject%20-%20span%20labeling%20-%20hierarchical%20label%20set.png?alt=media" alt=""><figcaption></figcaption></figure>

However, using the same label name more than once under the same parent is not allowed:

```
id,label
1,Fruit
1.1,Apple
1.2,Apple
```

In this case, the system will flag an error because both "Apple" entries are under "Fruit".

#### 4. Hierarchical Dropdown Options in Row or Document Labeling Projects

You have to choose **Hierarchical Dropdown** as the question type when creating the project.

The hierarchy will be displayed in the **Row Labeling extension** and the **answer column in the table**.

![](https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-adf836644a186873e1f495dbb7763429500e6be4%2FProject%20-%20row%20labeling%20-%20Hierarchical%20Dropdown.png?alt=media)

{% hint style="info" %}
**Tips**

* Clicking the **Home** icon navigates directly to the top-level label.
* You can search for **bottom-level options** globally.
  {% endhint %}
