[Embeddings.create] Improve InvalidRequestError message: "['', 'a'] is not valid under any of the given schemas - 'input'" for large arrays

Hi,
The error message returns from embedding.create does not point to the exact element in the input array that us not valid. This is really annoying when you pass large array and need to debug what element is not valid.

My suggestion here is to point to the specific element in the input array that is not valid instead of returning the whole array.

E.g.
Running this code in python:

from openai.utils import get_embeddings
get_embeddings(['','a'])

will return the following error message
ERROR: openai.error.InvalidRequestError: ['', 'a'] is not valid under any of the given schemas - 'input'

A better error message in this case will be

`ERROR: openai.error.InvalidRequestError: [''] is not valid under any of the given schemas - 'input'`

Thanks,
Roy.

1 Like

Yes, the API is officially a beta and your feedback is very important. Thank you @roy-pstr

Regarding your embedding prompt, I tried two versions and both worked for me. Here is an incomplete snapshot (not showing the entire 1024 long vector, in the interest of saving space, haha ):

Prompt: ‘’,‘a’

Prompt: [‘’,‘a’]

HTH

from openai.embeddings_utils import get_embeddings
get_embeddings(['','a'])

raise the following error:

openai.error.InvalidRequestError: ['', 'a'] is not valid under any of the given schemas - 'input'

version:
openai 0.26.4

It worths mention that the default engine is used here: “text-similarity-davinci-001”

And make sure the input you are using is list of prompts. not a single prompt which is a string of list.

Anyway. I’m 100% sure that this raising an error, and my suggestion is to point to the element in the array that cause the error.

Best,
Roy.

2 Likes

i encounter same error

1 Like

I had the same error and couldn’t figure out what’s wrong as I have big volume of data. Strangely, when I worked without batching (passing only a list of length 1 each time) it worked :man_shrugging: