Keyword argument `table` should be either of type `dict` or `list`, but is <class 'str'>)

I am trying to run Tapas for Question Answering using the Inference API and can’t figure out the problem in the parsing as I followed the example on inference and built the JSON in the same format as required and still getting this error.

Here is the code

 dataToPass["query"] = "What is Akshat ID Number"
        dataToPass["table"] = ast.literal_eval(str(dict))
        jsonFinal = {}
        jsonFinal["inputs"] = dataToPass
        test_string = str(jsonFinal)
        answer = getAnswer(test_string)

I am getting the output for jsonFinal as the following

{"inputs": {"query": "What is Akshat ID Number", "table": {"id": [1, 2, 3, 4, 5, 6, 7], "gender": ["", "MALE", "MALE", "MALE", "MALE", "MALE", "MALE"], "name": ["", "Akshat", "Rishabh Sahu", "Ashu", "Ashu", "Ashu", "Ashu"], "dob": ["", "1999", "1999", "1999", "1999", "1999", "1999"], "id_number": ["", "808", "1011", "100", "100", "100", "102"]}}}

I have tried passing in jsonFinal and test_string and a couple of other combination but I am not sure why this error persists

Just FYI I am using a custom dictionary class hence converting the above way to a dictionary and
getAnswer is where I call the inference API.

And I am building the dict by iterating over a django model queryset -
here is the code to that

def dataToJSON(coloumName, jsonData):
    jsonBar = []
    for i in jsonData:

    dict.add(coloumName, jsonBar)
    return ""

cc @nielsr

Thanks for the ping. However, I don’t have access to the accelerated inference API.

What is the error you’re getting?

Hye when I am sending the JSON data to the inference API it shows that the table argument where I am fetching the data from my table and posting it as a JSON in the inference API function call but getting that the Keyword argument tbale should be either list or dict and it find that its a string.

Looking at the documentation, it might be that the error is due to the fact that the values of the “id” column in the table that you provide are not strings.

Can you try by updating the id column to [“1”, “2”, “3”, “4”, “5”, “6”, “7”] instead of [1, 2, 3, 4, 5, 6, 7]?

1 Like

Hey did that still in the same issue

Updated JSON

{"inputs": {"query": "What is Akshat ID Number", "table": {"id": ["2", "3", "4", "5"], "gender": ["MALE", "MALE", "MALE", "MALE"], "name": ["Akshat", "Rishabh Sahu", "Ashu", "Sourabh Bakshi"], "dob": ["1999", "1999", "1999", "1998"], "id_number": ["808", "5054", "222", "333"]}}}

Same error I am not exactly sure what’s the cause as in the example it was running just fine.

Edit -

This for some reasons seems to run fine in a Google Notebook I used the same input as mentioned

Edit 2 - it worked thanks a lot the string part worked needed to just make all of them as string used str() thanks a lot

1 Like