HumanSignal/label-studio · error · ValidationError

Prediction must have "result" fields

Error message

Prediction must have "result" fields

What it means

TaskValidator.validate raises this when a task item's 'predictions' list contains a dict entry without a 'result' key. Predictions follow the same schema as annotations and must include a 'result' array describing the model's proposed labels.

Source

Thrown at label_studio/tasks/validation.py:191

                ok = 'result' in annotation
                if not ok:
                    raise ValidationError('Annotation must have "result" fields')

                # check result is list
                if not isinstance(annotation.get('result', []), list):
                    raise ValidationError('"result" field in annotation must be list')

            # task[predictions]
            self.raise_if_wrong_class(task, 'predictions', list)
            for prediction in task.get('predictions', []):
                if not isinstance(prediction, dict):
                    logger.warning('Prediction must be dict, but "%s" found', str(type(prediction)))
                    continue

                ok = 'result' in prediction
                if not ok:
                    raise ValidationError('Prediction must have "result" fields')

            # task[meta]
            self.raise_if_wrong_class(task, 'meta', (dict, list))

        # task is data as is, validate task as data and move it to task['data']
        else:
            self.check_data_and_root(self.project, task, dict_is_root=True)
            task = {'data': task}

        return task

    @staticmethod
    def format_error(i, detail, item):
        if len(detail) == 1:
            code = (str(detail[0].code + ' ')) if detail[0].code != 'invalid' else ''
            return 'Error {code} at item {i}: {detail} :: {item}'.format(code=code, i=i, detail=detail[0], item=item)
        else:
            errors = ', '.join(detail)

View on GitHub (pinned to 0b49e9b539)

Solutions

  1. Add 'result' to every prediction dict, e.g. 'result': [] if there are no results
  2. Remove the empty prediction shell entirely if it carries no information
  3. Populate 'result' with the model's output in Label Studio result format ({from_name, to_name, type, value})
  4. Pre-validate: for each p in task.get('predictions', []): assert isinstance(p, dict) and 'result' in p

Example fix

// before
{"data": {"text": "hi"}, "predictions": [{"score": 0.9, "model_version": "v1"}]}
// after
{"data": {"text": "hi"}, "predictions": [{"score": 0.9, "model_version": "v1", "result": []}]}
Defensive patterns

Strategy: validation

Validate before calling

def validate_predictions(task):
    for p in task.get('predictions', []):
        if isinstance(p, dict) and 'result' not in p:
            raise ValueError('prediction missing result: %r' % p)

Type guard

def has_valid_prediction(p):
    return isinstance(p, dict) and isinstance(p.get('result'), list)

Try / catch

try:
    client.import_tasks(id=project_id, tasks=tasks)
except LabelStudioError as e:
    if 'Prediction must have "result" fields' in str(e):
        for t in tasks:
            for p in t.get('predictions', []):
                if isinstance(p, dict):
                    p.setdefault('result', [])
        client.import_tasks(id=project_id, tasks=tasks)
    else:
        raise

Prevention

When it happens

Trigger: POSTing tasks to the import endpoint with {'predictions': [{'score': 0.9}]} or {'predictions': [{'model_version': 'v1'}]} — prediction dict lacking 'result'. Non-dict prediction entries are skipped with a warning, not this error.

Common situations: ML backend output adapters that attach scores/model metadata but omit results; scripts importing pre-annotations that pass an empty prediction shell {} to mark model version; template files where results were stripped.

Understand the failure class

Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — this error's family across 20 libraries.

Related errors


AI-assisted analysis of HumanSignal/label-studio@0b49e9b539 (2026-08-29). Data as JSON: /api/errors/9fc83e756369bbf8. Report an issue: GitHub.