Managing Labeling Jobs

You can also use the SDK to control how tasks appear in the data manager to annotators or reviewers. You can create custom filters and ordering for the tasks based on parameters that you specify with the SDK. This lets you have more granular control over which tasks in your dataset get labeled or reviewed, and in which order.

Create a batch of tasks to annotate using filters

For example, you can create a filter to prepare tasks to be annotated. If you want annotators to focus on tasks in the first 10 tasks in a dataset that contain the word “hello” in the field “text” in the task data, you could use the following:

1LABEL_STUDIO_URL = 'YOUR_BASE_URL'
2LABEL_STUDIO_API_KEY = 'YOUR_API_KEY'
3PROJECT_ID=1 # replace with your project ID
4
5from label_studio_sdk import LabelStudio
6
7client = LabelStudio(base_url=LABEL_STUDIO_URL, api_key=LABEL_STUDIO_API_KEY)
8
9# Build filters JSON per API schema:
10# https://api.labelstud.io/api-reference/api-reference/views/create#request.body.data.filters
11filters = {
12 "conjunction": "and",
13 "items": [
14 {
15 # If your task data field is "text", use data.text; otherwise change the field name accordingly
16 "filter": "filter:tasks:data.text",
17 "operator": "contains",
18 "type": "String",
19 "value": "hello",
20 },
21 {
22 "filter": "filter:tasks:inner_id",
23 "operator": "less",
24 "value": 10,
25 "child_filter": None,
26 "type": "Number",
27 }
28 ],
29}
30
31view_payload = {
32 "title": 'Text contains "hello"',
33 "type": "list",
34 "target": "tasks",
35 "filters": filters,
36}
37
38view = client.views.create(project=PROJECT_ID, data=view_payload)
39
40print(f"Created view (tab) id={view.id}, title={view.data.get('title')}")
41# Optional: list task IDs shown by this tab
42for task in client.tasks.list(view=view.id, fields=["id"]):
43 print(task.id)