Error in Prodigy Web App ("Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.[missing argument]")

I get the following error when I try to run the recipe below:

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.[missing argument]

The intention of this code is to ask a series of questions, one after the other, about a single response to a single query, then move on to asking the same questions about another response to a different query.

My assumption was that the task text and options would automatically be applied to the choice block. I might be mistaken.

I have created an Excel file that should work with this program without containing propriety information (the code has also been modified to remove anything proprietary), but I'm not able to actually upload this Excel file as an attachment, so I'm linking a Google sheet with the same content:

import pandas as pd
import prodigy
from prodigy.core import recipe
from prodigy.components.stream import get_stream
from pathlib import Path
import json


df = pd.read_excel('./data/feedback_mwe.xlsx')
texts = []
responses = []
metas = []
for i, row in df.iterrows():
    meta = {}
    meta['SME'] = row['SME']
    meta['id'] = row['Query ID']
    text = row['Query']
    response = row['Query Response']
    meta['url'] = row['Response URL']
    texts.append(text)
    responses.append(response)
    metas.append(meta)
label_cols = ['Comprehension',
              'Correctness',
              'Completeness',
              'Clinical Harmfulness',
              'Clinical Harmfulness Level',
              'Overall Answer']
labels = {'Comprehension': ['Option 0',
                            'Option 1',
                            'Option 2'],
          'Correctness': ['Option 0',
                          'Option 1',
                          'Option 2',
                          'Option 3',
                          'Option 4'],
          'Completeness': ['Option 0',
                           'Option 1',
                           'Option 2'],
          'Clinical Harmfulness': ['Option 0', 'Option 1'],
          'Clinical Harmfulness Level': ['Option 0',
                                         'Option 1',
                                         'Option 2',
                                         'Option 3',
                                         'Option 4'],
          'Overall Answer': ['🙁', '😐', '😀']}



def compose_json(texts, responses, metas, label_cols):
    json_ = []
    for text, response, meta in zip(texts, responses, metas):
        for labelcol in label_cols:
            dict_ = {}
            dict_['meta'] = meta.copy()
            dict_['text'] = ['Query: %s\n\n\nResponse: %s' % (text, response)]
            dict_['meta']['labelcol'] = labelcol
            json_.append(dict_)
    with open('data/feedback_Vaccine_guidelines.json', 'w') as f:
        json.dump(json_, f)


compose_json(texts, responses, metas, label_cols)


@prodigy.recipe("vaccine-guidelines")
def annotate():
    file_path = Path('./data/feedback_Vaccine_guidelines.json')
    dataset = './data/dataset.json'
    stream = get_stream(file_path)
    stream = add_options(stream)
    blocks = [{'view_id': 'html', 'html_template': '<p>{{meta.labelcol}}</p>'},
              {'view_id': 'choice'},
              {'view_id': 'text_input', 'field_id': 'notes',
               'field_label': 'Notes'}]
    return {'dataset': dataset,
            'view_id': 'blocks',
            'stream': stream,
            'config': {'labels': ['LABEL'],
                       'blocks': blocks,
                       'choice_style': 'single'}}


def add_options(stream):
    for task in stream:
        task['options'] = labels[task['meta']['labelcol']]
        yield task

I'm looking for one of two things: 1) how to fix or work around the error I'm experiencing or 2) how to debug the error myself. I don't see how to use the "non-minified" developer interface mentioned by React, and without that, I can't see the full content of the error message and warnings, so I don't see how to debug anything.

Hi! I hope I'm reading your code correctly but I think the problem might be the structure of the "options" you're providing (which normally Prodigy should catch on the back-end – I wonder if it's not strict enough with the blocks UI, so we'll look into that :+1:)

In label_cols, you have the labels/options of a list of strings, but it expects a list of dictionaries with a "text" and "id", so both can be customised individually. Also see the JSON format here. For example:

[
    {"id": "Comprehension", "text": "Comprehension"},
   # ...
]

So something like this should work:

sub_labels = labels[task['meta']['labelcol']]
task['options'] = [{"id": opt, "text": opt} for opt in sub_labels]
1 Like

Thank you! That fixed it!